builder/parallels: Disable default cdrom0 device and then enable it on cleanup

This is needed to make 'cdrom0' device unavailable during the ISO installation process.
It is required for some guest OS types, such as FreeBSD and OmniOS.
This commit is contained in:
Mikhail Zholobov 2014-09-30 10:44:20 +04:00 committed by Rickard von Essen
parent 13251ced49
commit eb37742ab0
1 changed files with 32 additions and 6 deletions

View File

@ -38,6 +38,7 @@ func (s *stepAttachISO) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
// Set new boot order
ui.Say("Setting the boot order...")
command := []string{
"set", vmName,
@ -51,6 +52,20 @@ func (s *stepAttachISO) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
// Disable 'cdrom0' device
ui.Say("Disabling default CD/DVD drive...")
command = []string{
"set", vmName,
"--device-set", "cdrom0", "--disable",
}
if err := driver.Prlctl(command...); err != nil {
err := fmt.Errorf("Error disabling default CD/DVD drive: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
// Track the device name so that we can can delete later
s.cdromDevice = cdrom
@ -58,17 +73,28 @@ func (s *stepAttachISO) Run(state multistep.StateBag) multistep.StepAction {
}
func (s *stepAttachISO) Cleanup(state multistep.StateBag) {
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...")
// Enable 'cdrom0' device back
log.Println("Enabling default CD/DVD drive...")
command := []string{
"set", vmName,
"--device-set", "cdrom0", "--enable",
}
if err := driver.Prlctl(command...); err != nil {
ui.Error(fmt.Sprintf("Error enabling default CD/DVD drive: %s", err))
}
// Detach ISO
if s.cdromDevice == "" {
return
}
log.Println("Detaching ISO...")
command = []string{
"set", vmName,
"--device-del", s.cdromDevice,
}