builder/virtualbox: remove floppy drive before exporting

This commit is contained in:
Mitchell Hashimoto 2013-07-09 12:38:34 -07:00
parent 3a420478f9
commit dbad270d27
2 changed files with 20 additions and 3 deletions

View File

@ -85,7 +85,6 @@ func (s *stepAttachFloppy) Cleanup(state map[string]interface{}) {
defer os.Remove(s.floppyPath) defer os.Remove(s.floppyPath)
driver := state["driver"].(Driver) driver := state["driver"].(Driver)
ui := state["ui"].(packer.Ui)
vmName := state["vmName"].(string) vmName := state["vmName"].(string)
command := []string{ command := []string{
@ -97,7 +96,7 @@ func (s *stepAttachFloppy) Cleanup(state map[string]interface{}) {
} }
if err := driver.VBoxManage(command...); err != nil { if err := driver.VBoxManage(command...); err != nil {
ui.Error(fmt.Sprintf("Error unregistering floppy: %s", err)) log.Printf("Error unregistering floppy: %s", err)
} }
} }

View File

@ -22,7 +22,8 @@ func (s *stepExport) Run(state map[string]interface{}) multistep.StepAction {
vmName := state["vmName"].(string) vmName := state["vmName"].(string)
// Clear out the Packer-created forwarding rule // Clear out the Packer-created forwarding rule
ui.Say(fmt.Sprintf("Deleting forwarded port mapping for SSH (host port %d)", state["sshHostPort"])) ui.Say("Preparing to export machine...")
ui.Message(fmt.Sprintf("Deleting forwarded port mapping for SSH (host port %d)", state["sshHostPort"]))
command := []string{"modifyvm", vmName, "--natpf1", "delete", "packerssh"} command := []string{"modifyvm", vmName, "--natpf1", "delete", "packerssh"}
if err := driver.VBoxManage(command...); err != nil { if err := driver.VBoxManage(command...); err != nil {
err := fmt.Errorf("Error deleting port forwarding rule: %s", err) err := fmt.Errorf("Error deleting port forwarding rule: %s", err)
@ -31,6 +32,23 @@ func (s *stepExport) Run(state map[string]interface{}) multistep.StepAction {
return multistep.ActionHalt return multistep.ActionHalt
} }
// Remove the attached floppy disk, if it exists
if _, ok := state["floppy_path"]; ok {
ui.Message("Removing floppy drive...")
command := []string{
"storageattach", vmName,
"--storagectl", "Floppy Controller",
"--port", "0",
"--device", "0",
"--medium", "none",
}
if err := driver.VBoxManage(command...); err != nil {
state["error"] = fmt.Errorf("Error removing floppy: %s", err)
return multistep.ActionHalt
}
}
// Export the VM to an OVF // Export the VM to an OVF
outputPath := filepath.Join(config.OutputDir, "packer.ovf") outputPath := filepath.Join(config.OutputDir, "packer.ovf")