2014-04-06 13:21:22 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
2015-05-27 16:49:31 -04:00
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2015-05-27 16:49:31 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
2014-04-06 13:21:22 -04:00
|
|
|
)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-12-11 17:37:41 -05:00
|
|
|
// StepUploadParallelsTools is a step that uploads the Parallels Tools ISO
|
|
|
|
// to the VM.
|
|
|
|
//
|
|
|
|
// Uses:
|
|
|
|
// communicator packer.Communicator
|
|
|
|
// parallels_tools_path string
|
|
|
|
// ui packer.Ui
|
2014-04-06 13:21:22 -04:00
|
|
|
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
|
2015-05-27 16:49:31 -04:00
|
|
|
Ctx interpolate.Context
|
2014-04-06 13:21:22 -04:00
|
|
|
}
|
|
|
|
|
2016-12-16 14:51:55 -05:00
|
|
|
// Run uploads the Parallels Tools ISO to the VM.
|
2014-04-06 13:21:22 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-03-28 20:45:01 -04:00
|
|
|
// Get the Parallels Tools path on the host machine
|
2014-09-02 05:28:04 -04:00
|
|
|
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
|
|
|
|
2015-05-27 16:49:31 -04:00
|
|
|
s.Ctx.Data = &toolsPathTemplate{
|
2014-09-02 05:28:04 -04:00
|
|
|
Flavor: s.ParallelsToolsFlavor,
|
2014-04-06 13:21:22 -04:00
|
|
|
}
|
|
|
|
|
2015-05-27 16:49:31 -04:00
|
|
|
s.ParallelsToolsGuestPath, err = interpolate.Render(s.ParallelsToolsGuestPath, &s.Ctx)
|
2014-04-06 13:21:22 -04:00
|
|
|
if err != nil {
|
2016-12-11 16:12:55 -05:00
|
|
|
err = fmt.Errorf("Error preparing Parallels Tools path: %s", err)
|
2014-04-06 13:21:22 -04:00
|
|
|
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-05-10 00:03:35 -04:00
|
|
|
if err := comm.Upload(s.ParallelsToolsGuestPath, f, nil); err != nil {
|
2016-12-11 16:12:55 -05:00
|
|
|
err = fmt.Errorf("Error uploading Parallels Tools: %s", err)
|
2014-09-02 05:28:04 -04:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
2014-04-06 13:21:22 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2016-12-16 14:51:55 -05:00
|
|
|
// Cleanup does nothing.
|
2014-04-06 13:21:22 -04:00
|
|
|
func (s *StepUploadParallelsTools) Cleanup(state multistep.StateBag) {}
|