Commit bed62702 authored by Mikhail Zholobov's avatar Mikhail Zholobov

builder/parallels: Detect path to Parallels Tools ISO automatically.

'parallels_tools_host_path' param is deprecated
'parallels_tools_flavor' is added (mandatory).
parent 40c169f7
...@@ -7,18 +7,18 @@ import ( ...@@ -7,18 +7,18 @@ import (
"log" "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. // the virtual machine.
// //
// Uses: // Uses:
// driver Driver // driver Driver
// toolsPath string // parallels_tools_path string
// ui packer.Ui // ui packer.Ui
// vmName string // vmName string
// //
// Produces: // Produces:
// attachedToolsIso boolean
type StepAttachParallelsTools struct { type StepAttachParallelsTools struct {
ParallelsToolsHostPath string
ParallelsToolsMode string ParallelsToolsMode string
} }
...@@ -33,12 +33,15 @@ func (s *StepAttachParallelsTools) Run(state multistep.StateBag) multistep.StepA ...@@ -33,12 +33,15 @@ func (s *StepAttachParallelsTools) Run(state multistep.StateBag) multistep.StepA
return multistep.ActionContinue 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 // Attach the guest additions to the computer
ui.Say("Attaching Parallels Tools ISO onto IDE controller...") ui.Say("Attaching Parallels Tools ISO onto IDE controller...")
command := []string{ command := []string{
"set", vmName, "set", vmName,
"--device-add", "cdrom", "--device-add", "cdrom",
"--image", s.ParallelsToolsHostPath, "--image", parallelsToolsPath,
} }
if err := driver.Prlctl(command...); err != nil { if err := driver.Prlctl(command...); err != nil {
err := fmt.Errorf("Error attaching Parallels Tools: %s", err) err := fmt.Errorf("Error attaching Parallels Tools: %s", err)
...@@ -59,6 +62,7 @@ func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) { ...@@ -59,6 +62,7 @@ func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) {
} }
driver := state.Get("driver").(Driver) driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string) vmName := state.Get("vmName").(string)
log.Println("Detaching Parallels Tools ISO...") log.Println("Detaching Parallels Tools ISO...")
...@@ -71,5 +75,8 @@ func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) { ...@@ -71,5 +75,8 @@ func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) {
"set", vmName, "set", vmName,
"--device-del", cdDevice, "--device-del", cdDevice,
} }
driver.Prlctl(command...)
if err := driver.Prlctl(command...); err != nil {
ui.Error(fmt.Sprintf("Error detaching Parallels Tools ISO: %s", err))
}
} }
...@@ -8,13 +8,21 @@ import ( ...@@ -8,13 +8,21 @@ import (
"os" "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 { type toolsPathTemplate struct {
Version string Flavor string
} }
// This step uploads the guest additions ISO to the VM. // This step uploads the guest additions ISO to the VM.
type StepUploadParallelsTools struct { type StepUploadParallelsTools struct {
ParallelsToolsHostPath string ParallelsToolsFlavor string
ParallelsToolsGuestPath string ParallelsToolsGuestPath string
ParallelsToolsMode string ParallelsToolsMode string
Tpl *packer.ConfigTemplate Tpl *packer.ConfigTemplate
...@@ -22,7 +30,6 @@ type StepUploadParallelsTools struct { ...@@ -22,7 +30,6 @@ type StepUploadParallelsTools struct {
func (s *StepUploadParallelsTools) Run(state multistep.StateBag) multistep.StepAction { func (s *StepUploadParallelsTools) Run(state multistep.StateBag) multistep.StepAction {
comm := state.Get("communicator").(packer.Communicator) comm := state.Get("communicator").(packer.Communicator)
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
// If we're attaching then don't do this, since we attached. // 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 ...@@ -31,20 +38,18 @@ func (s *StepUploadParallelsTools) Run(state multistep.StateBag) multistep.StepA
return multistep.ActionContinue return multistep.ActionContinue
} }
version, err := driver.Version() // Get the Paralells Tools path on the host machine
if err != nil { parallelsToolsPath := state.Get("parallels_tools_path").(string)
state.Put("error", fmt.Errorf("Error reading version for Parallels Tools upload: %s", err))
return multistep.ActionHalt
}
f, err := os.Open(s.ParallelsToolsHostPath) f, err := os.Open(parallelsToolsPath)
if err != nil { if err != nil {
state.Put("error", fmt.Errorf("Error opening Parallels Tools ISO: %s", err)) state.Put("error", fmt.Errorf("Error opening Parallels Tools ISO: %s", err))
return multistep.ActionHalt return multistep.ActionHalt
} }
defer f.Close()
tplData := &toolsPathTemplate{ tplData := &toolsPathTemplate{
Version: version, Flavor: s.ParallelsToolsFlavor,
} }
s.ParallelsToolsGuestPath, err = s.Tpl.Process(s.ParallelsToolsGuestPath, tplData) s.ParallelsToolsGuestPath, err = s.Tpl.Process(s.ParallelsToolsGuestPath, tplData)
...@@ -55,9 +60,12 @@ func (s *StepUploadParallelsTools) Run(state multistep.StateBag) multistep.StepA ...@@ -55,9 +60,12 @@ func (s *StepUploadParallelsTools) Run(state multistep.StateBag) multistep.StepA
return multistep.ActionHalt 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 { 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 return multistep.ActionHalt
} }
......
...@@ -248,7 +248,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -248,7 +248,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
new(stepCreateDisk), new(stepCreateDisk),
new(stepAttachISO), new(stepAttachISO),
&parallelscommon.StepAttachParallelsTools{ &parallelscommon.StepAttachParallelsTools{
ParallelsToolsHostPath: b.config.ParallelsToolsHostPath,
ParallelsToolsMode: b.config.ParallelsToolsMode, ParallelsToolsMode: b.config.ParallelsToolsMode,
}, },
new(parallelscommon.StepAttachFloppy), new(parallelscommon.StepAttachFloppy),
...@@ -275,8 +274,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -275,8 +274,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Path: b.config.PrlctlVersionFile, Path: b.config.PrlctlVersionFile,
}, },
&parallelscommon.StepUploadParallelsTools{ &parallelscommon.StepUploadParallelsTools{
ParallelsToolsFlavor: b.config.ParallelsToolsFlavor,
ParallelsToolsGuestPath: b.config.ParallelsToolsGuestPath, ParallelsToolsGuestPath: b.config.ParallelsToolsGuestPath,
ParallelsToolsHostPath: b.config.ParallelsToolsHostPath,
ParallelsToolsMode: b.config.ParallelsToolsMode, ParallelsToolsMode: b.config.ParallelsToolsMode,
Tpl: b.config.tpl, Tpl: b.config.tpl,
}, },
......
...@@ -13,6 +13,7 @@ func testConfig() map[string]interface{} { ...@@ -13,6 +13,7 @@ func testConfig() map[string]interface{} {
"iso_url": "http://www.google.com/", "iso_url": "http://www.google.com/",
"shutdown_command": "yes", "shutdown_command": "yes",
"ssh_username": "foo", "ssh_username": "foo",
"parallels_tools_flavor": "lin",
packer.BuildNameConfigKey: "foo", packer.BuildNameConfigKey: "foo",
} }
......
...@@ -63,7 +63,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -63,7 +63,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
SourcePath: b.config.SourcePath, SourcePath: b.config.SourcePath,
}, },
&parallelscommon.StepAttachParallelsTools{ &parallelscommon.StepAttachParallelsTools{
ParallelsToolsHostPath: b.config.ParallelsToolsHostPath,
ParallelsToolsMode: b.config.ParallelsToolsMode, ParallelsToolsMode: b.config.ParallelsToolsMode,
}, },
new(parallelscommon.StepAttachFloppy), new(parallelscommon.StepAttachFloppy),
...@@ -90,8 +89,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -90,8 +89,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Path: b.config.PrlctlVersionFile, Path: b.config.PrlctlVersionFile,
}, },
&parallelscommon.StepUploadParallelsTools{ &parallelscommon.StepUploadParallelsTools{
ParallelsToolsFlavor: b.config.ParallelsToolsFlavor,
ParallelsToolsGuestPath: b.config.ParallelsToolsGuestPath, ParallelsToolsGuestPath: b.config.ParallelsToolsGuestPath,
ParallelsToolsHostPath: b.config.ParallelsToolsHostPath,
ParallelsToolsMode: b.config.ParallelsToolsMode, ParallelsToolsMode: b.config.ParallelsToolsMode,
Tpl: b.config.tpl, Tpl: b.config.tpl,
}, },
......
...@@ -10,6 +10,7 @@ func testConfig(t *testing.T) map[string]interface{} { ...@@ -10,6 +10,7 @@ func testConfig(t *testing.T) map[string]interface{} {
return map[string]interface{}{ return map[string]interface{}{
"ssh_username": "foo", "ssh_username": "foo",
"shutdown_command": "foo", "shutdown_command": "foo",
"parallels_tools_flavor": "lin",
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment