From 4ebee7bf3f4fecf7b49018225e798de845b3dbe2 Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Sun, 21 Jun 2015 12:17:06 +0300 Subject: [PATCH] builder/parallels: Add "DiskPath" driver function This function determines path to the first virtual disk image of the specified virtual machine. --- builder/parallels/common/driver.go | 3 +++ builder/parallels/common/driver_9.go | 17 +++++++++++++++++ builder/parallels/common/driver_mock.go | 11 +++++++++++ 3 files changed, 31 insertions(+) diff --git a/builder/parallels/common/driver.go b/builder/parallels/common/driver.go index 03a4e0f09..81b7cd974 100644 --- a/builder/parallels/common/driver.go +++ b/builder/parallels/common/driver.go @@ -18,6 +18,9 @@ type Driver interface { // Adds new CD/DVD drive to the VM and returns name of this device DeviceAddCdRom(string, string) (string, error) + // Get path to the first virtual disk image + DiskPath(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 c577151dc..1093351c8 100644 --- a/builder/parallels/common/driver_9.go +++ b/builder/parallels/common/driver_9.go @@ -121,6 +121,23 @@ func (d *Parallels9Driver) DeviceAddCdRom(name string, image string) (string, er 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) { var stdout bytes.Buffer diff --git a/builder/parallels/common/driver_mock.go b/builder/parallels/common/driver_mock.go index 5629a6db9..fc43247f5 100644 --- a/builder/parallels/common/driver_mock.go +++ b/builder/parallels/common/driver_mock.go @@ -11,6 +11,11 @@ type DriverMock struct { DeviceAddCdRomResult string DeviceAddCdRomErr error + DiskPathCalled bool + DiskPathName string + DiskPathResult string + DiskPathErr error + ImportCalled bool ImportName string ImportSrcPath string @@ -61,6 +66,12 @@ func (d *DriverMock) DeviceAddCdRom(name string, image string) (string, error) { 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 { d.ImportCalled = true d.ImportName = name