2014-04-06 13:21:22 -04:00
|
|
|
package iso
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-12-11 14:13:37 -05:00
|
|
|
"log"
|
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
parallelscommon "github.com/hashicorp/packer/builder/parallels/common"
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2014-04-06 13:21:22 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// This step attaches the ISO to the virtual machine.
|
|
|
|
//
|
|
|
|
// Uses:
|
2014-09-17 07:14:54 -04:00
|
|
|
// driver Driver
|
2016-12-11 13:49:54 -05:00
|
|
|
// iso_path string
|
2014-09-17 07:14:54 -04:00
|
|
|
// ui packer.Ui
|
|
|
|
// vmName string
|
2014-04-06 13:21:22 -04:00
|
|
|
//
|
|
|
|
// Produces:
|
2014-11-27 07:20:19 -05:00
|
|
|
// attachedIso bool
|
|
|
|
type stepAttachISO struct{}
|
2014-04-06 13:21:22 -04:00
|
|
|
|
2018-01-22 18:31:41 -05:00
|
|
|
func (s *stepAttachISO) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
2014-04-06 13:21:22 -04:00
|
|
|
driver := state.Get("driver").(parallelscommon.Driver)
|
|
|
|
isoPath := state.Get("iso_path").(string)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
vmName := state.Get("vmName").(string)
|
|
|
|
|
2014-11-27 07:20:19 -05:00
|
|
|
// Attach the disk to the cdrom0 device. We couldn't use a separated device because it is failed to boot in PD9 [GH-1667]
|
|
|
|
ui.Say("Attaching ISO to the default CD/DVD ROM device...")
|
2014-11-27 09:13:50 -05:00
|
|
|
command := []string{
|
2014-09-30 02:44:20 -04:00
|
|
|
"set", vmName,
|
2014-11-27 07:20:19 -05:00
|
|
|
"--device-set", "cdrom0",
|
|
|
|
"--image", isoPath,
|
|
|
|
"--enable", "--connect",
|
2014-09-30 02:44:20 -04:00
|
|
|
}
|
|
|
|
if err := driver.Prlctl(command...); err != nil {
|
2014-11-27 07:20:19 -05:00
|
|
|
err := fmt.Errorf("Error attaching ISO: %s", err)
|
2014-09-30 02:44:20 -04:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2014-11-27 07:20:19 -05:00
|
|
|
// Set some state so we know to remove
|
|
|
|
state.Put("attachedIso", true)
|
2014-04-06 13:21:22 -04:00
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2014-08-08 02:12:48 -04:00
|
|
|
func (s *stepAttachISO) Cleanup(state multistep.StateBag) {
|
2014-11-27 07:20:19 -05:00
|
|
|
if _, ok := state.GetOk("attachedIso"); !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-08-08 02:12:48 -04:00
|
|
|
driver := state.Get("driver").(parallelscommon.Driver)
|
2014-09-17 07:14:54 -04:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2014-08-08 02:12:48 -04:00
|
|
|
vmName := state.Get("vmName").(string)
|
|
|
|
|
2014-11-27 07:20:19 -05:00
|
|
|
// Detach ISO by setting an empty string image.
|
|
|
|
log.Println("Detaching ISO from the default CD/DVD ROM device...")
|
2014-08-08 02:12:48 -04:00
|
|
|
command := []string{
|
2014-09-30 02:44:20 -04:00
|
|
|
"set", vmName,
|
2014-11-27 07:20:19 -05:00
|
|
|
"--device-set", "cdrom0",
|
|
|
|
"--image", "", "--disconnect", "--enable",
|
2014-08-08 02:12:48 -04:00
|
|
|
}
|
|
|
|
|
2014-09-17 07:14:54 -04:00
|
|
|
if err := driver.Prlctl(command...); err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Error detaching ISO: %s", err))
|
|
|
|
}
|
2014-08-08 02:12:48 -04:00
|
|
|
}
|