2013-06-29 23:08:27 -04:00
|
|
|
package vmware
|
|
|
|
|
|
|
|
import (
|
2013-07-01 12:39:19 -04:00
|
|
|
"fmt"
|
2013-06-29 23:08:27 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
2013-06-29 23:20:38 -04:00
|
|
|
"os"
|
2013-06-29 23:08:27 -04:00
|
|
|
)
|
|
|
|
|
2013-07-01 13:40:38 -04:00
|
|
|
type toolsUploadPathTemplate struct {
|
|
|
|
Flavor string
|
|
|
|
}
|
|
|
|
|
2013-06-29 23:08:27 -04:00
|
|
|
type stepUploadTools struct{}
|
|
|
|
|
2013-08-31 15:50:25 -04:00
|
|
|
func (*stepUploadTools) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
config := state.Get("config").(*config)
|
2013-07-01 13:40:38 -04:00
|
|
|
if config.ToolsUploadFlavor == "" {
|
|
|
|
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
|
|
|
|
2013-07-01 13:40:38 -04:00
|
|
|
ui.Say(fmt.Sprintf("Uploading the '%s' VMware Tools", config.ToolsUploadFlavor))
|
|
|
|
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
|
|
|
|
2013-07-01 13:40:38 -04:00
|
|
|
tplData := &toolsUploadPathTemplate{Flavor: config.ToolsUploadFlavor}
|
2013-08-08 19:18:01 -04:00
|
|
|
config.ToolsUploadPath, err = config.tpl.Process(config.ToolsUploadPath, tplData)
|
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
|
|
|
|
}
|
|
|
|
|
2013-08-08 19:18:01 -04:00
|
|
|
if err := comm.Upload(config.ToolsUploadPath, f); err != nil {
|
2013-08-31 15:50:25 -04:00
|
|
|
state.Put("error", fmt.Errorf("Error uploading VMware Tools: %s", err))
|
2013-06-29 23:08:27 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-08-31 15:50:25 -04:00
|
|
|
func (*stepUploadTools) Cleanup(multistep.StateBag) {}
|