forked from hashicorp/packer
/
step_attach_floppy.go
78 lines (67 loc) · 1.78 KB
/
step_attach_floppy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package common
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
// This step attaches a floppy to the virtual machine.
//
// Uses:
// driver Driver
// ui packer.Ui
// vmName string
//
// Produces:
type StepAttachFloppy struct {
floppyPath string
}
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)
ui.Say("Deleting any current floppy disk...")
// Delete the floppy disk controller
del_command := []string{
"set", vmName,
"--device-del", "fdd0",
}
// This will almost certainly fail with 'The fdd0 device does not exist.'
driver.Prlctl(del_command...)
ui.Say("Attaching floppy disk...")
// Attaching the floppy disk
add_command := []string{
"set", vmName,
"--device-add", "fdd",
"--image", floppyPath,
"--connect",
}
if err := driver.Prlctl(add_command...); err != nil {
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
}
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...)
}