2014-04-06 13:21:22 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-12-11 13:49:54 -05:00
|
|
|
"log"
|
|
|
|
|
2014-04-06 13:21:22 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
2014-09-02 05:28:04 -04:00
|
|
|
// This step attaches the Parallels Tools as an inserted CD onto
|
2014-04-06 13:21:22 -04:00
|
|
|
// the virtual machine.
|
|
|
|
//
|
|
|
|
// Uses:
|
|
|
|
// driver Driver
|
2014-09-02 05:28:04 -04:00
|
|
|
// parallels_tools_path string
|
2014-04-06 13:21:22 -04:00
|
|
|
// ui packer.Ui
|
|
|
|
// vmName string
|
|
|
|
//
|
|
|
|
// Produces:
|
|
|
|
type StepAttachParallelsTools struct {
|
2014-09-17 07:14:54 -04:00
|
|
|
cdromDevice string
|
2014-09-02 05:28:04 -04:00
|
|
|
ParallelsToolsMode string
|
2014-04-06 13:21:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepAttachParallelsTools) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
driver := state.Get("driver").(Driver)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
vmName := state.Get("vmName").(string)
|
|
|
|
|
|
|
|
// If we're not attaching the guest additions then just return
|
|
|
|
if s.ParallelsToolsMode != ParallelsToolsModeAttach {
|
|
|
|
log.Println("Not attaching parallels tools since we're uploading.")
|
|
|
|
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
|
|
|
// Attach the guest additions to the computer
|
2014-09-17 07:14:54 -04:00
|
|
|
ui.Say("Attaching Parallels Tools ISO to the new CD/DVD drive...")
|
|
|
|
|
2016-12-11 13:49:54 -05:00
|
|
|
cdrom, err := driver.DeviceAddCDROM(vmName, parallelsToolsPath)
|
2014-09-17 07:14:54 -04:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error attaching Parallels Tools ISO: %s", err)
|
2014-04-06 13:21:22 -04:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2014-09-17 07:14:54 -04:00
|
|
|
// Track the device name so that we can can delete later
|
|
|
|
s.cdromDevice = cdrom
|
2014-04-06 13:21:22 -04:00
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2014-08-08 02:12:48 -04:00
|
|
|
func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) {
|
2014-09-17 07:14:54 -04:00
|
|
|
if s.cdromDevice == "" {
|
2014-08-08 02:12:48 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
driver := state.Get("driver").(Driver)
|
2014-09-02 05:28:04 -04:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2014-08-08 02:12:48 -04:00
|
|
|
vmName := state.Get("vmName").(string)
|
|
|
|
|
|
|
|
log.Println("Detaching Parallels Tools ISO...")
|
|
|
|
|
|
|
|
command := []string{
|
|
|
|
"set", vmName,
|
2014-09-17 07:14:54 -04:00
|
|
|
"--device-del", s.cdromDevice,
|
2014-08-08 02:12:48 -04:00
|
|
|
}
|
2014-09-02 05:28:04 -04:00
|
|
|
|
|
|
|
if err := driver.Prlctl(command...); err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Error detaching Parallels Tools ISO: %s", err))
|
|
|
|
}
|
2014-08-08 02:12:48 -04:00
|
|
|
}
|