Added support for the cpu_count, memory_size, sound, and usb options to the parallels builder.
This commit is contained in:
parent
06c2c35e4c
commit
71d15d05c0
|
@ -7,19 +7,17 @@ type Parallels10Driver struct {
|
|||
|
||||
// SetDefaultConfiguration applies pre-defined default settings to the VM config.
|
||||
func (d *Parallels10Driver) 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"}
|
||||
commands := make([][]string, 10)
|
||||
commands[0] = []string{"set", vmName, "--startup-view", "same"}
|
||||
commands[1] = []string{"set", vmName, "--on-shutdown", "close"}
|
||||
commands[2] = []string{"set", vmName, "--on-window-close", "keep-running"}
|
||||
commands[3] = []string{"set", vmName, "--auto-share-camera", "off"}
|
||||
commands[4] = []string{"set", vmName, "--smart-guard", "off"}
|
||||
commands[5] = []string{"set", vmName, "--shared-cloud", "off"}
|
||||
commands[6] = []string{"set", vmName, "--shared-profile", "off"}
|
||||
commands[7] = []string{"set", vmName, "--smart-mount", "off"}
|
||||
commands[8] = []string{"set", vmName, "--sh-app-guest-to-host", "off"}
|
||||
commands[9] = []string{"set", vmName, "--sh-app-host-to-guest", "off"}
|
||||
|
||||
for _, command := range commands {
|
||||
err := d.Prlctl(command...)
|
||||
|
|
|
@ -38,19 +38,17 @@ func (d *Parallels11Driver) Verify() error {
|
|||
|
||||
// SetDefaultConfiguration applies pre-defined default settings to the VM config.
|
||||
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", "headless"}
|
||||
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"}
|
||||
commands := make([][]string, 10)
|
||||
commands[0] = []string{"set", vmName, "--startup-view", "headless"}
|
||||
commands[1] = []string{"set", vmName, "--on-shutdown", "close"}
|
||||
commands[2] = []string{"set", vmName, "--on-window-close", "keep-running"}
|
||||
commands[3] = []string{"set", vmName, "--auto-share-camera", "off"}
|
||||
commands[4] = []string{"set", vmName, "--smart-guard", "off"}
|
||||
commands[5] = []string{"set", vmName, "--shared-cloud", "off"}
|
||||
commands[6] = []string{"set", vmName, "--shared-profile", "off"}
|
||||
commands[7] = []string{"set", vmName, "--smart-mount", "off"}
|
||||
commands[8] = []string{"set", vmName, "--sh-app-guest-to-host", "off"}
|
||||
commands[9] = []string{"set", vmName, "--sh-app-host-to-guest", "off"}
|
||||
|
||||
for _, command := range commands {
|
||||
err := d.Prlctl(command...)
|
||||
|
|
|
@ -331,14 +331,12 @@ func prepend(head string, tail []string) []string {
|
|||
|
||||
// SetDefaultConfiguration applies pre-defined default settings to the VM config.
|
||||
func (d *Parallels9Driver) SetDefaultConfiguration(vmName string) error {
|
||||
commands := make([][]string, 7)
|
||||
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 := make([][]string, 5)
|
||||
commands[0] = []string{"set", vmName, "--startup-view", "same"}
|
||||
commands[1] = []string{"set", vmName, "--on-shutdown", "close"}
|
||||
commands[2] = []string{"set", vmName, "--on-window-close", "keep-running"}
|
||||
commands[3] = []string{"set", vmName, "--auto-share-camera", "off"}
|
||||
commands[4] = []string{"set", vmName, "--smart-guard", "off"}
|
||||
|
||||
for _, command := range commands {
|
||||
err := d.Prlctl(command...)
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/packer/template/interpolate"
|
||||
)
|
||||
|
||||
type HWConfig struct {
|
||||
|
||||
// cpu information
|
||||
CpuCount int `mapstructure:"cpu_count"`
|
||||
MemorySize int `mapstructure:"memory_size"`
|
||||
|
||||
// device presence
|
||||
Sound bool `mapstructure:"sound"`
|
||||
USB bool `mapstructure:"usb"`
|
||||
}
|
||||
|
||||
func (c *HWConfig) Prepare(ctx *interpolate.Context) []error {
|
||||
var errs []error
|
||||
|
||||
// Hardware and cpu options
|
||||
if c.CpuCount < 0 {
|
||||
errs = append(errs, fmt.Errorf("An invalid cpu_count was specified (cpu_count < 0): %d", c.CpuCount))
|
||||
c.CpuCount = 0
|
||||
}
|
||||
if c.CpuCount == 0 {
|
||||
c.CpuCount = 1
|
||||
}
|
||||
|
||||
if c.MemorySize < 0 {
|
||||
errs = append(errs, fmt.Errorf("An invalid memory_size was specified (memory_size < 0): %d", c.MemorySize))
|
||||
c.MemorySize = 0
|
||||
}
|
||||
if c.MemorySize == 0 {
|
||||
c.MemorySize = 512
|
||||
}
|
||||
|
||||
// Peripherals
|
||||
if !c.Sound {
|
||||
c.Sound = false
|
||||
}
|
||||
|
||||
if !c.USB {
|
||||
c.USB = false
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHWConfigPrepare(t *testing.T) {
|
||||
c := new(HWConfig)
|
||||
if errs := c.Prepare(testConfigTemplate(t)); len(errs) > 0 {
|
||||
t.Fatalf("err: %#v", errs)
|
||||
}
|
||||
|
||||
if c.CpuCount < 1 {
|
||||
t.Errorf("bad cpu count: %d", c.CpuCount)
|
||||
}
|
||||
|
||||
if c.MemorySize < 64 {
|
||||
t.Errorf("bad memory size: %d", c.MemorySize)
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ type Config struct {
|
|||
common.FloppyConfig `mapstructure:",squash"`
|
||||
bootcommand.BootConfig `mapstructure:",squash"`
|
||||
parallelscommon.OutputConfig `mapstructure:",squash"`
|
||||
parallelscommon.HWConfig `mapstructure:",squash"`
|
||||
parallelscommon.PrlctlConfig `mapstructure:",squash"`
|
||||
parallelscommon.PrlctlPostConfig `mapstructure:",squash"`
|
||||
parallelscommon.PrlctlVersionConfig `mapstructure:",squash"`
|
||||
|
@ -76,6 +77,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|||
errs = packer.MultiErrorAppend(errs, b.config.FloppyConfig.Prepare(&b.config.ctx)...)
|
||||
errs = packer.MultiErrorAppend(
|
||||
errs, b.config.OutputConfig.Prepare(&b.config.ctx, &b.config.PackerConfig)...)
|
||||
errs = packer.MultiErrorAppend(errs, b.config.HWConfig.Prepare(&b.config.ctx)...)
|
||||
errs = packer.MultiErrorAppend(errs, b.config.PrlctlConfig.Prepare(&b.config.ctx)...)
|
||||
errs = packer.MultiErrorAppend(errs, b.config.PrlctlPostConfig.Prepare(&b.config.ctx)...)
|
||||
errs = packer.MultiErrorAppend(errs, b.config.PrlctlVersionConfig.Prepare(&b.config.ctx)...)
|
||||
|
|
|
@ -3,6 +3,7 @@ package iso
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
parallelscommon "github.com/hashicorp/packer/builder/parallels/common"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
|
@ -24,19 +25,46 @@ func (s *stepCreateVM) Run(_ context.Context, state multistep.StateBag) multiste
|
|||
ui := state.Get("ui").(packer.Ui)
|
||||
name := config.VMName
|
||||
|
||||
command := []string{
|
||||
commands := make([][]string, 3)
|
||||
|
||||
commands[0] = []string{
|
||||
"create", name,
|
||||
"--distribution", config.GuestOSType,
|
||||
"--dst", config.OutputDir,
|
||||
"--no-hdd",
|
||||
}
|
||||
commands[1] = []string{
|
||||
"set", name,
|
||||
"--cpus", strconv.Itoa(config.HWConfig.CpuCount),
|
||||
}
|
||||
commands[2] = []string{
|
||||
"set", name,
|
||||
"--memsize", strconv.Itoa(config.HWConfig.MemorySize),
|
||||
}
|
||||
|
||||
if config.HWConfig.Sound {
|
||||
commands = append(commands, []string{
|
||||
"set", name,
|
||||
"--device-add-sound",
|
||||
"--connect",
|
||||
})
|
||||
}
|
||||
|
||||
if config.HWConfig.USB {
|
||||
commands = append(commands, []string{
|
||||
"set", name,
|
||||
"--device-add-usb",
|
||||
})
|
||||
}
|
||||
|
||||
ui.Say("Creating virtual machine...")
|
||||
if err := driver.Prlctl(command...); err != nil {
|
||||
err := fmt.Errorf("Error creating VM: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
for _, command := range commands {
|
||||
if err := driver.Prlctl(command...); err != nil {
|
||||
err := fmt.Errorf("Error creating VM: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
}
|
||||
|
||||
ui.Say("Applying default settings...")
|
||||
|
|
Loading…
Reference in New Issue