From 7a45e4c8b074600d9327f1dadf6ba7bdb5eef7ca Mon Sep 17 00:00:00 2001 From: Marin Salinas Date: Fri, 21 Aug 2020 10:40:14 -0500 Subject: [PATCH] refactor: change step tag bsu volumes to new OSC SDK --- builder/osc/common/state.go | 6 ++++++ builder/osc/common/step_stop_bsu_backed_vm.go | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/builder/osc/common/state.go b/builder/osc/common/state.go index dd9ddc378..62e763043 100644 --- a/builder/osc/common/state.go +++ b/builder/osc/common/state.go @@ -52,6 +52,12 @@ func waitUntilVmStopped(conn *oapi.Client, vmID string) error { return <-errCh } +func waitUntilOscVmStopped(conn *osc.APIClient, vmID string) error { + errCh := make(chan error, 1) + go waitForState(errCh, "stopped", waitUntilOscVmStateFunc(conn, vmID)) + return <-errCh +} + func WaitUntilSnapshotCompleted(conn *oapi.Client, id string) error { errCh := make(chan error, 1) go waitForState(errCh, "completed", waitUntilSnapshotStateFunc(conn, id)) diff --git a/builder/osc/common/step_stop_bsu_backed_vm.go b/builder/osc/common/step_stop_bsu_backed_vm.go index 79bd693c8..9c31a3c8b 100644 --- a/builder/osc/common/step_stop_bsu_backed_vm.go +++ b/builder/osc/common/step_stop_bsu_backed_vm.go @@ -4,11 +4,11 @@ import ( "context" "fmt" + "github.com/antihax/optional" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" - "github.com/outscale/osc-go/oapi" "github.com/outscale/osc-sdk-go/osc" ) @@ -18,7 +18,7 @@ type StepStopBSUBackedVm struct { } func (s *StepStopBSUBackedVm) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { - oapiconn := state.Get("oapi").(*oapi.Client) + oscconn := state.Get("osc").(*osc.APIClient) vm := state.Get("vm").(osc.Vm) ui := state.Get("ui").(packer.Ui) @@ -44,8 +44,10 @@ func (s *StepStopBSUBackedVm) Run(ctx context.Context, state multistep.StateBag) err := common.Retry(10, 60, 6, func(i uint) (bool, error) { ui.Message(fmt.Sprintf("Stopping vm, attempt %d", i+1)) - _, err = oapiconn.POST_StopVms(oapi.StopVmsRequest{ - VmIds: []string{vm.VmId}, + _, _, err = oscconn.VmApi.StopVms(context.Background(), &osc.StopVmsOpts{ + StopVmsRequest: optional.NewInterface(osc.StopVmsRequest{ + VmIds: []string{vm.VmId}, + }), }) if err == nil { @@ -79,7 +81,7 @@ func (s *StepStopBSUBackedVm) Run(ctx context.Context, state multistep.StateBag) // Wait for the vm to actually stop ui.Say("Waiting for the vm to stop...") - err = waitUntilVmStopped(oapiconn, vm.VmId) + err = waitUntilOscVmStopped(oscconn, vm.VmId) if err != nil { err := fmt.Errorf("Error waiting for vm to stop: %s", err)