Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a bigger initial disk on Parallels Desktop 13.0 #68

Merged
merged 4 commits into from
Sep 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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