Merge pull request #1043 from hairyhenderson/driver-ipaddress-property-1041

Adding/Renaming IPAddress properties for consistency across drivers
This commit is contained in:
Evan Hazlett 2015-05-01 14:57:15 -04:00
commit 2c461bb50f
9 changed files with 79 additions and 26 deletions

View File

@ -29,7 +29,7 @@ func TestCmdInspectFormat(t *testing.T) {
assert.Equal(t, "\"none\"", actual) assert.Equal(t, "\"none\"", actual)
actual, _ = runInspectCommand(t, []string{"--format", "{{prettyjson .Driver}}"}) actual, _ = runInspectCommand(t, []string{"--format", "{{prettyjson .Driver}}"})
assert.Equal(t, "{\n \"URL\": \"unix:///var/run/docker.sock\"\n}", actual) assert.Equal(t, "{\n \"IPAddress\": \"\",\n \"URL\": \"unix:///var/run/docker.sock\"\n}", actual)
} }
func runInspectCommand(t *testing.T, args []string) (string, *libmachine.Host) { func runInspectCommand(t *testing.T, args []string) (string, *libmachine.Host) {

View File

@ -21,6 +21,7 @@ import (
) )
type Driver struct { type Driver struct {
IPAddress string
MachineName string MachineName string
SubscriptionID string SubscriptionID string
SubscriptionCert string SubscriptionCert string
@ -312,7 +313,9 @@ func (d *Driver) Start() error {
return err return err
} }
return nil var err error
d.IPAddress, err = d.GetIP()
return err
} }
func (d *Driver) Stop() error { func (d *Driver) Stop() error {
@ -329,7 +332,12 @@ func (d *Driver) Stop() error {
log.Debugf("stopping %s", d.MachineName) log.Debugf("stopping %s", d.MachineName)
return vmClient.ShutdownRole(d.MachineName, d.MachineName, d.MachineName) if err := vmClient.ShutdownRole(d.MachineName, d.MachineName, d.MachineName); err != nil {
return err
}
d.IPAddress = ""
return nil
} }
func (d *Driver) Remove() error { func (d *Driver) Remove() error {
@ -364,7 +372,8 @@ func (d *Driver) Restart() error {
return err return err
} }
return nil d.IPAddress, err = d.GetIP()
return err
} }
func (d *Driver) Kill() error { func (d *Driver) Kill() error {
@ -381,7 +390,12 @@ func (d *Driver) Kill() error {
log.Debugf("killing %s", d.MachineName) log.Debugf("killing %s", d.MachineName)
return vmClient.ShutdownRole(d.MachineName, d.MachineName, d.MachineName) if err := vmClient.ShutdownRole(d.MachineName, d.MachineName, d.MachineName); err != nil {
return err
}
d.IPAddress = ""
return nil
} }
func generateVMName() string { func generateVMName() string {

View File

@ -14,6 +14,7 @@ import (
// Driver is a struct compatible with the docker.hosts.drivers.Driver interface. // Driver is a struct compatible with the docker.hosts.drivers.Driver interface.
type Driver struct { type Driver struct {
IPAddress string
MachineName string MachineName string
SSHUser string SSHUser string
SSHPort int SSHPort int
@ -250,7 +251,11 @@ func (d *Driver) Start() error {
if err != nil { if err != nil {
return err return err
} }
return c.createInstance(d) if err = c.createInstance(d); err != nil {
return err
}
d.IPAddress, err = d.GetIP()
return err
} }
// Stop deletes the GCE instance, but keeps the disk. // Stop deletes the GCE instance, but keeps the disk.
@ -259,7 +264,11 @@ func (d *Driver) Stop() error {
if err != nil { if err != nil {
return err return err
} }
return c.deleteInstance() if err = c.deleteInstance(); err != nil {
return err
}
d.IPAddress = ""
return nil
} }
// Remove deletes the GCE instance and the disk. // Remove deletes the GCE instance and the disk.

View File

@ -19,6 +19,7 @@ import (
) )
type Driver struct { type Driver struct {
IPAddress string
SSHUser string SSHUser string
SSHPort int SSHPort int
storePath string storePath string
@ -334,7 +335,13 @@ func (d *Driver) Start() error {
if err != nil { if err != nil {
return err return err
} }
return d.wait()
if err := d.wait(); err != nil {
return err
}
d.IPAddress, err = d.GetIP()
return err
} }
func (d *Driver) Stop() error { func (d *Driver) Stop() error {
@ -356,6 +363,7 @@ func (d *Driver) Stop() error {
break break
} }
} }
d.IPAddress = ""
return nil return nil
} }
@ -406,6 +414,7 @@ func (d *Driver) Kill() error {
break break
} }
} }
d.IPAddress = ""
return nil return nil
} }

View File

