packer-cn/builder/hyperone/step_detach_disk.go

35 lines
925 B
Go
Raw Normal View History

2019-01-28 06:30:15 -05:00
package hyperone
import (
"context"
"fmt"
2020-11-17 19:31:03 -05:00
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
openapi "github.com/hyperonecom/h1-client-go"
2019-01-28 06:30:15 -05:00
)
type stepDetachDisk struct {
vmID string
}
func (s *stepDetachDisk) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*openapi.APIClient)
ui := state.Get("ui").(packersdk.Ui)
2019-01-28 06:30:15 -05:00
vmID := state.Get("vm_id").(string)
chrootDiskID := state.Get("chroot_disk_id").(string)
ui.Say("Detaching chroot disk...")
_, _, err := client.VmApi.VmDeleteHddDiskId(ctx, vmID, chrootDiskID)
if err != nil {
err := fmt.Errorf("error detaching disk: %s", formatOpenAPIError(err))
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
return multistep.ActionContinue
}
func (s *stepDetachDisk) Cleanup(state multistep.StateBag) {}