diff --git a/commands_test.go b/commands_test.go index dc166d34b3..6c8321a8b6 100644 --- a/commands_test.go +++ b/commands_test.go @@ -12,7 +12,7 @@ import ( "github.com/codegangsta/cli" drivers "github.com/docker/machine/drivers" - "github.com/docker/machine/hypervisor" + "github.com/docker/machine/provider" "github.com/docker/machine/state" ) @@ -44,8 +44,8 @@ func (d *FakeDriver) GetMachineName() string { return "" } -func (d *FakeDriver) GetHypervisorType() hypervisor.HypervisorType { - return hypervisor.None +func (d *FakeDriver) GetProviderType() provider.ProviderType { + return provider.None } func (d *FakeDriver) GetIP() (string, error) { diff --git a/drivers/amazonec2/amazonec2.go b/drivers/amazonec2/amazonec2.go index 8a69883cb7..361189a724 100644 --- a/drivers/amazonec2/amazonec2.go +++ b/drivers/amazonec2/amazonec2.go @@ -15,7 +15,7 @@ import ( "github.com/codegangsta/cli" "github.com/docker/machine/drivers" "github.com/docker/machine/drivers/amazonec2/amz" - "github.com/docker/machine/hypervisor" + "github.com/docker/machine/provider" "github.com/docker/machine/ssh" "github.com/docker/machine/state" "github.com/docker/machine/utils" @@ -43,6 +43,7 @@ type Driver struct { Region string AMI string SSHKeyID int + SSHPort int KeyName string InstanceId string InstanceType string @@ -64,7 +65,6 @@ type Driver struct { SwarmDiscovery string storePath string keyPath string - SSHPort int } type CreateFlags struct { @@ -170,8 +170,8 @@ func NewDriver(machineName string, storePath string, caCert string, privateKey s }, nil } -func (d *Driver) GetHypervisorType() hypervisor.HypervisorType { - return hypervisor.Remote +func (d *Driver) GetProviderType() provider.ProviderType { + return provider.Remote } func (d *Driver) AuthorizePort(ports []*drivers.Port) error { diff --git a/drivers/drivers.go b/drivers/drivers.go index 623be64bab..d0627b5549 100644 --- a/drivers/drivers.go +++ b/drivers/drivers.go @@ -6,7 +6,7 @@ import ( "sort" "github.com/codegangsta/cli" - "github.com/docker/machine/hypervisor" + "github.com/docker/machine/provider" "github.com/docker/machine/state" ) @@ -57,8 +57,8 @@ type Driver interface { // GetState returns the state that the host is in (running, stopped, etc) GetState() (state.State, error) - // GetHypervisorType returns whether the instance is local/remote - GetHypervisorType() hypervisor.HypervisorType + // GetProviderType returns whether the instance is local/remote + GetProviderType() provider.ProviderType // Kill stops a host forcefully Kill() error diff --git a/drivers/none/none.go b/drivers/none/none.go index 4f32148756..1b8a275fb3 100644 --- a/drivers/none/none.go +++ b/drivers/none/none.go @@ -6,7 +6,7 @@ import ( "github.com/codegangsta/cli" "github.com/docker/docker/api" "github.com/docker/machine/drivers" - "github.com/docker/machine/hypervisor" + "github.com/docker/machine/provider" "github.com/docker/machine/state" ) @@ -86,8 +86,8 @@ func (d *Driver) GetState() (state.State, error) { return state.None, nil } -func (d *Driver) GetHypervisorType() hypervisor.HypervisorType { - return hypervisor.None +func (d *Driver) GetProviderType() provider.ProviderType { + return provider.None } func (d *Driver) Kill() error { diff --git a/host.go b/host.go index 5156c442e5..3b8528f6ce 100644 --- a/host.go +++ b/host.go @@ -19,7 +19,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/docker/machine/drivers" - "github.com/docker/machine/hypervisor" + "github.com/docker/machine/provider" "github.com/docker/machine/ssh" "github.com/docker/machine/utils" ) @@ -112,10 +112,10 @@ func ValidateHostName(name string) (string, error) { func (h *Host) GetDockerConfigDir() (string, error) { // TODO: this will be refactored in https://github.com/docker/machine/issues/699 - switch h.Driver.GetHypervisorType() { - case hypervisor.Local: + switch h.Driver.GetProviderType() { + case provider.Local: return "/var/lib/boot2docker", nil - case hypervisor.Remote: + case provider.Remote: return "/etc/default", nil default: return "", ErrUnknownHypervisorType @@ -212,10 +212,10 @@ func (h *Host) StartDocker() error { err error ) - switch h.Driver.GetHypervisorType() { - case hypervisor.Local: + switch h.Driver.GetProviderType() { + case provider.Local: cmd, err = h.GetSSHCommand("sudo /etc/init.d/docker start") - case hypervisor.Remote: + case provider.Remote: cmd, err = h.GetSSHCommand("sudo service docker start") default: return ErrUnknownHypervisorType @@ -240,10 +240,10 @@ func (h *Host) StopDocker() error { err error ) - switch h.Driver.GetHypervisorType() { - case hypervisor.Local: + switch h.Driver.GetProviderType() { + case provider.Local: cmd, err = h.GetSSHCommand("if [ -e /var/run/docker.pid ]; then sudo /etc/init.d/docker stop ; fi") - case hypervisor.Remote: + case provider.Remote: cmd, err = h.GetSSHCommand("sudo service docker stop") default: return ErrUnknownHypervisorType @@ -549,14 +549,14 @@ func (h *Host) SetHostname() error { err error ) - switch h.Driver.GetHypervisorType() { - case hypervisor.Local: + switch h.Driver.GetProviderType() { + case provider.Local: cmd, err = h.GetSSHCommand(fmt.Sprintf( "sudo hostname %s && echo \"%s\" | sudo tee /var/lib/boot2docker/etc/hostname", h.Name, h.Name, )) - case hypervisor.Remote: + case provider.Remote: cmd, err = h.GetSSHCommand(fmt.Sprintf( "echo \"127.0.0.1 %s\" | sudo tee -a /etc/hosts && sudo hostname %s && echo \"%s\" | sudo tee /etc/hostname", h.Name, diff --git a/hypervisor/hypervisor.go b/hypervisor/hypervisor.go deleted file mode 100644 index 545312d318..0000000000 --- a/hypervisor/hypervisor.go +++ /dev/null @@ -1,25 +0,0 @@ -package hypervisor - -// HypervisorType represents the type of hypervisor a machine is using -type HypervisorType int - -const ( - None HypervisorType = iota - Local - Remote -) - -var hypervisorTypes = []string{ - "", - "Local", - "Remote", -} - -// Given a type, returns its string representation -func (h HypervisorType) String() string { - if int(h) >= 0 && int(h) < len(hypervisorTypes) { - return hypervisorTypes[h] - } else { - return "" - } -} diff --git a/provider/provider.go b/provider/provider.go new file mode 100644 index 0000000000..713c62cad1 --- /dev/null +++ b/provider/provider.go @@ -0,0 +1,25 @@ +package provider + +// ProviderType represents the type of a provider for a machine +type ProviderType int + +const ( + None ProviderType = iota + Local + Remote +) + +var providerTypes = []string{ + "", + "Local", + "Remote", +} + +// Given a type, returns its string representation +func (t ProviderType) String() string { + if int(t) >= 0 && int(t) < len(providerTypes) { + return providerTypes[t] + } else { + return "" + } +}