Merge pull request #4496 from mitchellh/vmrmguest2

builder/virtualbox: remove guest additions
This commit is contained in:
Matthew Hooker 2017-02-03 23:14:35 -08:00 committed by GitHub
commit 84fc62f6b2
2 changed files with 21 additions and 4 deletions

View File

@ -56,6 +56,7 @@ func (s *StepAttachGuestAdditions) Run(state multistep.StateBag) multistep.StepA
// Track the path so that we can unregister it from VirtualBox later // Track the path so that we can unregister it from VirtualBox later
s.attachedPath = guestAdditionsPath s.attachedPath = guestAdditionsPath
state.Put("guest_additions_attached", true)
return multistep.ActionContinue return multistep.ActionContinue
} }
@ -66,7 +67,6 @@ func (s *StepAttachGuestAdditions) Cleanup(state multistep.StateBag) {
} }
driver := state.Get("driver").(Driver) driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string) vmName := state.Get("vmName").(string)
command := []string{ command := []string{
@ -77,7 +77,7 @@ func (s *StepAttachGuestAdditions) Cleanup(state multistep.StateBag) {
"--medium", "none", "--medium", "none",
} }
if err := driver.VBoxManage(command...); err != nil { // Remove the ISO. Note that this will probably fail since
ui.Error(fmt.Sprintf("Error unregistering guest additions: %s", err)) // stepRemoveDevices does this as well. No big deal.
} driver.VBoxManage(command...)
} }

View File

@ -79,6 +79,23 @@ func (s *StepRemoveDevices) Run(state multistep.StateBag) multistep.StepAction {
} }
} }
if _, ok := state.GetOk("guest_additions_attached"); ok {
ui.Message("Removing guest additions drive...")
command := []string{
"storageattach", vmName,
"--storagectl", "IDE Controller",
"--port", "1",
"--device", "0",
"--medium", "none",
}
if err := driver.VBoxManage(command...); err != nil {
err := fmt.Errorf("Error removing guest additions: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
}
return multistep.ActionContinue return multistep.ActionContinue
} }