From da3b0f54c71473d5536317a125500529c3a96751 Mon Sep 17 00:00:00 2001 From: Steven Merrill Date: Sat, 29 Jun 2013 23:08:27 -0400 Subject: [PATCH 1/3] Upload the linux.iso to /tmp/linux.iso. --- builder/vmware/builder.go | 1 + builder/vmware/driver.go | 5 +++++ builder/vmware/step_upload_tools.go | 35 +++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 builder/vmware/step_upload_tools.go diff --git a/builder/vmware/builder.go b/builder/vmware/builder.go index e49609ab0..bac14188a 100644 --- a/builder/vmware/builder.go +++ b/builder/vmware/builder.go @@ -222,6 +222,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &stepRun{}, &stepTypeBootCommand{}, &stepWaitForSSH{}, + &stepUploadTools{}, &stepProvision{}, &stepShutdown{}, &stepCleanFiles{}, diff --git a/builder/vmware/driver.go b/builder/vmware/driver.go index 45a8f05fb..810031664 100644 --- a/builder/vmware/driver.go +++ b/builder/vmware/driver.go @@ -121,6 +121,11 @@ func (d *Fusion5Driver) vmrunPath() string { return filepath.Join(d.AppPath, "Contents", "Library", "vmrun") } +// @TODO: Be smarter about guest type before deciding on linux.iso. +func (d *Fusion5Driver) vmwareToolsIsoPath() string { + return filepath.Join(d.AppPath, "Contents", "Library", "isoimages", "linux.iso") +} + func (d *Fusion5Driver) runAndLog(cmd *exec.Cmd) (string, string, error) { var stdout, stderr bytes.Buffer diff --git a/builder/vmware/step_upload_tools.go b/builder/vmware/step_upload_tools.go new file mode 100644 index 000000000..5e6fbfe5b --- /dev/null +++ b/builder/vmware/step_upload_tools.go @@ -0,0 +1,35 @@ +package vmware + +import ( + "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" + "log" +) + +a { + +type stepUploadTools struct{} + +func (*stepUploadTools) Run(state map[string]interface{}) multistep.StepAction { + comm := state["communicator"].(packer.Communicator) + ui := state["ui"].(packer.Ui) + driver := state["driver"].(Driver) + + ui.Say("Uploading the VMware Tools.") + log.Println("Uploading the VMware Tools.") + + f, err := os.Open(driver.vmwareToolsIsoPath()) + if err != nil { + state["error"] = fmt.Errorf("Error opening VMware Tools ISO: %s", err) + return multistep.ActionHalt + } + + if err := comm.Upload("/tmp/linux.iso", f); err != nil { + state["error"] = fmt.Errorf("Error uploading VMware Tools: %s", err) + return multistep.ActionHalt + } + + return multistep.ActionContinue +} + +func (*stepUploadTools) Cleanup(map[string]interface{}) {} From dbad9a40581862692df298c6c1e821a1220e82c5 Mon Sep 17 00:00:00 2001 From: Steven Merrill Date: Sat, 29 Jun 2013 23:20:38 -0400 Subject: [PATCH 2/3] Add a method to get the VMware Tools ISO path. --- builder/vmware/driver.go | 5 ++++- builder/vmware/step_upload_tools.go | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/builder/vmware/driver.go b/builder/vmware/driver.go index 810031664..906fb66b3 100644 --- a/builder/vmware/driver.go +++ b/builder/vmware/driver.go @@ -24,6 +24,9 @@ type Driver interface { // Stop stops a VM specified by the path to the VMX given. Stop(string) error + // Get the path to the VMware ISO. + ToolsIsoPath() string + // Verify checks to make sure that this driver should function // properly. This should check that all the files it will use // appear to exist and so on. If everything is okay, this doesn't @@ -122,7 +125,7 @@ func (d *Fusion5Driver) vmrunPath() string { } // @TODO: Be smarter about guest type before deciding on linux.iso. -func (d *Fusion5Driver) vmwareToolsIsoPath() string { +func (d *Fusion5Driver) ToolsIsoPath() string { return filepath.Join(d.AppPath, "Contents", "Library", "isoimages", "linux.iso") } diff --git a/builder/vmware/step_upload_tools.go b/builder/vmware/step_upload_tools.go index 5e6fbfe5b..a381e2ae3 100644 --- a/builder/vmware/step_upload_tools.go +++ b/builder/vmware/step_upload_tools.go @@ -4,10 +4,10 @@ import ( "github.com/mitchellh/multistep" "github.com/mitchellh/packer/packer" "log" + "os" + "fmt" ) -a { - type stepUploadTools struct{} func (*stepUploadTools) Run(state map[string]interface{}) multistep.StepAction { @@ -18,7 +18,7 @@ func (*stepUploadTools) Run(state map[string]interface{}) multistep.StepAction { ui.Say("Uploading the VMware Tools.") log.Println("Uploading the VMware Tools.") - f, err := os.Open(driver.vmwareToolsIsoPath()) + f, err := os.Open(driver.ToolsIsoPath()) if err != nil { state["error"] = fmt.Errorf("Error opening VMware Tools ISO: %s", err) return multistep.ActionHalt From fc06324ca09411823b383c329c08ace0c15e63ae Mon Sep 17 00:00:00 2001 From: Steven Merrill Date: Sun, 30 Jun 2013 11:09:05 -0400 Subject: [PATCH 3/3] Incorporate code review feedback. --- builder/vmware/step_upload_tools.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builder/vmware/step_upload_tools.go b/builder/vmware/step_upload_tools.go index a381e2ae3..ee6bfc14c 100644 --- a/builder/vmware/step_upload_tools.go +++ b/builder/vmware/step_upload_tools.go @@ -3,7 +3,6 @@ package vmware import ( "github.com/mitchellh/multistep" "github.com/mitchellh/packer/packer" - "log" "os" "fmt" ) @@ -16,13 +15,13 @@ func (*stepUploadTools) Run(state map[string]interface{}) multistep.StepAction { driver := state["driver"].(Driver) ui.Say("Uploading the VMware Tools.") - log.Println("Uploading the VMware Tools.") f, err := os.Open(driver.ToolsIsoPath()) if err != nil { state["error"] = fmt.Errorf("Error opening VMware Tools ISO: %s", err) return multistep.ActionHalt } + defer f.Close() if err := comm.Upload("/tmp/linux.iso", f); err != nil { state["error"] = fmt.Errorf("Error uploading VMware Tools: %s", err)