-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
polish code: introduce provisioners package
- Loading branch information
Showing
7 changed files
with
76 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package provisioners | ||
|
||
import ( | ||
"github.com/mhewedy/vermin/command" | ||
"github.com/mhewedy/vermin/ip" | ||
) | ||
|
||
type Ansible struct{} | ||
|
||
func (Ansible) Accept(ptype string) bool { | ||
return ptype == "ansible" | ||
} | ||
|
||
func (Ansible) Exec(vmName string, script string) error { | ||
|
||
ipAddr, err := ip.Find(vmName, false) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return command.AnsiblePlaybook(ipAddr, script).Interact() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package provisioners | ||
|
||
import "fmt" | ||
|
||
type Func func(vmName string, script string) error | ||
|
||
type Provisioner interface { | ||
Accept(ptype string) bool | ||
Exec(vmName string, script string) error | ||
} | ||
|
||
func Load(pType string) (Func, error) { | ||
|
||
// TODO in future if we need to implement plugin arch, | ||
// we might construct this slice dynamically by checking some directory of binaries of some name | ||
// e.g. vermin-provisioner-<name> | ||
ps := []Provisioner{ | ||
Shell{}, | ||
Ansible{}, | ||
} | ||
|
||
for _, p := range ps { | ||
if p.Accept(pType) { | ||
return p.Exec, nil | ||
} | ||
} | ||
|
||
return nil, fmt.Errorf("Cannot load provisioner of type: %s", pType) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters