Stop polling the instance when status is ERROR
Fix #1269 Signed-off-by: Guillaume Giamarchi <guillaume.giamarchi@gmail.com>
This commit is contained in:
parent
bf695fb8cf
commit
641d5bde24
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue