github.phpd.cn/hashicorp/packer@v1.3.2/builder/parallels/common/driver_11.go (about)

     1  package common
     2  
     3  import (
     4  	"fmt"
     5  	"os/exec"
     6  	"regexp"
     7  )
     8  
     9  // Parallels11Driver are inherited from Parallels9Driver.
    10  // Used for Parallels Desktop 11, requires Pro or Business Edition
    11  type Parallels11Driver struct {
    12  	Parallels9Driver
    13  }
    14  
    15  // Verify raises an error if the builder could not be used on that host machine.
    16  func (d *Parallels11Driver) Verify() error {
    17  
    18  	stdout, err := exec.Command(d.PrlsrvctlPath, "info", "--license").Output()
    19  	if err != nil {
    20  		return err
    21  	}
    22  
    23  	editionRe := regexp.MustCompile(`edition="(\w+)"`)
    24  	matches := editionRe.FindStringSubmatch(string(stdout))
    25  	if matches == nil {
    26  		return fmt.Errorf(
    27  			"Could not determine your Parallels Desktop edition using: %s info --license", d.PrlsrvctlPath)
    28  	}
    29  	switch matches[1] {
    30  	case "pro", "business":
    31  		break
    32  	default:
    33  		return fmt.Errorf("Packer can be used only with Parallels Desktop 11 Pro or Business edition. You use: %s edition", matches[1])
    34  	}
    35  
    36  	return nil
    37  }
    38  
    39  // SetDefaultConfiguration applies pre-defined default settings to the VM config.
    40  func (d *Parallels11Driver) SetDefaultConfiguration(vmName string) error {
    41  	commands := make([][]string, 12)
    42  	commands[0] = []string{"set", vmName, "--cpus", "1"}
    43  	commands[1] = []string{"set", vmName, "--memsize", "512"}
    44  	commands[2] = []string{"set", vmName, "--startup-view", "headless"}
    45  	commands[3] = []string{"set", vmName, "--on-shutdown", "close"}
    46  	commands[4] = []string{"set", vmName, "--on-window-close", "keep-running"}
    47  	commands[5] = []string{"set", vmName, "--auto-share-camera", "off"}
    48  	commands[6] = []string{"set", vmName, "--smart-guard", "off"}
    49  	commands[7] = []string{"set", vmName, "--shared-cloud", "off"}
    50  	commands[8] = []string{"set", vmName, "--shared-profile", "off"}
    51  	commands[9] = []string{"set", vmName, "--smart-mount", "off"}
    52  	commands[10] = []string{"set", vmName, "--sh-app-guest-to-host", "off"}
    53  	commands[11] = []string{"set", vmName, "--sh-app-host-to-guest", "off"}
    54  
    55  	for _, command := range commands {
    56  		err := d.Prlctl(command...)
    57  		if err != nil {
    58  			return err
    59  		}
    60  	}
    61  	return nil
    62  }