github.com/homburg/packer@v0.6.1-0.20140528012651-1dcaf1716848/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("Attaching floppy disk...") 37 38 // Create the floppy disk controller 39 command := []string{ 40 "set", vmName, 41 "--device-add", "fdd", 42 "--image", floppyPath, 43 } 44 if err := driver.Prlctl(command...); err != nil { 45 state.Put("error", fmt.Errorf("Error adding floppy: %s", err)) 46 return multistep.ActionHalt 47 } 48 49 // Track the path so that we can unregister it from Parallels later 50 s.floppyPath = floppyPath 51 52 return multistep.ActionContinue 53 } 54 55 func (s *StepAttachFloppy) Cleanup(state multistep.StateBag) {}