2014-12-29 06:46:54 -06:00
|
|
|
package common
|
2014-11-10 12:16:02 -06:00
|
|
|
|
|
|
|
import (
|
2021-01-03 16:08:24 -06:00
|
|
|
"context"
|
2014-12-09 08:02:48 -06:00
|
|
|
"fmt"
|
2020-09-13 03:21:07 -05:00
|
|
|
|
2021-02-23 16:43:20 -06:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/packer"
|
2014-11-10 12:16:02 -06:00
|
|
|
)
|
|
|
|
|
2021-03-24 01:36:34 -05:00
|
|
|
type StepStartVmPaused struct {
|
|
|
|
VmCleanup
|
|
|
|
}
|
2014-11-10 12:16:02 -06:00
|
|
|
|
2021-01-03 16:08:24 -06:00
|
|
|
func (self *StepStartVmPaused) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2014-11-10 12:16:02 -06:00
|
|
|
|
2020-09-13 03:21:07 -05:00
|
|
|
c := state.Get("client").(*Connection)
|
2014-12-08 09:34:48 -06:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2022-06-05 10:28:23 -05:00
|
|
|
config := state.Get("config").(Config)
|
2014-11-10 12:16:02 -06:00
|
|
|
|
2014-12-08 09:34:48 -06:00
|
|
|
ui.Say("Step: Start VM Paused")
|
2014-11-10 12:16:02 -06:00
|
|
|
|
2014-12-09 08:02:48 -06:00
|
|
|
uuid := state.Get("instance_uuid").(string)
|
2020-09-13 03:21:07 -05:00
|
|
|
instance, err := c.client.VM.GetByUUID(c.session, uuid)
|
2014-12-09 08:02:48 -06:00
|
|
|
if err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Unable to get VM from UUID '%s': %s", uuid, err.Error()))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2015-01-06 05:34:44 -06:00
|
|
|
// note that here "cd" means boot from hard drive ('c') first, then CDROM ('d')
|
2020-09-13 03:21:07 -05:00
|
|
|
err = c.client.VM.SetHVMBootPolicy(c.session, instance, "BIOS order")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Unable to set HVM boot params: %s", err.Error()))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2022-06-05 10:28:23 -05:00
|
|
|
err = c.client.VM.SetHVMBootParams(c.session, instance, map[string]string{"order": "cd", "firmware": config.Firmware})
|
2015-01-06 05:34:44 -06:00
|
|
|
if err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Unable to set HVM boot params: %s", err.Error()))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2020-09-13 03:21:07 -05:00
|
|
|
err = c.client.VM.Start(c.session, instance, true, false)
|
2014-12-09 08:02:48 -06:00
|
|
|
if err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Unable to start VM with UUID '%s': %s", uuid, err.Error()))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2020-09-13 03:21:07 -05:00
|
|
|
domid, err := c.client.VM.GetDomid(c.session, instance)
|
2014-12-09 08:02:48 -06:00
|
|
|
if err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Unable to get domid of VM with UUID '%s': %s", uuid, err.Error()))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2014-12-08 09:34:48 -06:00
|
|
|
state.Put("domid", domid)
|
2014-11-10 12:16:02 -06:00
|
|
|
|
2014-12-08 09:34:48 -06:00
|
|
|
return multistep.ActionContinue
|
2014-11-10 12:16:02 -06:00
|
|
|
}
|