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
|
// versions out of the builder steps, so sometimes the methods are
|
||||||
// extremely specific.
|
// extremely specific.
|
||||||
type Driver interface {
|
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
|
// Adds new CD/DVD drive to the VM and returns name of this device
|
||||||
DeviceAddCdRom(string, string) (string, error)
|
DeviceAddCdRom(string, string) (string, error)
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,33 @@ func getAppPath(bundleId string) (string, error) {
|
||||||
return pathOutput, nil
|
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) {
|
func (d *Parallels9Driver) DeviceAddCdRom(name string, image string) (string, error) {
|
||||||
command := []string{
|
command := []string{
|
||||||
"set", name,
|
"set", name,
|
||||||
|
|
|
@ -5,6 +5,10 @@ import "sync"
|
||||||
type DriverMock struct {
|
type DriverMock struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
|
||||||
|
CompactDiskCalled bool
|
||||||
|
CompactDiskPath string
|
||||||
|
CompactDiskErr error
|
||||||
|
|
||||||
DeviceAddCdRomCalled bool
|
DeviceAddCdRomCalled bool
|
||||||
DeviceAddCdRomName string
|
DeviceAddCdRomName string
|
||||||
DeviceAddCdRomImage string
|
DeviceAddCdRomImage string
|
||||||
|
@ -59,6 +63,12 @@ type DriverMock struct {
|
||||||
IpAddressError error
|
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) {
|
func (d *DriverMock) DeviceAddCdRom(name string, image string) (string, error) {
|
||||||
d.DeviceAddCdRomCalled = true
|
d.DeviceAddCdRomCalled = true
|
||||||
d.DeviceAddCdRomName = name
|
d.DeviceAddCdRomName = name
|
||||||
|
|
Loading…
Reference in New Issue