github.com/rothwerx/packer@v0.9.0/builder/parallels/common/step_attach_parallels_tools.go (about) 1 package common 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 "log" 8 ) 9 10 // This step attaches the Parallels Tools as an inserted CD onto 11 // the virtual machine. 12 // 13 // Uses: 14 // driver Driver 15 // parallels_tools_path string 16 // ui packer.Ui 17 // vmName string 18 // 19 // Produces: 20 type StepAttachParallelsTools struct { 21 cdromDevice string 22 ParallelsToolsMode string 23 } 24 25 func (s *StepAttachParallelsTools) Run(state multistep.StateBag) multistep.StepAction { 26 driver := state.Get("driver").(Driver) 27 ui := state.Get("ui").(packer.Ui) 28 vmName := state.Get("vmName").(string) 29 30 // If we're not attaching the guest additions then just return 31 if s.ParallelsToolsMode != ParallelsToolsModeAttach { 32 log.Println("Not attaching parallels tools since we're uploading.") 33 return multistep.ActionContinue 34 } 35 36 // Get the Paralells Tools path on the host machine 37 parallelsToolsPath := state.Get("parallels_tools_path").(string) 38 39 // Attach the guest additions to the computer 40 ui.Say("Attaching Parallels Tools ISO to the new CD/DVD drive...") 41 42 cdrom, err := driver.DeviceAddCdRom(vmName, parallelsToolsPath) 43 44 if err != nil { 45 err := fmt.Errorf("Error attaching Parallels Tools ISO: %s", err) 46 state.Put("error", err) 47 ui.Error(err.Error()) 48 return multistep.ActionHalt 49 } 50 51 // Track the device name so that we can can delete later 52 s.cdromDevice = cdrom 53 54 return multistep.ActionContinue 55 } 56 57 func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) { 58 if s.cdromDevice == "" { 59 return 60 } 61 62 driver := state.Get("driver").(Driver) 63 ui := state.Get("ui").(packer.Ui) 64 vmName := state.Get("vmName").(string) 65 66 log.Println("Detaching Parallels Tools ISO...") 67 68 command := []string{ 69 "set", vmName, 70 "--device-del", s.cdromDevice, 71 } 72 73 if err := driver.Prlctl(command...); err != nil { 74 ui.Error(fmt.Sprintf("Error detaching Parallels Tools ISO: %s", err)) 75 } 76 }