|
|
|
|
@ -10,7 +10,8 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type stepStopAlicloudInstance struct {
|
|
|
|
|
ForceStop bool
|
|
|
|
|
ForceStop bool
|
|
|
|
|
DisableStop bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *stepStopAlicloudInstance) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
@ -18,8 +19,9 @@ func (s *stepStopAlicloudInstance) Run(_ context.Context, state multistep.StateB
|
|
|
|
|
instance := state.Get("instance").(*ecs.InstanceAttributesType)
|
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
|
|
|
|
|
err := client.StopInstance(instance.InstanceId, s.ForceStop)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if !s.DisableStop {
|
|
|
|
|
ui.Say(fmt.Sprintf("Stopping instance: %s", instance.InstanceId))
|
|
|
|
|
err := client.StopInstance(instance.InstanceId, s.ForceStop)
|
|
|
|
|
if err != nil {
|
|
|
|
|
err := fmt.Errorf("Error stopping alicloud instance: %s", err)
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
@ -28,7 +30,9 @@ func (s *stepStopAlicloudInstance) Run(_ context.Context, state multistep.StateB
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = client.WaitForInstance(instance.InstanceId, ecs.Stopped, ALICLOUD_DEFAULT_TIMEOUT)
|
|
|
|
|
ui.Say(fmt.Sprintf("Waiting instance stopped: %s", instance.InstanceId))
|
|
|
|
|
|
|
|
|
|
err := client.WaitForInstance(instance.InstanceId, ecs.Stopped, ALICLOUD_DEFAULT_TIMEOUT)
|
|
|
|
|
if err != nil {
|
|
|
|
|
err := fmt.Errorf("Error waiting for alicloud instance to stop: %s", err)
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
|