builder/parallels: Add "DiskPath" driver function

This function determines path to the first virtual disk image of the specified virtual machine.
This commit is contained in:
Mikhail Zholobov 2015-06-21 12:17:06 +03:00
parent 17cea4fa95
commit 4ebee7bf3f
3 changed files with 31 additions and 0 deletions

View File

@ -18,6 +18,9 @@ type Driver interface {
// Adds new CD/DVD drive to the VM and returns name of this device // Adds new CD/DVD drive to the VM and returns name of this device
DeviceAddCdRom(string, string) (string, error) DeviceAddCdRom(string, string) (string, error)
// Get path to the first virtual disk image
DiskPath(string) (string, error)
// Import a VM // Import a VM
Import(string, string, string, bool) error Import(string, string, string, bool) error

View File

@ -121,6 +121,23 @@ func (d *Parallels9Driver) DeviceAddCdRom(name string, image string) (string, er
return device_name, nil return device_name, nil
} }
func (d *Parallels9Driver) DiskPath(name string) (string, error) {
out, err := exec.Command(d.PrlctlPath, "list", "-i", name).Output()
if err != nil {
return "", err
}
hddRe := regexp.MustCompile("hdd0.* image='(.*)' type=*")
matches := hddRe.FindStringSubmatch(string(out))
if matches == nil {
return "", fmt.Errorf(
"Could not determine hdd image path in the output:\n%s", string(out))
}
hdd_path := matches[1]
return hdd_path, 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

View File

@ -11,6 +11,11 @@ type DriverMock struct {
DeviceAddCdRomResult string DeviceAddCdRomResult string
DeviceAddCdRomErr error DeviceAddCdRomErr error
DiskPathCalled bool
DiskPathName string
DiskPathResult string
DiskPathErr error
ImportCalled bool ImportCalled bool
ImportName string ImportName string
ImportSrcPath string ImportSrcPath string
@ -61,6 +66,12 @@ func (d *DriverMock) DeviceAddCdRom(name string, image string) (string, error) {
return d.DeviceAddCdRomResult, d.DeviceAddCdRomErr return d.DeviceAddCdRomResult, d.DeviceAddCdRomErr
} }
func (d *DriverMock) DiskPath(name string) (string, error) {
d.DiskPathCalled = true
d.DiskPathName = name
return d.DiskPathResult, d.DiskPathErr
}
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