@ -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
s tate. 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 ) )
}
}