providers/digitalocean: restart droplet in failed resize

This commit is contained in:
Jack Pearkes 2014-08-01 10:10:52 -04:00
parent 8679ae6a2f
commit 2fe6f2e2b1
1 changed files with 27 additions and 0 deletions

View File

@ -112,6 +112,10 @@ func resource_digitalocean_droplet_update(
err = client.Resize(rs.ID, attr.New)
if err != nil {
newErr := power_on_and_wait(rs.ID, client)
if newErr != nil {
return rs, newErr
}
return rs, err
}
@ -120,6 +124,10 @@ func resource_digitalocean_droplet_update(
rs.ID, attr.New, []string{"", attr.Old}, "size", client)
if err != nil {
newErr := power_on_and_wait(rs.ID, client)
if newErr != nil {
return rs, newErr
}
return s, err
}
@ -376,3 +384,22 @@ func new_droplet_state_refresh_func(id string, attribute string, client *digital
return nil, "", nil
}
}
// Powers on the droplet and waits for it to be active
func power_on_and_wait(id string, client *digitalocean.Client) error {
err := client.PowerOn(id)
if err != nil {
return err
}
// Wait for power off
_, err = WaitForDropletAttribute(
id, "active", []string{"off"}, "status", client)
if err != nil {
return err
}
return nil
}