2014-04-06 13:21:22 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-12-11 14:13:37 -05:00
|
|
|
"log"
|
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2014-04-06 13:21:22 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
)
|
|
|
|
|
2016-12-11 17:37:41 -05:00
|
|
|
// StepAttachFloppy is a step that attaches a floppy to the virtual machine.
|
2014-04-06 13:21:22 -04:00
|
|
|
//
|
|
|
|
// Uses:
|
|
|
|
// driver Driver
|
|
|
|
// ui packer.Ui
|
|
|
|
// vmName string
|
|
|
|
//
|
|
|
|
// Produces:
|
|
|
|
type StepAttachFloppy struct {
|
|
|
|
floppyPath string
|
|
|
|
}
|
|
|
|
|
2016-12-16 14:51:55 -05:00
|
|
|
// Run adds a virtual FDD device to the VM and attaches the image.
|
|
|
|
// If the image is not specified, then this step will be skipped.
|
2014-04-06 13:21:22 -04:00
|
|
|
func (s *StepAttachFloppy) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
// Determine if we even have a floppy disk to attach
|
|
|
|
var floppyPath string
|
|
|
|
if floppyPathRaw, ok := state.GetOk("floppy_path"); ok {
|
|
|
|
floppyPath = floppyPathRaw.(string)
|
|
|
|
} else {
|
|
|
|
log.Println("No floppy disk, not attaching.")
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
driver := state.Get("driver").(Driver)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
vmName := state.Get("vmName").(string)
|
|
|
|
|
2014-06-06 09:54:19 -04:00
|
|
|
ui.Say("Deleting any current floppy disk...")
|
|
|
|
// Delete the floppy disk controller
|
2016-12-11 13:49:54 -05:00
|
|
|
delCommand := []string{
|
2014-06-06 09:54:19 -04:00
|
|
|
"set", vmName,
|
|
|
|
"--device-del", "fdd0",
|
|
|
|
}
|
2014-09-15 17:57:39 -04:00
|
|
|
// This will almost certainly fail with 'The fdd0 device does not exist.'
|
2016-12-11 13:49:54 -05:00
|
|
|
driver.Prlctl(delCommand...)
|
2014-04-06 13:21:22 -04:00
|
|
|
|
2014-09-15 17:57:39 -04:00
|
|
|
ui.Say("Attaching floppy disk...")
|
2014-08-08 02:12:48 -04:00
|
|
|
// Attaching the floppy disk
|
2016-12-11 13:49:54 -05:00
|
|
|
addCommand := []string{
|
2014-04-06 13:21:22 -04:00
|
|
|
"set", vmName,
|
|
|
|
"--device-add", "fdd",
|
|
|
|
"--image", floppyPath,
|
2014-06-06 09:54:19 -04:00
|
|
|
"--connect",
|
2014-04-06 13:21:22 -04:00
|
|
|
}
|
2016-12-11 13:49:54 -05:00
|
|
|
if err := driver.Prlctl(addCommand...); err != nil {
|
2014-04-06 13:21:22 -04:00
|
|
|
state.Put("error", fmt.Errorf("Error adding floppy: %s", err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
// Track the path so that we can unregister it from Parallels later
|
|
|
|
s.floppyPath = floppyPath
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2016-12-16 14:51:55 -05:00
|
|
|
// Cleanup removes the virtual FDD device attached to the VM.
|
2014-08-08 02:12:48 -04:00
|
|
|
func (s *StepAttachFloppy) Cleanup(state multistep.StateBag) {
|
|
|
|
driver := state.Get("driver").(Driver)
|
|
|
|
vmName := state.Get("vmName").(string)
|
|
|
|
|
|
|
|
if s.floppyPath == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("Detaching floppy disk...")
|
|
|
|
command := []string{
|
|
|
|
"set", vmName,
|
|
|
|
"--device-del", "fdd0",
|
|
|
|
}
|
|
|
|
driver.Prlctl(command...)
|
|
|
|
}
|