2014-04-06 13:21:22 -04:00
|
|
|
package pvm
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2014-04-06 13:21:22 -04:00
|
|
|
"fmt"
|
2016-12-11 14:13:37 -05:00
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2017-04-04 16:39:01 -04:00
|
|
|
parallelscommon "github.com/hashicorp/packer/builder/parallels/common"
|
2014-04-06 13:21:22 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// This step imports an PVM VM into Parallels.
|
|
|
|
type StepImport struct {
|
|
|
|
Name string
|
|
|
|
SourcePath string
|
|
|
|
vmName string
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepImport) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2014-04-06 13:21:22 -04:00
|
|
|
driver := state.Get("driver").(parallelscommon.Driver)
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2014-04-06 13:21:22 -04:00
|
|
|
config := state.Get("config").(*Config)
|
|
|
|
|
|
|
|
ui.Say(fmt.Sprintf("Importing VM: %s", s.SourcePath))
|
2016-12-11 13:49:54 -05:00
|
|
|
if err := driver.Import(s.Name, s.SourcePath, config.OutputDir, config.ReassignMAC); err != nil {
|
2014-04-06 13:21:22 -04:00
|
|
|
err := fmt.Errorf("Error importing VM: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
s.vmName = s.Name
|
|
|
|
state.Put("vmName", s.Name)
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepImport) Cleanup(state multistep.StateBag) {
|
|
|
|
|
|
|
|
if s.vmName == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
driver := state.Get("driver").(parallelscommon.Driver)
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2014-04-06 13:21:22 -04:00
|
|
|
|
|
|
|
ui.Say("Unregistering virtual machine...")
|
|
|
|
if err := driver.Prlctl("unregister", s.vmName); err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Error unregistering virtual machine: %s", err))
|
|
|
|
}
|
|
|
|
}
|