@ -2,6 +2,7 @@ package none
import ( import (
"fmt" "fmt"
neturl "net/url"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/docker/machine/drivers" "github.com/docker/machine/drivers"
@ -13,6 +14,7 @@ import (
// connect to existing Docker hosts by specifying the URL of the host as // connect to existing Docker hosts by specifying the URL of the host as
// an option. // an option.
type Driver struct { type Driver struct {
IPAddress string
URL string URL string
} }
@ -54,7 +56,7 @@ func (d *Driver) DriverName() string {
} }
func (d *Driver) GetIP() (string, error) { func (d *Driver) GetIP() (string, error) {
return "", nil return d.IPAddress, nil
} }
func (d *Driver) GetMachineName() string { func (d *Driver) GetMachineName() string {
@ -113,6 +115,12 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
} }
d.URL = url d.URL = url
u, err := neturl.Parse(url)
if err != nil {
return err
}
d.IPAddress = u.Host
return nil return nil
} }

View File

@ -41,7 +41,7 @@ type Driver struct {
FloatingIpPoolId string FloatingIpPoolId string
SSHUser string SSHUser string
SSHPort int SSHPort int
Ip string IPAddress string
CaCertPath string CaCertPath string
PrivateKeyPath string PrivateKeyPath string
storePath string storePath string
@ -278,8 +278,8 @@ func (d *Driver) GetURL() (string, error) {
} }
func (d *Driver) GetIP() (string, error) { func (d *Driver) GetIP() (string, error) {
if d.Ip != "" { if d.IPAddress != "" {
return d.Ip, nil return d.IPAddress, nil
} }
log.WithField("MachineId", d.MachineId).Debug("Looking for the IP address...") log.WithField("MachineId", d.MachineId).Debug("Looking for the IP address...")
@ -663,7 +663,7 @@ func (d *Driver) assignFloatingIp() error {
if err := d.client.AssignFloatingIP(d, floatingIp, portId); err != nil { if err := d.client.AssignFloatingIP(d, floatingIp, portId); err != nil {
return err return err
} }
d.Ip = floatingIp.Ip d.IPAddress = floatingIp.Ip
return nil return nil
} }
@ -680,7 +680,7 @@ func (d *Driver) lookForIpAddress() error {
if err != nil { if err != nil {
return err return err
} }
d.Ip = ip d.IPAddress = ip
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"IP": ip, "IP": ip,
"MachineId": d.MachineId, "MachineId": d.MachineId,

View File

@ -30,6 +30,7 @@ const (
) )
type Driver struct { type Driver struct {
IPAddress string
CPU int CPU int
MachineName string MachineName string
SSHUser string SSHUser string
@ -392,7 +393,8 @@ func (d *Driver) Start() error {
log.Infof("VM not in restartable state") log.Infof("VM not in restartable state")
} }
return nil d.IPAddress, err = d.GetIP()
return err
} }
func (d *Driver) Stop() error { func (d *Driver) Stop() error {
@ -410,6 +412,9 @@ func (d *Driver) Stop() error {
break break
} }
} }
d.IPAddress = ""
return nil return nil
} }

View File

@ -22,6 +22,7 @@ import (
) )
type Driver struct { type Driver struct {
IPAddress string
UserName string UserName string
UserPassword string UserPassword string
ComputeID string ComputeID string
@ -418,8 +419,8 @@ func (d *Driver) Create() error {
// Set VAppID with ID of the created VApp // Set VAppID with ID of the created VApp
d.VAppID = vapp.VApp.ID d.VAppID = vapp.VApp.ID
return nil d.IPAddress, err = d.GetIP()
return err
} }
func (d *Driver) Remove() error { func (d *Driver) Remove() error {
@ -497,7 +498,6 @@ func (d *Driver) Remove() error {
} }
return nil return nil
} }
func (d *Driver) Start() error { func (d *Driver) Start() error {
@ -540,8 +540,8 @@ func (d *Driver) Start() error {
return err return err
} }
return nil d.IPAddress, err = d.GetIP()
return err
} }
func (d *Driver) Stop() error { func (d *Driver) Stop() error {
@ -584,8 +584,9 @@ func (d *Driver) Stop() error {
return err return err
} }
return nil d.IPAddress = ""
return nil
} }
func (d *Driver) Restart() error { func (d *Driver) Restart() error {
@ -640,8 +641,8 @@ func (d *Driver) Restart() error {
return err return err
} }
return nil d.IPAddress, err = d.GetIP()
return err
} }
func (d *Driver) Kill() error { func (d *Driver) Kill() error {
@ -683,8 +684,9 @@ func (d *Driver) Kill() error {
return err return err
} }
return nil d.IPAddress = ""
return nil
} }
// Helpers // Helpers

View File

@ -37,6 +37,7 @@ const (
) )
type Driver struct { type Driver struct {
IPAddress string
MachineName string MachineName string
SSHUser string SSHUser string
SSHPort int SSHPort int
@ -406,7 +407,8 @@ func (d *Driver) Start() error {
return err return err
} }
return nil d.IPAddress, err = d.GetIP()
return err
} }
return errors.NewInvalidStateError(d.MachineName) return errors.NewInvalidStateError(d.MachineName)
} }
@ -417,6 +419,8 @@ func (d *Driver) Stop() error {
return err return err
} }
d.IPAddress = ""
return nil return nil
} }
@ -474,6 +478,8 @@ func (d *Driver) Kill() error {
return err return err
} }
d.IPAddress = ""
return nil return nil
} }