2014-05-09 20:24:19 -04:00
|
|
|
package common
|
2013-06-29 23:08:27 -04:00
|
|
|
|
|
|
|
import (
|
2013-07-01 12:39:19 -04:00
|
|
|
"fmt"
|
2015-05-27 17:16:28 -04:00
|
|
|
"os"
|
|
|
|
|
2013-06-29 23:08:27 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
2014-04-26 14:12:43 -04:00
|
|
|
"github.com/mitchellh/packer/packer"
|
2015-05-27 17:16:28 -04:00
|
|
|
"github.com/mitchellh/packer/template/interpolate"
|
2013-06-29 23:08:27 -04:00
|
|
|
)
|
|
|
|
|
2013-07-01 13:40:38 -04:00
|
|
|
type toolsUploadPathTemplate struct {
|
|
|
|
Flavor string
|
|
|
|
}
|
|
|
|
|
2014-05-10 00:12:14 -04:00
|
|
|
type StepUploadTools struct {
|
2014-05-10 13:21:44 -04:00
|
|
|
RemoteType string
|
|
|
|
ToolsUploadFlavor string
|
|
|
|
ToolsUploadPath string
|
2015-05-27 17:16:28 -04:00
|
|
|
Ctx interpolate.Context
|
2014-05-09 20:24:19 -04:00
|
|
|
}
|
2013-06-29 23:08:27 -04:00
|
|
|
|
2014-05-09 20:24:19 -04:00
|
|
|
func (c *StepUploadTools) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
driver := state.Get("driver").(Driver)
|
2014-04-21 11:25:32 -04:00
|
|
|
|
2014-05-09 20:24:19 -04:00
|
|
|
if c.RemoteType == "esx5" {
|
2014-04-21 11:25:32 -04:00
|
|
|
if err := driver.ToolsInstall(); err != nil {
|
2014-06-24 22:20:24 -04:00
|
|
|
state.Put("error", fmt.Errorf("Couldn't mount VMware tools ISO. Please check the 'guest_os_type' in your template.json."))
|
2014-04-21 11:25:32 -04:00
|
|
|
}
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2014-05-09 20:24:19 -04:00
|
|
|
if c.ToolsUploadFlavor == "" {
|
2013-07-01 13:40:38 -04:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-08-31 15:50:25 -04:00
|
|
|
comm := state.Get("communicator").(packer.Communicator)
|
|
|
|
tools_source := state.Get("tools_upload_source").(string)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2013-06-29 23:08:27 -04:00
|
|
|
|
2014-05-09 20:24:19 -04:00
|
|
|
ui.Say(fmt.Sprintf("Uploading the '%s' VMware Tools", c.ToolsUploadFlavor))
|
2013-07-01 13:40:38 -04:00
|
|
|
f, err := os.Open(tools_source)
|
2013-06-29 23:08:27 -04:00
|
|
|
if err != nil {
|
2013-08-31 15:50:25 -04:00
|
|
|
state.Put("error", fmt.Errorf("Error opening VMware Tools ISO: %s", err))
|
2013-06-29 23:08:27 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2013-06-30 11:09:05 -04:00
|
|
|
defer f.Close()
|
2013-06-29 23:08:27 -04:00
|
|
|
|
2015-05-27 17:16:28 -04:00
|
|
|
c.Ctx.Data = &toolsUploadPathTemplate{
|
2014-05-09 20:24:19 -04:00
|
|
|
Flavor: c.ToolsUploadFlavor,
|
|
|
|
}
|
2015-05-27 17:16:28 -04:00
|
|
|
c.ToolsUploadPath, err = interpolate.Render(c.ToolsUploadPath, &c.Ctx)
|
2013-08-08 19:21:21 -04:00
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error preparing upload path: %s", err)
|
2013-08-31 15:50:25 -04:00
|
|
|
state.Put("error", err)
|
2013-08-08 19:21:21 -04:00
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2014-09-08 16:20:46 -04:00
|
|
|
if err := comm.Upload(c.ToolsUploadPath, f, nil); err != nil {
|
2014-02-21 17:07:25 -05:00
|
|
|
err := fmt.Errorf("Error uploading VMware Tools: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
2013-06-29 23:08:27 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2014-05-09 20:24:19 -04:00
|
|
|
func (c *StepUploadTools) Cleanup(multistep.StateBag) {}
|