Skip to content

Commit

Permalink
Add check for Parallels Desktop edition in PD 11.
Browse files Browse the repository at this point in the history
Starting since Parallels Desktop 11, the command line functionality is
available only in Pro and Business editions.
  • Loading branch information
rickard-von-essen committed Aug 22, 2015
1 parent 133d76f commit 7d3afc8
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
19 changes: 18 additions & 1 deletion builder/parallels/common/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Driver interface {
func NewDriver() (Driver, error) {
var drivers map[string]Driver
var prlctlPath string
var prlsrvctlPath string
var supportedVersions []string
dhcp_lease_file := "/Library/Preferences/Parallels/parallels_dhcp_leases"

Expand All @@ -75,28 +76,44 @@ func NewDriver() (Driver, error) {

log.Printf("prlctl path: %s", prlctlPath)

if prlsrvctlPath == "" {
var err error
prlsrvctlPath, err = exec.LookPath("prlsrvctl")
if err != nil {
return nil, err
}
}

log.Printf("prlsrvctl path: %s", prlsrvctlPath)

drivers = map[string]Driver{
"11": &Parallels10Driver{
"11": &Parallels11Driver{
Parallels9Driver: Parallels9Driver{
PrlctlPath: prlctlPath,
PrlsrvctlPath: prlsrvctlPath,
dhcp_lease_file: dhcp_lease_file,
},
},
"10": &Parallels10Driver{
Parallels9Driver: Parallels9Driver{
PrlctlPath: prlctlPath,
PrlsrvctlPath: prlsrvctlPath,
dhcp_lease_file: dhcp_lease_file,
},
},
"9": &Parallels9Driver{
PrlctlPath: prlctlPath,
PrlsrvctlPath: prlsrvctlPath,
dhcp_lease_file: dhcp_lease_file,
},
}

for v, d := range drivers {
version, _ := d.Version()
if strings.HasPrefix(version, v) {
if err := d.Verify(); err != nil {
return nil, err
}
return d, nil
}
supportedVersions = append(supportedVersions, v)
Expand Down
61 changes: 61 additions & 0 deletions builder/parallels/common/driver_11.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package common

import (
"fmt"
"os/exec"
"regexp"
)

// Parallels11Driver are inherited from Parallels9Driver.
// Used for Parallels Desktop 11, requires Pro or Business Edition
type Parallels11Driver struct {
Parallels9Driver
}

func (d *Parallels11Driver) Verify() error {

stdout, err := exec.Command(d.PrlsrvctlPath, "info", "--license").Output()
if err != nil {
return err
}

editionRe := regexp.MustCompile(`edition="(\w+)"`)
matches := editionRe.FindStringSubmatch(string(stdout))
if matches == nil {
return fmt.Errorf(
"Could not determine your Parallels Desktop edition using: %s info --license", d.PrlsrvctlPath)
} else {
switch matches[1] {
case "pro", "business":
break
default:
return fmt.Errorf("Packer can be used only with Parallels Desktop 11 Pro or Business edition. You use: %s edition", matches[1])
}
}

return nil
}

func (d *Parallels11Driver) SetDefaultConfiguration(vmName string) error {
commands := make([][]string, 12)
commands[0] = []string{"set", vmName, "--cpus", "1"}
commands[1] = []string{"set", vmName, "--memsize", "512"}
commands[2] = []string{"set", vmName, "--startup-view", "same"}
commands[3] = []string{"set", vmName, "--on-shutdown", "close"}
commands[4] = []string{"set", vmName, "--on-window-close", "keep-running"}
commands[5] = []string{"set", vmName, "--auto-share-camera", "off"}
commands[6] = []string{"set", vmName, "--smart-guard", "off"}
commands[7] = []string{"set", vmName, "--shared-cloud", "off"}
commands[8] = []string{"set", vmName, "--shared-profile", "off"}
commands[9] = []string{"set", vmName, "--smart-mount", "off"}
commands[10] = []string{"set", vmName, "--sh-app-guest-to-host", "off"}
commands[11] = []string{"set", vmName, "--sh-app-host-to-guest", "off"}

for _, command := range commands {
err := d.Prlctl(command...)
if err != nil {
return err
}
}
return nil
}
4 changes: 4 additions & 0 deletions builder/parallels/common/driver_9.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
type Parallels9Driver struct {
// This is the path to the "prlctl" application.
PrlctlPath string

// This is the path to the "prlsrvctl" application.
PrlsrvctlPath string

// The path to the parallels_dhcp_leases file
dhcp_lease_file string
}
Expand Down
3 changes: 3 additions & 0 deletions website/source/docs/builders/parallels.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ Virtualization SDK](http://www.parallels.com/downloads/desktop/).

The SDK can be installed by downloading and following the instructions in the
dmg.

Parallels Desktop for Mac 9 and later is supported, from PD 11 Pro or Business
edition is required.

0 comments on commit 7d3afc8

Please sign in to comment.