Stop polling the instance when status is ERROR

Fix #1269

Signed-off-by: Guillaume Giamarchi <guillaume.giamarchi@gmail.com>
This commit is contained in:
Guillaume Giamarchi 2015-06-01 00:41:41 +02:00
parent bf695fb8cf
commit 641d5bde24
2 changed files with 21 additions and 7 deletions

View File

@ -4,8 +4,10 @@ import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"net/http" "net/http"
"time"
"github.com/docker/machine/log" "github.com/docker/machine/log"
"github.com/docker/machine/utils"
"github.com/docker/machine/version" "github.com/docker/machine/version"
"github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack" "github.com/rackspace/gophercloud/openstack"
@ -31,7 +33,7 @@ type Client interface {
StopInstance(d *Driver) error StopInstance(d *Driver) error
RestartInstance(d *Driver) error RestartInstance(d *Driver) error
DeleteInstance(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) GetInstanceIpAddresses(d *Driver) ([]IpAddress, error)
CreateKeyPair(d *Driver, name string, publicKey string) error CreateKeyPair(d *Driver, name string, publicKey string) error
DeleteKeyPair(d *Driver, name string) error DeleteKeyPair(d *Driver, name string) error
@ -132,11 +134,23 @@ func (c *GenericClient) DeleteInstance(d *Driver) error {
return nil return nil
} }
func (c *GenericClient) WaitForInstanceStatus(d *Driver, status string, timeout int) error { func (c *GenericClient) WaitForInstanceStatus(d *Driver, status string) error {
if err := servers.WaitForStatus(c.Compute, d.MachineId, status, timeout); err != nil { return utils.WaitForSpecificOrError(func() (bool, error) {
return err current, err := servers.Get(c.Compute, d.MachineId).Extract()
} if err != nil {
return 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) { func (c *GenericClient) GetInstanceIpAddresses(d *Driver) ([]IpAddress, error) {

View File

@ -664,7 +664,7 @@ func (d *Driver) assignFloatingIp() error {
func (d *Driver) waitForInstanceActive() error { func (d *Driver) waitForInstanceActive() error {
log.WithField("MachineId", d.MachineId).Debug("Waiting for the OpenStack instance to be ACTIVE...") 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 err
} }
return nil return nil