Skip to content

Commit

Permalink
Merge pull request #68 from legal90/fix-pd13
Browse files Browse the repository at this point in the history
Create a bigger initial disk on Parallels Desktop 13.0
  • Loading branch information
romankulikov committed Sep 13, 2017
2 parents 631fecb + b420b3f commit 00cfec0
Show file tree
Hide file tree
Showing 9 changed files with 982 additions and 20 deletions.
4 changes: 4 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 30 additions & 17 deletions parallels_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/docker/machine/libmachine/mcnutils"
"github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/libmachine/state"
"github.com/hashicorp/go-version"
)

const (
Expand All @@ -38,12 +39,15 @@ const (

var (
reMachineNotFound = regexp.MustCompile(`Failed to get VM config: The virtual machine could not be found..*`)
reMajorVersion = regexp.MustCompile(`prlctl version (\d+)\.\d+\.\d+.*`)
reParallelsVersion = regexp.MustCompile(`.* (\d+\.\d+\.\d+).*`)
reParallelsEdition = regexp.MustCompile(`edition="(.+)"`)

errMachineExist = errors.New("machine already exists")
errMachineNotExist = errors.New("machine does not exist")
errSharedNotConnected = errors.New("Your Mac host is not connected to Shared network. Please, enable this option: 'Parallels Desktop' -> 'Preferences' -> 'Network' -> 'Shared' -> 'Connect Mac to this network'")

v10, _ = version.NewVersion("10.0.0")
v11, _ = version.NewVersion("11.0.0")
)

// Driver for Parallels Desktop
Expand Down Expand Up @@ -99,7 +103,7 @@ func (d *Driver) Create() error {
}

distribution := "boot2docker"
if ver < 11 {
if ver.LessThan(v11) {
distribution = "linux-2.6"
}

Expand Down Expand Up @@ -141,22 +145,31 @@ func (d *Driver) Create() error {
return err
}

initialDiskSize := minDiskSize

// Fix for [GH-67]. Create a bigger disk on Parallels Desktop 13.0.*
constraints, _ := version.NewConstraint(">= 13.0.0, < 13.1.0")
if constraints.Check(ver) {
initialDiskSize = 1891
}

// Create a small plain disk. It will be converted and expanded later
if err = prlctl("set", d.MachineName,
"--device-add", "hdd",
"--iface", "sata",
"--position", "1",
"--image", d.diskPath(),
"--type", "plain",
"--size", fmt.Sprintf("%d", minDiskSize)); err != nil {
"--size", fmt.Sprintf("%d", initialDiskSize)); err != nil {
return err
}

if err = d.generateDiskImage(d.DiskSize); err != nil {
return err
}

if ver >= 11 {
// For Parallels Desktop >= 11.0.0
if ver.Compare(v11) >= 0 {
// Enable headless mode
if err = prlctl("set", d.MachineName,
"--startup-view", "headless"); err != nil {
Expand Down Expand Up @@ -331,12 +344,12 @@ func (d *Driver) PreCreateCheck() error {
return err
}

if ver < 10 {
return fmt.Errorf("Driver \"parallels\" supports only Parallels Desktop 10 and higher. You use: Parallels Desktop %d.", ver)
if ver.LessThan(v10) {
return fmt.Errorf("Driver \"parallels\" supports only Parallels Desktop 10 and higher. You use: Parallels Desktop %s.", ver)
}

if ver < 11 {
log.Debugf("Found Parallels Desktop version: %d", ver)
if ver.LessThan(v11) {
log.Debugf("Found Parallels Desktop version: %s", ver)
log.Infof("Driver \"parallels\" integration with Parallels Desktop 10 is maintained by open source community.")
log.Infof("For Parallels supported configuration you should use it with Parallels Desktop 11 or later (Pro or Business edition).")
return nil
Expand Down Expand Up @@ -638,7 +651,7 @@ func (d *Driver) generateDiskImage(size int) error {
hds.Close()

// Convert image to expanding type and resize it
if err := prldisktool("convert", "--expanding",
if err := prldisktool("convert", "--expanding", "--merge",
"--hdd", d.diskPath()); err != nil {
return err
}
Expand All @@ -664,24 +677,24 @@ func detectCmdInPath(cmd string) string {
}

// Detects Parallels Desktop major version
func getParallelsVersion() (int, error) {
func getParallelsVersion() (*version.Version, error) {
stdout, _, err := prlctlOutErr("--version")
if err != nil {
return 0, err
return nil, err
}

// Parse Parallels Desktop version
res := reMajorVersion.FindStringSubmatch(string(stdout))
if res == nil {
return 0, fmt.Errorf("Parallels Desktop version could not be fetched: %s", stdout)
verRaw := reParallelsVersion.FindStringSubmatch(string(stdout))
if verRaw == nil {
return nil, fmt.Errorf("Parallels Desktop version could not be fetched: %s", stdout)
}

majorVer, err := strconv.Atoi(res[1])
ver, err := version.NewVersion(verRaw[1])
if err != nil {
return 0, err
return nil, err
}

return majorVer, nil
return ver, nil
}

// Detects Parallels Desktop edition
Expand Down
4 changes: 1 addition & 3 deletions test/integration/bats/custom-mem-disk.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ use_disposable_machine

# Default memsize is 1024MB and disksize is 20000MB
# These values are defined in parallels.go
export DEFAULT_MEMSIZE=1024
export DEFAULT_DISKSIZE=20000
export CUSTOM_MEMSIZE=1536
export CUSTOM_DISKSIZE=10000
export CUSTOM_DISKSIZE=10017
export CUSTOM_CPUCOUNT=1

function findDiskSize() {
Expand Down
11 changes: 11 additions & 0 deletions vendor/github.com/hashicorp/go-version/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 00cfec0

Please sign in to comment.