From fe37d9b6e19123491d16adb9ff31fe83b78c947e Mon Sep 17 00:00:00 2001 From: Rickard von Essen Date: Fri, 8 Aug 2014 08:12:48 +0200 Subject: [PATCH] parallels-iso: ISO not removed from VM after install [GH-1338] Also remove floppy and prl-tools ISO if applicable. --- .../parallels/common/step_attach_floppy.go | 18 +++++++++++++-- .../common/step_attach_parallels_tools.go | 23 +++++++++++++++++-- builder/parallels/iso/step_attach_iso.go | 21 ++++++++++++++++- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/builder/parallels/common/step_attach_floppy.go b/builder/parallels/common/step_attach_floppy.go index efc4088fb..8085cf96c 100644 --- a/builder/parallels/common/step_attach_floppy.go +++ b/builder/parallels/common/step_attach_floppy.go @@ -44,7 +44,7 @@ func (s *StepAttachFloppy) Run(state multistep.StateBag) multistep.StepAction { } ui.Say("Attaching floppy disk...") - // Create the floppy disk controller + // Attaching the floppy disk add_command := []string{ "set", vmName, "--device-add", "fdd", @@ -62,4 +62,18 @@ func (s *StepAttachFloppy) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionContinue } -func (s *StepAttachFloppy) Cleanup(state multistep.StateBag) {} +func (s *StepAttachFloppy) Cleanup(state multistep.StateBag) { + driver := state.Get("driver").(Driver) + vmName := state.Get("vmName").(string) + + if s.floppyPath == "" { + return + } + + log.Println("Detaching floppy disk...") + command := []string{ + "set", vmName, + "--device-del", "fdd0", + } + driver.Prlctl(command...) +} diff --git a/builder/parallels/common/step_attach_parallels_tools.go b/builder/parallels/common/step_attach_parallels_tools.go index 250f2e50c..0d626c844 100644 --- a/builder/parallels/common/step_attach_parallels_tools.go +++ b/builder/parallels/common/step_attach_parallels_tools.go @@ -34,7 +34,7 @@ func (s *StepAttachParallelsTools) Run(state multistep.StateBag) multistep.StepA } // Attach the guest additions to the computer - log.Println("Attaching Parallels Tools ISO onto IDE controller...") + ui.Say("Attaching Parallels Tools ISO onto IDE controller...") command := []string{ "set", vmName, "--device-add", "cdrom", @@ -53,4 +53,23 @@ func (s *StepAttachParallelsTools) Run(state multistep.StateBag) multistep.StepA return multistep.ActionContinue } -func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) {} +func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) { + if _, ok := state.GetOk("attachedToolsIso"); !ok { + return + } + + driver := state.Get("driver").(Driver) + 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, + } + driver.Prlctl(command...) +} diff --git a/builder/parallels/iso/step_attach_iso.go b/builder/parallels/iso/step_attach_iso.go index c4937217c..7f9f699ad 100644 --- a/builder/parallels/iso/step_attach_iso.go +++ b/builder/parallels/iso/step_attach_iso.go @@ -5,6 +5,7 @@ import ( "github.com/mitchellh/multistep" parallelscommon "github.com/mitchellh/packer/builder/parallels/common" "github.com/mitchellh/packer/packer" + "log" ) // This step attaches the ISO to the virtual machine. @@ -23,6 +24,7 @@ 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", @@ -42,4 +44,21 @@ func (s *stepAttachISO) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionContinue } -func (s *stepAttachISO) Cleanup(state multistep.StateBag) {} +func (s *stepAttachISO) Cleanup(state multistep.StateBag) { + if _, ok := state.GetOk("attachedIso"); !ok { + return + } + + driver := state.Get("driver").(parallelscommon.Driver) + vmName := state.Get("vmName").(string) + + command := []string{ + "set", vmName, + "--device-set", "cdrom0", + "--enable", "--disconnect", + } + + // Remove the ISO, ignore errors + log.Println("Detaching ISO...") + driver.Prlctl(command...) +}