github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/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 // attachedToolsIso boolean 21 type StepAttachParallelsTools struct { 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 onto IDE controller...") 41 command := []string{ 42 "set", vmName, 43 "--device-add", "cdrom", 44 "--image", parallelsToolsPath, 45 } 46 if err := driver.Prlctl(command...); err != nil { 47 err := fmt.Errorf("Error attaching Parallels Tools: %s", err) 48 state.Put("error", err) 49 ui.Error(err.Error()) 50 return multistep.ActionHalt 51 } 52 53 // Set some state so we know to remove 54 state.Put("attachedToolsIso", true) 55 56 return multistep.ActionContinue 57 } 58 59 func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) { 60 if _, ok := state.GetOk("attachedToolsIso"); !ok { 61 return 62 } 63 64 driver := state.Get("driver").(Driver) 65 ui := state.Get("ui").(packer.Ui) 66 vmName := state.Get("vmName").(string) 67 68 log.Println("Detaching Parallels Tools ISO...") 69 cdDevice := "cdrom0" 70 if _, ok := state.GetOk("attachedIso"); ok { 71 cdDevice = "cdrom1" 72 } 73 74 command := []string{ 75 "set", vmName, 76 "--device-del", cdDevice, 77 } 78 79 if err := driver.Prlctl(command...); err != nil { 80 ui.Error(fmt.Sprintf("Error detaching Parallels Tools ISO: %s", err)) 81 } 82 }