diff --git a/drivers/generic/generic.go b/drivers/generic/generic.go index 14d598042c..57a47f1702 100644 --- a/drivers/generic/generic.go +++ b/drivers/generic/generic.go @@ -55,6 +55,7 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag { } } +// NewDriver creates and returns a new instance of the driver func NewDriver(hostName, storePath string) drivers.Driver { return &Driver{ SSHKey: defaultSSHKey, diff --git a/drivers/none/driver.go b/drivers/none/driver.go index 9d0396586a..0b250eb974 100644 --- a/drivers/none/driver.go +++ b/drivers/none/driver.go @@ -9,11 +9,7 @@ import ( "github.com/docker/machine/libmachine/state" ) -const drivername = "none" - -// func main() { -// plugin.RegisterDriver(new(Driver)) -// } +const driverName = "none" // Driver is the driver used when no driver is selected. It is used to // connect to existing Docker hosts by specifying the URL of the host as @@ -47,7 +43,7 @@ func (d *Driver) Create() error { } func (d *Driver) DriverName() string { - return drivername + return driverName } func (d *Driver) GetIP() (string, error) { diff --git a/libmachine/drivers/base.go b/libmachine/drivers/base.go index 48e16a9df4..17bd097dd8 100644 --- a/libmachine/drivers/base.go +++ b/libmachine/drivers/base.go @@ -20,12 +20,12 @@ func (d *BaseDriver) GetSSHKeyPath() string { return filepath.Join(d.StorePath, "machines", d.MachineName, "id_rsa") } -// DriverName - This must be implemented in every driver +// DriverName returns the name of the driver func (d *BaseDriver) DriverName() string { return "unknown" } -// GetMachineName - +// GetIP returns the ip func (d *BaseDriver) GetMachineName() string { return d.MachineName } @@ -35,7 +35,7 @@ func (d *BaseDriver) ResolveStorePath(file string) string { return filepath.Join(d.StorePath, "machines", d.MachineName, file) } -// GetSSHPort - +// GetSSHPort returns the ssh port, 22 if not specified func (d *BaseDriver) GetSSHPort() (int, error) { if d.SSHPort == 0 { d.SSHPort = 22 @@ -44,7 +44,7 @@ func (d *BaseDriver) GetSSHPort() (int, error) { return d.SSHPort, nil } -// GetSSHUsername - +// GetSSHUsername returns the ssh user name, root if not specified func (d *BaseDriver) GetSSHUsername() string { if d.SSHUser == "" { d.SSHUser = "root" diff --git a/libmachine/drivers/drivers.go b/libmachine/drivers/drivers.go index 00d521384c..ea15e5797a 100644 --- a/libmachine/drivers/drivers.go +++ b/libmachine/drivers/drivers.go @@ -18,6 +18,10 @@ type Driver interface { // DriverName returns the name of the driver as it is registered DriverName() string + // GetCreateFlags returns the mcnflag.Flag slice representing the flags + // that can be set, their descriptions and defaults. + GetCreateFlags() []mcnflag.Flag + // GetIP returns an IP or hostname that this host is available at // e.g. 1.2.3.4 or docker-host-d60b70a14d3a.cloudapp.net GetIP() (string, error) @@ -57,10 +61,6 @@ type Driver interface { // have any special restart behaviour. Restart() error - // GetCreateFlags returns the mcnflag.Flag slice representing the flags - // that can be set, their descriptions and defaults. - GetCreateFlags() []mcnflag.Flag - // SetConfigFromFlags configures the driver with the object that was returned // by RegisterCreateFlags SetConfigFromFlags(opts DriverOptions) error diff --git a/libmachine/drivers/utils.go b/libmachine/drivers/utils.go index 62caeef952..67e0448e97 100644 --- a/libmachine/drivers/utils.go +++ b/libmachine/drivers/utils.go @@ -10,7 +10,7 @@ import ( ) func GetSSHClientFromDriver(d Driver) (ssh.Client, error) { - addr, err := d.GetSSHHostname() + address, err := d.GetSSHHostname() if err != nil { return nil, err } @@ -24,7 +24,7 @@ func GetSSHClientFromDriver(d Driver) (ssh.Client, error) { Keys: []string{d.GetSSHKeyPath()}, } - client, err := ssh.NewClient(d.GetSSHUsername(), addr, port, auth) + client, err := ssh.NewClient(d.GetSSHUsername(), address, port, auth) return client, err } @@ -40,12 +40,11 @@ func RunSSHCommandFromDriver(d Driver, command string) (string, error) { output, err := client.Output(command) log.Debugf("SSH cmd err, output: %v: %s", err, output) if err != nil { - returnedErr := fmt.Errorf(`Something went wrong running an SSH command! + return "", fmt.Errorf(`Something went wrong running an SSH command! command : %s err : %v output : %s `, command, err, output) - return "", returnedErr } return output, nil