builder/parallels: Added driver method 'DeviceAddCdRom'
This commit is contained in:
parent
5394ce61fd
commit
0cfe58193f
|
@ -15,6 +15,9 @@ import (
|
||||||
// versions out of the builder steps, so sometimes the methods are
|
// versions out of the builder steps, so sometimes the methods are
|
||||||
// extremely specific.
|
// extremely specific.
|
||||||
type Driver interface {
|
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 a VM
|
||||||
Import(string, string, string, bool) error
|
Import(string, string, string, bool) error
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,29 @@ func getAppPath(bundleId string) (string, error) {
|
||||||
return pathOutput, nil
|
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) {
|
func (d *Parallels9Driver) IsRunning(name string) (bool, error) {
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,12 @@ import "sync"
|
||||||
type DriverMock struct {
|
type DriverMock struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
|
||||||
|
DeviceAddCdRomCalled bool
|
||||||
|
DeviceAddCdRomName string
|
||||||
|
DeviceAddCdRomImage string
|
||||||
|
DeviceAddCdRomResult string
|
||||||
|
DeviceAddCdRomErr error
|
||||||
|
|
||||||
ImportCalled bool
|
ImportCalled bool
|
||||||
ImportName string
|
ImportName string
|
||||||
ImportSrcPath string
|
ImportSrcPath string
|
||||||
|
@ -45,6 +51,13 @@ type DriverMock struct {
|
||||||
IpAddressError error
|
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 {
|
func (d *DriverMock) Import(name, srcPath, dstPath string, reassignMac bool) error {
|
||||||
d.ImportCalled = true
|
d.ImportCalled = true
|
||||||
d.ImportName = name
|
d.ImportName = name
|
||||||
|
|
Loading…
Reference in New Issue