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..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 @@ -121,6 +124,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) ToolsIsoPath() 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..ee6bfc14c --- /dev/null +++ b/builder/vmware/step_upload_tools.go @@ -0,0 +1,34 @@ +package vmware + +import ( + "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" + "os" + "fmt" +) + +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.") + + 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) + return multistep.ActionHalt + } + + return multistep.ActionContinue +} + +func (*stepUploadTools) Cleanup(map[string]interface{}) {}