2014-04-06 13:21:22 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2014-09-02 05:28:04 -04:00
|
|
|
// This step uploads the Parallels Tools ISO to the virtual machine.
|
|
|
|
//
|
|
|
|
// Uses:
|
|
|
|
// communicator packer.Communicator
|
|
|
|
// parallels_tools_path string
|
|
|
|
// ui packer.Ui
|
|
|
|
//
|
|
|
|
// Produces:
|
2014-04-06 13:21:22 -04:00
|
|
|
type toolsPathTemplate struct {
|
2014-09-02 05:28:04 -04:00
|
|
|
Flavor string
|
2014-04-06 13:21:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// This step uploads the guest additions ISO to the VM.
|
|
|
|
type StepUploadParallelsTools struct {
|
2014-09-02 05:28:04 -04:00
|
|
|
ParallelsToolsFlavor string
|
2014-04-06 13:21:22 -04:00
|
|
|
ParallelsToolsGuestPath string
|
|
|
|
ParallelsToolsMode string
|
|
|
|
Tpl *packer.ConfigTemplate
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepUploadParallelsTools) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
comm := state.Get("communicator").(packer.Communicator)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
|
|
|
// If we're attaching then don't do this, since we attached.
|
|
|
|
if s.ParallelsToolsMode != ParallelsToolsModeUpload {
|
|
|
|
log.Println("Not uploading Parallels Tools since mode is not upload")
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2014-09-02 05:28:04 -04:00
|
|
|
// Get the Paralells Tools path on the host machine
|
|
|
|
parallelsToolsPath := state.Get("parallels_tools_path").(string)
|
2014-04-06 13:21:22 -04:00
|
|
|
|
2014-09-02 05:28:04 -04:00
|
|
|
f, err := os.Open(parallelsToolsPath)
|
2014-04-06 13:21:22 -04:00
|
|
|
if err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("Error opening Parallels Tools ISO: %s", err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2014-09-02 05:28:04 -04:00
|
|
|
defer f.Close()
|
2014-04-06 13:21:22 -04:00
|
|
|
|
|
|
|
tplData := &toolsPathTemplate{
|
2014-09-02 05:28:04 -04:00
|
|
|
Flavor: s.ParallelsToolsFlavor,
|
2014-04-06 13:21:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
s.ParallelsToolsGuestPath, err = s.Tpl.Process(s.ParallelsToolsGuestPath, tplData)
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error preparing Parallels Tools path: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2014-09-02 05:28:04 -04:00
|
|
|
ui.Say(fmt.Sprintf("Uploading Parallels Tools for '%s' to path: '%s'",
|
|
|
|
s.ParallelsToolsFlavor, s.ParallelsToolsGuestPath))
|
2014-04-06 13:21:22 -04:00
|
|
|
if err := comm.Upload(s.ParallelsToolsGuestPath, f); err != nil {
|
2014-09-02 05:28:04 -04:00
|
|
|
err := fmt.Errorf("Error uploading Parallels Tools: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
2014-04-06 13:21:22 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepUploadParallelsTools) Cleanup(state multistep.StateBag) {}
|