Skip to content

Commit

Permalink
Enable headless mode by default on Parallels Desktop 11
Browse files Browse the repository at this point in the history
  • Loading branch information
rickard-von-essen committed Aug 24, 2015
1 parent 7d3afc8 commit 83980d2
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 12 deletions.
2 changes: 1 addition & 1 deletion builder/parallels/common/driver_11.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
1 change: 0 additions & 1 deletion builder/parallels/common/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

type RunConfig struct {
Headless bool `mapstructure:"headless"`
RawBootWait string `mapstructure:"boot_wait"`

BootWait time.Duration ``
Expand Down
8 changes: 0 additions & 8 deletions builder/parallels/common/step_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
// Produces:
type StepRun struct {
BootWait time.Duration
Headless bool

vmName string
}
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion builder/parallels/iso/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
&parallelscommon.StepRun{
BootWait: b.config.BootWait,
Headless: b.config.Headless, // TODO: migth work on Enterprise Ed.
},
&parallelscommon.StepTypeBootCommand{
BootCommand: b.config.BootCommand,
Expand Down
1 change: 0 additions & 1 deletion builder/parallels/pvm/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
&parallelscommon.StepRun{
BootWait: b.config.BootWait,
Headless: b.config.Headless,
},
&parallelscommon.StepTypeBootCommand{
BootCommand: b.config.BootCommand,
Expand Down
2 changes: 2 additions & 0 deletions fix/fixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func init() {
"virtualbox-gaattach": new(FixerVirtualBoxGAAttach),
"virtualbox-rename": new(FixerVirtualBoxRename),
"vmware-rename": new(FixerVMwareRename),
"parallels-headless": new(FixerParallelsHeadless),
}

FixerOrder = []string{
Expand All @@ -35,5 +36,6 @@ func init() {
"pp-vagrant-override",
"virtualbox-rename",
"vmware-rename",
"parallels-headless",
}
}
51 changes: 51 additions & 0 deletions fix/fixer_parallels_headless.go
Original file line number Diff line number Diff line change
@@ -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`
}
61 changes: 61 additions & 0 deletions fix/fixer_parallels_headless_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 83980d2

Please sign in to comment.