github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/alicloud/ecs/step_stop_instance.go (about) 1 package ecs 2 3 import ( 4 "fmt" 5 6 "github.com/denverdino/aliyungo/ecs" 7 "github.com/hashicorp/packer/packer" 8 "github.com/mitchellh/multistep" 9 ) 10 11 type stepStopAlicloudInstance struct { 12 ForceStop bool 13 } 14 15 func (s *stepStopAlicloudInstance) Run(state multistep.StateBag) multistep.StepAction { 16 client := state.Get("client").(*ecs.Client) 17 instance := state.Get("instance").(*ecs.InstanceAttributesType) 18 ui := state.Get("ui").(packer.Ui) 19 20 err := client.StopInstance(instance.InstanceId, s.ForceStop) 21 if err != nil { 22 if err != nil { 23 err := fmt.Errorf("Error stopping alicloud instance: %s", err) 24 state.Put("error", err) 25 ui.Error(err.Error()) 26 return multistep.ActionHalt 27 } 28 } 29 30 err = client.WaitForInstance(instance.InstanceId, ecs.Stopped, ALICLOUD_DEFAULT_TIMEOUT) 31 if err != nil { 32 err := fmt.Errorf("Error waiting for alicloud instance to stop: %s", err) 33 state.Put("error", err) 34 ui.Error(err.Error()) 35 return multistep.ActionHalt 36 } 37 38 return multistep.ActionContinue 39 } 40 41 func (s *stepStopAlicloudInstance) Cleanup(multistep.StateBag) { 42 // No cleanup... 43 }