github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/builder/parallels/pvm/step_import.go (about) 1 package pvm 2 3 import ( 4 "fmt" 5 6 "github.com/mitchellh/multistep" 7 parallelscommon "github.com/mitchellh/packer/builder/parallels/common" 8 "github.com/mitchellh/packer/packer" 9 ) 10 11 // This step imports an PVM VM into Parallels. 12 type StepImport struct { 13 Name string 14 SourcePath string 15 vmName string 16 } 17 18 func (s *StepImport) Run(state multistep.StateBag) multistep.StepAction { 19 driver := state.Get("driver").(parallelscommon.Driver) 20 ui := state.Get("ui").(packer.Ui) 21 config := state.Get("config").(*Config) 22 23 ui.Say(fmt.Sprintf("Importing VM: %s", s.SourcePath)) 24 if err := driver.Import(s.Name, s.SourcePath, config.OutputDir, config.ReassignMAC); err != nil { 25 err := fmt.Errorf("Error importing VM: %s", err) 26 state.Put("error", err) 27 ui.Error(err.Error()) 28 return multistep.ActionHalt 29 } 30 31 s.vmName = s.Name 32 state.Put("vmName", s.Name) 33 return multistep.ActionContinue 34 } 35 36 func (s *StepImport) Cleanup(state multistep.StateBag) { 37 38 if s.vmName == "" { 39 return 40 } 41 42 driver := state.Get("driver").(parallelscommon.Driver) 43 ui := state.Get("ui").(packer.Ui) 44 45 ui.Say("Unregistering virtual machine...") 46 if err := driver.Prlctl("unregister", s.vmName); err != nil { 47 ui.Error(fmt.Sprintf("Error unregistering virtual machine: %s", err)) 48 } 49 }