github.com/rothwerx/packer@v0.9.0/builder/parallels/common/step_attach_floppy.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 a floppy to the virtual machine. 11 // 12 // Uses: 13 // driver Driver 14 // ui packer.Ui 15 // vmName string 16 // 17 // Produces: 18 type StepAttachFloppy struct { 19 floppyPath string 20 } 21 22 func (s *StepAttachFloppy) Run(state multistep.StateBag) multistep.StepAction { 23 // Determine if we even have a floppy disk to attach 24 var floppyPath string 25 if floppyPathRaw, ok := state.GetOk("floppy_path"); ok { 26 floppyPath = floppyPathRaw.(string) 27 } else { 28 log.Println("No floppy disk, not attaching.") 29 return multistep.ActionContinue 30 } 31 32 driver := state.Get("driver").(Driver) 33 ui := state.Get("ui").(packer.Ui) 34 vmName := state.Get("vmName").(string) 35 36 ui.Say("Deleting any current floppy disk...") 37 // Delete the floppy disk controller 38 del_command := []string{ 39 "set", vmName, 40 "--device-del", "fdd0", 41 } 42 // This will almost certainly fail with 'The fdd0 device does not exist.' 43 driver.Prlctl(del_command...) 44 45 ui.Say("Attaching floppy disk...") 46 // Attaching the floppy disk 47 add_command := []string{ 48 "set", vmName, 49 "--device-add", "fdd", 50 "--image", floppyPath, 51 "--connect", 52 } 53 if err := driver.Prlctl(add_command...); err != nil { 54 state.Put("error", fmt.Errorf("Error adding floppy: %s", err)) 55 return multistep.ActionHalt 56 } 57 58 // Track the path so that we can unregister it from Parallels later 59 s.floppyPath = floppyPath 60 61 return multistep.ActionContinue 62 } 63 64 func (s *StepAttachFloppy) Cleanup(state multistep.StateBag) { 65 driver := state.Get("driver").(Driver) 66 vmName := state.Get("vmName").(string) 67 68 if s.floppyPath == "" { 69 return 70 } 71 72 log.Println("Detaching floppy disk...") 73 command := []string{ 74 "set", vmName, 75 "--device-del", "fdd0", 76 } 77 driver.Prlctl(command...) 78 }