diff --git a/drivers/openstack/client.go b/drivers/openstack/client.go index e464a567..218af191 100644 --- a/drivers/openstack/client.go +++ b/drivers/openstack/client.go @@ -4,8 +4,10 @@ import ( "crypto/tls" "fmt" "net/http" + "time" "github.com/docker/machine/log" + "github.com/docker/machine/utils" "github.com/docker/machine/version" "github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud/openstack" @@ -31,7 +33,7 @@ type Client interface { StopInstance(d *Driver) error RestartInstance(d *Driver) error DeleteInstance(d *Driver) error - WaitForInstanceStatus(d *Driver, status string, timeout int) error + WaitForInstanceStatus(d *Driver, status string) error GetInstanceIpAddresses(d *Driver) ([]IpAddress, error) CreateKeyPair(d *Driver, name string, publicKey string) error DeleteKeyPair(d *Driver, name string) error @@ -132,11 +134,23 @@ func (c *GenericClient) DeleteInstance(d *Driver) error { return nil } -func (c *GenericClient) WaitForInstanceStatus(d *Driver, status string, timeout int) error { - if err := servers.WaitForStatus(c.Compute, d.MachineId, status, timeout); err != nil { - return err - } - return nil +func (c *GenericClient) WaitForInstanceStatus(d *Driver, status string) error { + return utils.WaitForSpecificOrError(func() (bool, error) { + current, err := servers.Get(c.Compute, d.MachineId).Extract() + if err != nil { + return true, err + } + + if current.Status == "ERROR" { + return true, fmt.Errorf("Instance creation failed. Instance is in ERROR state") + } + + if current.Status == status { + return true, nil + } + + return false, nil + }, 50, 4*time.Second) } func (c *GenericClient) GetInstanceIpAddresses(d *Driver) ([]IpAddress, error) { diff --git a/drivers/openstack/openstack.go b/drivers/openstack/openstack.go index d6e6bdf8..2bba3e5e 100644 --- a/drivers/openstack/openstack.go +++ b/drivers/openstack/openstack.go @@ -664,7 +664,7 @@ func (d *Driver) assignFloatingIp() error { func (d *Driver) waitForInstanceActive() error { log.WithField("MachineId", d.MachineId).Debug("Waiting for the OpenStack instance to be ACTIVE...") - if err := d.client.WaitForInstanceStatus(d, "ACTIVE", 200); err != nil { + if err := d.client.WaitForInstanceStatus(d, "ACTIVE"); err != nil { return err } return nil