Merge pull request #4872 from sean-/f-synchronous-deletes

Synchronous Deletes for Triton Machines
This commit is contained in:
James Nugent 2017-05-10 17:07:36 -05:00 committed by GitHub
commit bad36dfc2d
4 changed files with 24 additions and 13 deletions

View File

@ -3,6 +3,7 @@ package triton
import (
"context"
"errors"
"net/http"
"time"
"github.com/hashicorp/packer/packer"
@ -129,15 +130,16 @@ func (d *driverTriton) WaitForMachineState(machineId string, state string, timeo
func (d *driverTriton) WaitForMachineDeletion(machineId string, timeout time.Duration) error {
return waitFor(
func() (bool, error) {
machine, err := d.client.Machines().GetMachine(context.Background(), &triton.GetMachineInput{
_, err := d.client.Machines().GetMachine(context.Background(), &triton.GetMachineInput{
ID: machineId,
})
if err != nil && triton.IsResourceNotFound(err) {
return true, nil
}
if machine != nil {
return machine.State == "deleted", nil
if err != nil {
// Return true only when we receive a 410 (Gone) response. A 404
// indicates that the machine is being deleted whereas a 410 indicates
// that this process has completed.
if triErr, ok := err.(*triton.TritonError); ok && triErr.StatusCode == http.StatusGone {
return true, nil
}
}
return false, err

View File

@ -64,5 +64,12 @@ func (s *StepCreateSourceMachine) Cleanup(state multistep.StateBag) {
state.Put("error", fmt.Errorf("Problem deleting source machine: %s", err))
return
}
ui.Say(fmt.Sprintf("Waiting for source machine to be destroyed (%s)...", machineId))
err = driver.WaitForMachineDeletion(machineId, 10*time.Minute)
if err != nil {
state.Put("error", fmt.Errorf("Problem waiting for source machine to be deleted: %s", err))
return
}
}
}

View File

@ -102,7 +102,8 @@ func (client *MachinesClient) GetMachine(ctx context.Context, input *GetMachineI
}
if response.StatusCode == http.StatusNotFound || response.StatusCode == http.StatusGone {
return nil, &TritonError{
Code: "ResourceNotFound",
StatusCode: response.StatusCode,
Code: "ResourceNotFound",
}
}
if err != nil {
@ -134,7 +135,8 @@ func (client *MachinesClient) ListMachines(ctx context.Context, _ *ListMachinesI
}
if response.StatusCode == http.StatusNotFound {
return nil, &TritonError{
Code: "ResourceNotFound",
StatusCode: response.StatusCode,
Code: "ResourceNotFound",
}
}
if err != nil {
@ -249,7 +251,7 @@ func (client *MachinesClient) DeleteMachine(ctx context.Context, input *DeleteMa
if response.Body != nil {
defer response.Body.Close()
}
if response.StatusCode == http.StatusNotFound {
if response.StatusCode == http.StatusNotFound || response.StatusCode == http.StatusGone {
return nil
}
if err != nil {

6
vendor/vendor.json vendored
View File

@ -520,10 +520,10 @@
"revision": "c01cf91b011868172fdcd9f41838e80c9d716264"
},
{
"checksumSHA1": "3yw6Wr66v4WrQyY2hYveEmiFadM=",
"checksumSHA1": "cdoXZmgAhucjxu9V0xuAwwOoN0U=",
"path": "github.com/joyent/triton-go",
"revision": "16cef4c2d78ba1d3bf89af75e93ae2dec6e56634",
"revisionTime": "2017-05-04T20:45:05Z"
"revision": "97ccd9f6c0c0652cf87997bcb01955e0329cd37e",
"revisionTime": "2017-05-09T20:29:43Z"
},
{
"checksumSHA1": "QzUqkCSn/ZHyIK346xb9V6EBw9U=",