2013-06-29 23:08:27 -04:00
|
|
|
package vmware
|
|
|
|
|
|
|
|
import (
|
2013-07-01 13:40:38 -04:00
|
|
|
"bytes"
|
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-07-01 13:40:38 -04:00
|
|
|
"text/template"
|
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{}
|
|
|
|
|
|
|
|
func (*stepUploadTools) Run(state map[string]interface{}) multistep.StepAction {
|
2013-07-01 13:40:38 -04:00
|
|
|
config := state["config"].(*config)
|
|
|
|
if config.ToolsUploadFlavor == "" {
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-06-29 23:08:27 -04:00
|
|
|
comm := state["communicator"].(packer.Communicator)
|
2013-07-01 13:40:38 -04:00
|
|
|
tools_source := state["tools_upload_source"].(string)
|
2013-06-29 23:08:27 -04:00
|
|
|
ui := state["ui"].(packer.Ui)
|
|
|
|
|
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 {
|
|
|
|
state["error"] = fmt.Errorf("Error opening VMware Tools ISO: %s", err)
|
|
|
|
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}
|
|
|
|
var processedPath bytes.Buffer
|
|
|
|
t := template.Must(template.New("path").Parse(config.ToolsUploadPath))
|
|
|
|
t.Execute(&processedPath, tplData)
|
|
|
|
|
|
|
|
if err := comm.Upload(processedPath.String(), f); err != nil {
|
2013-06-29 23:08:27 -04:00
|
|
|
state["error"] = fmt.Errorf("Error uploading VMware Tools: %s", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*stepUploadTools) Cleanup(map[string]interface{}) {}
|