github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/builder/parallels/iso/step_attach_iso.go (about) 1 package iso 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 parallelscommon "github.com/mitchellh/packer/builder/parallels/common" 7 "github.com/mitchellh/packer/packer" 8 "log" 9 ) 10 11 // This step attaches the ISO to the virtual machine. 12 // 13 // Uses: 14 // 15 // Produces: 16 type stepAttachISO struct { 17 diskPath string 18 } 19 20 func (s *stepAttachISO) Run(state multistep.StateBag) multistep.StepAction { 21 driver := state.Get("driver").(parallelscommon.Driver) 22 isoPath := state.Get("iso_path").(string) 23 ui := state.Get("ui").(packer.Ui) 24 vmName := state.Get("vmName").(string) 25 26 // Attach the disk to the controller 27 ui.Say("Attaching ISO onto IDE controller...") 28 command := []string{ 29 "set", vmName, 30 "--device-set", "cdrom0", 31 "--image", isoPath, 32 "--enable", "--connect", 33 } 34 if err := driver.Prlctl(command...); err != nil { 35 err := fmt.Errorf("Error attaching ISO: %s", err) 36 state.Put("error", err) 37 ui.Error(err.Error()) 38 return multistep.ActionHalt 39 } 40 41 // Set some state so we know to remove 42 state.Put("attachedIso", true) 43 44 return multistep.ActionContinue 45 } 46 47 func (s *stepAttachISO) Cleanup(state multistep.StateBag) { 48 if _, ok := state.GetOk("attachedIso"); !ok { 49 return 50 } 51 52 driver := state.Get("driver").(parallelscommon.Driver) 53 vmName := state.Get("vmName").(string) 54 55 command := []string{ 56 "set", vmName, 57 "--device-set", "cdrom0", 58 "--enable", "--disconnect", 59 } 60 61 // Remove the ISO, ignore errors 62 log.Println("Detaching ISO...") 63 driver.Prlctl(command...) 64 }