builder/parallels: Add "CompactDisk" driver function
This function compacts the specified virtual disk image.
This commit is contained in:
parent
4ebee7bf3f
commit
f7b26e44fe
|
@ -15,6 +15,9 @@ import (
|
|||
// versions out of the builder steps, so sometimes the methods are
|
||||
// extremely specific.
|
||||
type Driver interface {
|
||||
// Compact a virtual disk image.
|
||||
CompactDisk(string) error
|
||||
|
||||
// Adds new CD/DVD drive to the VM and returns name of this device
|
||||
DeviceAddCdRom(string, string) (string, error)
|
||||
|
||||
|
|
|
@ -98,6 +98,33 @@ func getAppPath(bundleId string) (string, error) {
|
|||
return pathOutput, nil
|
||||
}
|
||||
|
||||
func (d *Parallels9Driver) CompactDisk(diskPath string) error {
|
||||
prlDiskToolPath, err := exec.LookPath("prl_disk_tool")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Analyze the disk content and remove unused blocks
|
||||
command := []string{
|
||||
"compact",
|
||||
"--hdd", diskPath,
|
||||
}
|
||||
if err := exec.Command(prlDiskToolPath, command...).Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Remove null blocks
|
||||
command = []string{
|
||||
"compact", "--buildmap",
|
||||
"--hdd", diskPath,
|
||||
}
|
||||
if err := exec.Command(prlDiskToolPath, command...).Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Parallels9Driver) DeviceAddCdRom(name string, image string) (string, error) {
|
||||
command := []string{
|
||||
"set", name,
|
||||
|
|
|
@ -5,6 +5,10 @@ import "sync"
|
|||
type DriverMock struct {
|
||||
sync.Mutex
|
||||
|
||||
CompactDiskCalled bool
|
||||
CompactDiskPath string
|
||||
CompactDiskErr error
|
||||
|
||||
DeviceAddCdRomCalled bool
|
||||
DeviceAddCdRomName string
|
||||
DeviceAddCdRomImage string
|
||||
|
@ -59,6 +63,12 @@ type DriverMock struct {
|
|||
IpAddressError error
|
||||
}
|
||||
|
||||
func (d *DriverMock) CompactDisk(path string) error {
|
||||
d.CompactDiskCalled = true
|
||||
d.CompactDiskPath = path
|
||||
return d.CompactDiskErr
|
||||
}
|
||||
|
||||
func (d *DriverMock) DeviceAddCdRom(name string, image string) (string, error) {
|
||||
d.DeviceAddCdRomCalled = true
|
||||
d.DeviceAddCdRomName = name
|
||||
|
|
Loading…
Reference in New Issue