builder/parallels: Attach ISO images to the separate cdrom device
For each ISO image the individual cdrom device will be added to the VM. During the cleanup these devices will be deleted. It makes attach steps more clear - there is no doubt what is the name of the device. Related to: [mitchellh/packer#1502]
This commit is contained in:
parent
0cfe58193f
commit
280c3c52de
|
@ -17,8 +17,8 @@ import (
|
|||
// vmName string
|
||||
//
|
||||
// Produces:
|
||||
// attachedToolsIso boolean
|
||||
type StepAttachParallelsTools struct {
|
||||
cdromDevice string
|
||||
ParallelsToolsMode string
|
||||
}
|
||||
|
||||
|
@ -37,27 +37,25 @@ func (s *StepAttachParallelsTools) Run(state multistep.StateBag) multistep.StepA
|
|||
parallelsToolsPath := state.Get("parallels_tools_path").(string)
|
||||
|
||||
// Attach the guest additions to the computer
|
||||
ui.Say("Attaching Parallels Tools ISO onto IDE controller...")
|
||||
command := []string{
|
||||
"set", vmName,
|
||||
"--device-add", "cdrom",
|
||||
"--image", parallelsToolsPath,
|
||||
}
|
||||
if err := driver.Prlctl(command...); err != nil {
|
||||
err := fmt.Errorf("Error attaching Parallels Tools: %s", err)
|
||||
ui.Say("Attaching Parallels Tools ISO to the new CD/DVD drive...")
|
||||
|
||||
cdrom, err := driver.DeviceAddCdRom(vmName, parallelsToolsPath)
|
||||
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error attaching Parallels Tools ISO: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
// Set some state so we know to remove
|
||||
state.Put("attachedToolsIso", true)
|
||||
// Track the device name so that we can can delete later
|
||||
s.cdromDevice = cdrom
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) {
|
||||
if _, ok := state.GetOk("attachedToolsIso"); !ok {
|
||||
if s.cdromDevice == "" {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -66,14 +64,10 @@ func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) {
|
|||
vmName := state.Get("vmName").(string)
|
||||
|
||||
log.Println("Detaching Parallels Tools ISO...")
|
||||
cdDevice := "cdrom0"
|
||||
if _, ok := state.GetOk("attachedIso"); ok {
|
||||
cdDevice = "cdrom1"
|
||||
}
|
||||
|
||||
command := []string{
|
||||
"set", vmName,
|
||||
"--device-del", cdDevice,
|
||||
"--device-del", s.cdromDevice,
|
||||
}
|
||||
|
||||
if err := driver.Prlctl(command...); err != nil {
|
||||
|
|
|
@ -11,10 +11,14 @@ import (
|
|||
// This step attaches the ISO to the virtual machine.
|
||||
//
|
||||
// Uses:
|
||||
// driver Driver
|
||||
// isoPath string
|
||||
// ui packer.Ui
|
||||
// vmName string
|
||||
//
|
||||
// Produces:
|
||||
type stepAttachISO struct {
|
||||
diskPath string
|
||||
cdromDevice string
|
||||
}
|
||||
|
||||
func (s *stepAttachISO) Run(state multistep.StateBag) multistep.StepAction {
|
||||
|
@ -24,41 +28,40 @@ func (s *stepAttachISO) Run(state multistep.StateBag) multistep.StepAction {
|
|||
vmName := state.Get("vmName").(string)
|
||||
|
||||
// Attach the disk to the controller
|
||||
ui.Say("Attaching ISO onto IDE controller...")
|
||||
command := []string{
|
||||
"set", vmName,
|
||||
"--device-set", "cdrom0",
|
||||
"--image", isoPath,
|
||||
"--enable", "--connect",
|
||||
}
|
||||
if err := driver.Prlctl(command...); err != nil {
|
||||
ui.Say("Attaching ISO to the new CD/DVD drive...")
|
||||
|
||||
cdrom, err := driver.DeviceAddCdRom(vmName, isoPath)
|
||||
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error attaching ISO: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
// Set some state so we know to remove
|
||||
state.Put("attachedIso", true)
|
||||
// Track the device name so that we can can delete later
|
||||
s.cdromDevice = cdrom
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *stepAttachISO) Cleanup(state multistep.StateBag) {
|
||||
if _, ok := state.GetOk("attachedIso"); !ok {
|
||||
if s.cdromDevice == "" {
|
||||
return
|
||||
}
|
||||
|
||||
driver := state.Get("driver").(parallelscommon.Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vmName := state.Get("vmName").(string)
|
||||
|
||||
log.Println("Detaching ISO...")
|
||||
|
||||
command := []string{
|
||||
"set", vmName,
|
||||
"--device-set", "cdrom0",
|
||||
"--enable", "--disconnect",
|
||||
"--device-del", s.cdromDevice,
|
||||
}
|
||||
|
||||
// Remove the ISO, ignore errors
|
||||
log.Println("Detaching ISO...")
|
||||
driver.Prlctl(command...)
|
||||
if err := driver.Prlctl(command...); err != nil {
|
||||
ui.Error(fmt.Sprintf("Error detaching ISO: %s", err))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue