diff --git a/builder/parallels/common/step_attach_parallels_tools.go b/builder/parallels/common/step_attach_parallels_tools.go index 0d626c844..b80ddd87e 100644 --- a/builder/parallels/common/step_attach_parallels_tools.go +++ b/builder/parallels/common/step_attach_parallels_tools.go @@ -7,19 +7,19 @@ import ( "log" ) -// This step attaches the Parallels Tools as a inserted CD onto +// This step attaches the Parallels Tools as an inserted CD onto // the virtual machine. // // Uses: // driver Driver -// toolsPath string +// parallels_tools_path string // ui packer.Ui // vmName string // // Produces: +// attachedToolsIso boolean type StepAttachParallelsTools struct { - ParallelsToolsHostPath string - ParallelsToolsMode string + ParallelsToolsMode string } func (s *StepAttachParallelsTools) Run(state multistep.StateBag) multistep.StepAction { @@ -33,12 +33,15 @@ func (s *StepAttachParallelsTools) Run(state multistep.StateBag) multistep.StepA return multistep.ActionContinue } + // Get the Paralells Tools path on the host machine + parallelsToolsPath := state.Get("parallels_tools_path").(string) + // Attach the guest additions to the computer ui.Say("Attaching Parallels Tools ISO onto IDE controller...") command := []string{ "set", vmName, "--device-add", "cdrom", - "--image", s.ParallelsToolsHostPath, + "--image", parallelsToolsPath, } if err := driver.Prlctl(command...); err != nil { err := fmt.Errorf("Error attaching Parallels Tools: %s", err) @@ -59,6 +62,7 @@ func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) { } driver := state.Get("driver").(Driver) + ui := state.Get("ui").(packer.Ui) vmName := state.Get("vmName").(string) log.Println("Detaching Parallels Tools ISO...") @@ -71,5 +75,8 @@ func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) { "set", vmName, "--device-del", cdDevice, } - driver.Prlctl(command...) + + if err := driver.Prlctl(command...); err != nil { + ui.Error(fmt.Sprintf("Error detaching Parallels Tools ISO: %s", err)) + } } diff --git a/builder/parallels/common/step_upload_parallels_tools.go b/builder/parallels/common/step_upload_parallels_tools.go index 374a8163e..9c421a22b 100644 --- a/builder/parallels/common/step_upload_parallels_tools.go +++ b/builder/parallels/common/step_upload_parallels_tools.go @@ -8,13 +8,21 @@ import ( "os" ) +// This step uploads the Parallels Tools ISO to the virtual machine. +// +// Uses: +// communicator packer.Communicator +// parallels_tools_path string +// ui packer.Ui +// +// Produces: type toolsPathTemplate struct { - Version string + Flavor string } // This step uploads the guest additions ISO to the VM. type StepUploadParallelsTools struct { - ParallelsToolsHostPath string + ParallelsToolsFlavor string ParallelsToolsGuestPath string ParallelsToolsMode string Tpl *packer.ConfigTemplate @@ -22,7 +30,6 @@ type StepUploadParallelsTools struct { func (s *StepUploadParallelsTools) Run(state multistep.StateBag) multistep.StepAction { comm := state.Get("communicator").(packer.Communicator) - driver := state.Get("driver").(Driver) ui := state.Get("ui").(packer.Ui) // If we're attaching then don't do this, since we attached. @@ -31,20 +38,18 @@ func (s *StepUploadParallelsTools) Run(state multistep.StateBag) multistep.StepA return multistep.ActionContinue } - version, err := driver.Version() - if err != nil { - state.Put("error", fmt.Errorf("Error reading version for Parallels Tools upload: %s", err)) - return multistep.ActionHalt - } + // Get the Paralells Tools path on the host machine + parallelsToolsPath := state.Get("parallels_tools_path").(string) - f, err := os.Open(s.ParallelsToolsHostPath) + f, err := os.Open(parallelsToolsPath) if err != nil { state.Put("error", fmt.Errorf("Error opening Parallels Tools ISO: %s", err)) return multistep.ActionHalt } + defer f.Close() tplData := &toolsPathTemplate{ - Version: version, + Flavor: s.ParallelsToolsFlavor, } s.ParallelsToolsGuestPath, err = s.Tpl.Process(s.ParallelsToolsGuestPath, tplData) @@ -55,9 +60,12 @@ func (s *StepUploadParallelsTools) Run(state multistep.StateBag) multistep.StepA return multistep.ActionHalt } - ui.Say("Uploading Parallels Tools ISO...") + ui.Say(fmt.Sprintf("Uploading Parallels Tools for '%s' to path: '%s'", + s.ParallelsToolsFlavor, s.ParallelsToolsGuestPath)) if err := comm.Upload(s.ParallelsToolsGuestPath, f); err != nil { - state.Put("error", fmt.Errorf("Error uploading Parallels Tools: %s", err)) + err := fmt.Errorf("Error uploading Parallels Tools: %s", err) + state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } diff --git a/builder/parallels/iso/builder.go b/builder/parallels/iso/builder.go index 5fa8eca1f..980f2b5d3 100644 --- a/builder/parallels/iso/builder.go +++ b/builder/parallels/iso/builder.go @@ -248,8 +248,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe new(stepCreateDisk), new(stepAttachISO), ¶llelscommon.StepAttachParallelsTools{ - ParallelsToolsHostPath: b.config.ParallelsToolsHostPath, - ParallelsToolsMode: b.config.ParallelsToolsMode, + ParallelsToolsMode: b.config.ParallelsToolsMode, }, new(parallelscommon.StepAttachFloppy), ¶llelscommon.StepPrlctl{ @@ -275,8 +274,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Path: b.config.PrlctlVersionFile, }, ¶llelscommon.StepUploadParallelsTools{ + ParallelsToolsFlavor: b.config.ParallelsToolsFlavor, ParallelsToolsGuestPath: b.config.ParallelsToolsGuestPath, - ParallelsToolsHostPath: b.config.ParallelsToolsHostPath, ParallelsToolsMode: b.config.ParallelsToolsMode, Tpl: b.config.tpl, }, diff --git a/builder/parallels/iso/builder_test.go b/builder/parallels/iso/builder_test.go index ac5a3a87c..fce9e14a4 100644 --- a/builder/parallels/iso/builder_test.go +++ b/builder/parallels/iso/builder_test.go @@ -8,11 +8,12 @@ import ( func testConfig() map[string]interface{} { return map[string]interface{}{ - "iso_checksum": "foo", - "iso_checksum_type": "md5", - "iso_url": "http://www.google.com/", - "shutdown_command": "yes", - "ssh_username": "foo", + "iso_checksum": "foo", + "iso_checksum_type": "md5", + "iso_url": "http://www.google.com/", + "shutdown_command": "yes", + "ssh_username": "foo", + "parallels_tools_flavor": "lin", packer.BuildNameConfigKey: "foo", } diff --git a/builder/parallels/pvm/builder.go b/builder/parallels/pvm/builder.go index a7931024c..83ac73b12 100644 --- a/builder/parallels/pvm/builder.go +++ b/builder/parallels/pvm/builder.go @@ -63,8 +63,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe SourcePath: b.config.SourcePath, }, ¶llelscommon.StepAttachParallelsTools{ - ParallelsToolsHostPath: b.config.ParallelsToolsHostPath, - ParallelsToolsMode: b.config.ParallelsToolsMode, + ParallelsToolsMode: b.config.ParallelsToolsMode, }, new(parallelscommon.StepAttachFloppy), ¶llelscommon.StepPrlctl{ @@ -90,8 +89,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Path: b.config.PrlctlVersionFile, }, ¶llelscommon.StepUploadParallelsTools{ + ParallelsToolsFlavor: b.config.ParallelsToolsFlavor, ParallelsToolsGuestPath: b.config.ParallelsToolsGuestPath, - ParallelsToolsHostPath: b.config.ParallelsToolsHostPath, ParallelsToolsMode: b.config.ParallelsToolsMode, Tpl: b.config.tpl, }, diff --git a/builder/parallels/pvm/config_test.go b/builder/parallels/pvm/config_test.go index 1fb15849b..c4270c366 100644 --- a/builder/parallels/pvm/config_test.go +++ b/builder/parallels/pvm/config_test.go @@ -8,8 +8,9 @@ import ( func testConfig(t *testing.T) map[string]interface{} { return map[string]interface{}{ - "ssh_username": "foo", - "shutdown_command": "foo", + "ssh_username": "foo", + "shutdown_command": "foo", + "parallels_tools_flavor": "lin", } }