diff --git a/builder/parallels/common/driver_11.go b/builder/parallels/common/driver_11.go index c59b6c111..32a1fc92a 100644 --- a/builder/parallels/common/driver_11.go +++ b/builder/parallels/common/driver_11.go @@ -40,7 +40,7 @@ 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[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"} diff --git a/builder/parallels/common/run_config.go b/builder/parallels/common/run_config.go index c755cdafb..072895f41 100644 --- a/builder/parallels/common/run_config.go +++ b/builder/parallels/common/run_config.go @@ -8,7 +8,6 @@ import ( ) type RunConfig struct { - Headless bool `mapstructure:"headless"` RawBootWait string `mapstructure:"boot_wait"` BootWait time.Duration `` diff --git a/builder/parallels/common/step_run.go b/builder/parallels/common/step_run.go index e9c3ab27d..43f0e92eb 100644 --- a/builder/parallels/common/step_run.go +++ b/builder/parallels/common/step_run.go @@ -17,7 +17,6 @@ import ( // Produces: type StepRun struct { BootWait time.Duration - Headless bool vmName string } @@ -28,13 +27,6 @@ func (s *StepRun) Run(state multistep.StateBag) multistep.StepAction { vmName := state.Get("vmName").(string) ui.Say("Starting the virtual machine...") - //guiArgument := "gui" - if s.Headless == true { - ui.Message("WARNING: The VM will be started in headless mode, as configured.\n" + - "In headless mode, errors during the boot sequence or OS setup\n" + - "won't be easily visible. Use at your own discretion.") - //guiArgument = "headless" - } command := []string{"start", vmName} if err := driver.Prlctl(command...); err != nil { err := fmt.Errorf("Error starting VM: %s", err) diff --git a/builder/parallels/iso/builder.go b/builder/parallels/iso/builder.go index 6b731544d..cba02dd19 100644 --- a/builder/parallels/iso/builder.go +++ b/builder/parallels/iso/builder.go @@ -241,7 +241,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe }, ¶llelscommon.StepRun{ BootWait: b.config.BootWait, - Headless: b.config.Headless, // TODO: migth work on Enterprise Ed. }, ¶llelscommon.StepTypeBootCommand{ BootCommand: b.config.BootCommand, diff --git a/builder/parallels/pvm/builder.go b/builder/parallels/pvm/builder.go index 471b59bef..b0b675fb6 100644 --- a/builder/parallels/pvm/builder.go +++ b/builder/parallels/pvm/builder.go @@ -74,7 +74,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe }, ¶llelscommon.StepRun{ BootWait: b.config.BootWait, - Headless: b.config.Headless, }, ¶llelscommon.StepTypeBootCommand{ BootCommand: b.config.BootCommand, diff --git a/fix/fixer.go b/fix/fixer.go index 8da82f48f..5b5006215 100644 --- a/fix/fixer.go +++ b/fix/fixer.go @@ -26,6 +26,7 @@ func init() { "virtualbox-gaattach": new(FixerVirtualBoxGAAttach), "virtualbox-rename": new(FixerVirtualBoxRename), "vmware-rename": new(FixerVMwareRename), + "parallels-headless": new(FixerParallelsHeadless), } FixerOrder = []string{ @@ -35,5 +36,6 @@ func init() { "pp-vagrant-override", "virtualbox-rename", "vmware-rename", + "parallels-headless", } } diff --git a/fix/fixer_parallels_headless.go b/fix/fixer_parallels_headless.go new file mode 100644 index 000000000..f7bc8874a --- /dev/null +++ b/fix/fixer_parallels_headless.go @@ -0,0 +1,51 @@ +package fix + +import ( + "github.com/mitchellh/mapstructure" +) + +// FixerParallelsHeadless removes "headless" from a template in a Parallels builder +type FixerParallelsHeadless struct{} + +func (FixerParallelsHeadless) Fix(input map[string]interface{}) (map[string]interface{}, error) { + // The type we'll decode into; we only care about builders + type template struct { + Builders []map[string]interface{} + } + + // Decode the input into our structure, if we can + var tpl template + if err := mapstructure.Decode(input, &tpl); err != nil { + return nil, err + } + + for _, builder := range tpl.Builders { + builderTypeRaw, ok := builder["type"] + if !ok { + continue + } + + builderType, ok := builderTypeRaw.(string) + if !ok { + continue + } + + if builderType != "parallels-iso" && builderType != "parallels-pvm" { + continue + } + + _, ok = builder["headless"] + if !ok { + continue + } + + delete(builder, "headless") + } + + input["builders"] = tpl.Builders + return input, nil +} + +func (FixerParallelsHeadless) Synopsis() string { + return `Removes unused "headless" from Parallels builders` +} diff --git a/fix/fixer_parallels_headless_test.go b/fix/fixer_parallels_headless_test.go new file mode 100644 index 000000000..c6c92e981 --- /dev/null +++ b/fix/fixer_parallels_headless_test.go @@ -0,0 +1,61 @@ +package fix + +import ( + "reflect" + "testing" +) + +func TestFixerParallelsHeadless_Impl(t *testing.T) { + var _ Fixer = new(FixerParallelsHeadless) +} + +func TestFixerParallelsHeadless_Fix(t *testing.T) { + cases := []struct { + Input map[string]interface{} + Expected map[string]interface{} + }{ + // No headless field + { + Input: map[string]interface{}{ + "type": "parallels-iso", + }, + + Expected: map[string]interface{}{ + "type": "parallels-iso", + }, + }, + + // Headless field + { + Input: map[string]interface{}{ + "type": "parallels-iso", + "headless": false, + }, + + Expected: map[string]interface{}{ + "type": "parallels-iso", + }, + }, + } + + for _, tc := range cases { + var f FixerParallelsHeadless + + input := map[string]interface{}{ + "builders": []map[string]interface{}{tc.Input}, + } + + expected := map[string]interface{}{ + "builders": []map[string]interface{}{tc.Expected}, + } + + output, err := f.Fix(input) + if err != nil { + t.Fatalf("err: %s", err) + } + + if !reflect.DeepEqual(output, expected) { + t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected) + } + } +}