diff --git a/builder/parallels/common/driver.go b/builder/parallels/common/driver.go index babc38c32..771395d8c 100644 --- a/builder/parallels/common/driver.go +++ b/builder/parallels/common/driver.go @@ -15,6 +15,9 @@ import ( // versions out of the builder steps, so sometimes the methods are // extremely specific. type Driver interface { + // Adds new CD/DVD drive to the VM and returns name of this device + DeviceAddCdRom(string, string) (string, error) + // Import a VM Import(string, string, string, bool) error diff --git a/builder/parallels/common/driver_9.go b/builder/parallels/common/driver_9.go index 97002cb86..7661a30c7 100644 --- a/builder/parallels/common/driver_9.go +++ b/builder/parallels/common/driver_9.go @@ -95,6 +95,29 @@ func getAppPath(bundleId string) (string, error) { return pathOutput, nil } +func (d *Parallels9Driver) DeviceAddCdRom(name string, image string) (string, error) { + command := []string{ + "set", name, + "--device-add", "cdrom", + "--image", image, + } + + out, err := exec.Command(d.PrlctlPath, command...).Output() + if err != nil { + return "", err + } + + deviceRe := regexp.MustCompile(`\s+(cdrom\d+)\s+`) + matches := deviceRe.FindStringSubmatch(string(out)) + if matches == nil { + return "", fmt.Errorf( + "Could not determine cdrom device name in the output:\n%s", string(out)) + } + + device_name := matches[1] + return device_name, nil +} + func (d *Parallels9Driver) IsRunning(name string) (bool, error) { var stdout bytes.Buffer diff --git a/builder/parallels/common/driver_mock.go b/builder/parallels/common/driver_mock.go index 77761586a..25e4ea182 100644 --- a/builder/parallels/common/driver_mock.go +++ b/builder/parallels/common/driver_mock.go @@ -5,6 +5,12 @@ import "sync" type DriverMock struct { sync.Mutex + DeviceAddCdRomCalled bool + DeviceAddCdRomName string + DeviceAddCdRomImage string + DeviceAddCdRomResult string + DeviceAddCdRomErr error + ImportCalled bool ImportName string ImportSrcPath string @@ -45,6 +51,13 @@ type DriverMock struct { IpAddressError error } +func (d *DriverMock) DeviceAddCdRom(name string, image string) (string, error) { + d.DeviceAddCdRomCalled = true + d.DeviceAddCdRomName = name + d.DeviceAddCdRomImage = image + return d.DeviceAddCdRomResult, d.DeviceAddCdRomErr +} + func (d *DriverMock) Import(name, srcPath, dstPath string, reassignMac bool) error { d.ImportCalled = true d.ImportName = name