packer-cn/builder/vmware/iso/step_upload_tools.go

52 lines
1.3 KiB
Go
Raw Normal View History

2013-12-24 00:58:41 -05:00
package iso
import (
2013-07-01 12:39:19 -04:00
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"os"
)
type toolsUploadPathTemplate struct {
Flavor string
}
type stepUploadTools struct{}
2013-08-31 15:50:25 -04:00
func (*stepUploadTools) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*config)
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)
ui.Say(fmt.Sprintf("Uploading the '%s' VMware Tools", config.ToolsUploadFlavor))
f, err := os.Open(tools_source)
if err != nil {
2013-08-31 15:50:25 -04:00
state.Put("error", fmt.Errorf("Error opening VMware Tools ISO: %s", err))
return multistep.ActionHalt
}
2013-06-30 11:09:05 -04:00
defer f.Close()
tplData := &toolsUploadPathTemplate{Flavor: config.ToolsUploadFlavor}
2013-08-08 19:18:01 -04:00
config.ToolsUploadPath, err = config.tpl.Process(config.ToolsUploadPath, tplData)
if err != nil {
err := fmt.Errorf("Error preparing upload path: %s", err)
2013-08-31 15:50:25 -04:00
state.Put("error", err)
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))
return multistep.ActionHalt
}
return multistep.ActionContinue
}
2013-08-31 15:50:25 -04:00
func (*stepUploadTools) Cleanup(multistep.StateBag) {}