Merge pull request #137 from bdon/forwarded-port-cleanup
builder/virtualbox: clean up port forwarding before exporting OVF.
This commit is contained in:
commit
d002f90cb1
|
@ -7,8 +7,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This step creates the virtual disk that will be used as the
|
// This step cleans up forwarded ports and exports the VM to an OVF.
|
||||||
// hard drive for the virtual machine.
|
|
||||||
//
|
//
|
||||||
// Uses:
|
// Uses:
|
||||||
//
|
//
|
||||||
|
@ -22,9 +21,20 @@ func (s *stepExport) Run(state map[string]interface{}) multistep.StepAction {
|
||||||
ui := state["ui"].(packer.Ui)
|
ui := state["ui"].(packer.Ui)
|
||||||
vmName := state["vmName"].(string)
|
vmName := state["vmName"].(string)
|
||||||
|
|
||||||
|
// Clear out the Packer-created forwarding rule
|
||||||
|
ui.Say(fmt.Sprintf("Deleting forwarded port mapping for SSH (host port %d)", state["sshHostPort"]))
|
||||||
|
command := []string{"modifyvm", vmName, "--natpf1", "delete", "packerssh"}
|
||||||
|
if err := driver.VBoxManage(command...); err != nil {
|
||||||
|
err := fmt.Errorf("Error deleting port forwarding rule: %s", err)
|
||||||
|
state["error"] = err
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export the VM to an OVF
|
||||||
outputPath := filepath.Join(config.OutputDir, "packer.ovf")
|
outputPath := filepath.Join(config.OutputDir, "packer.ovf")
|
||||||
|
|
||||||
command := []string{
|
command = []string{
|
||||||
"export",
|
"export",
|
||||||
vmName,
|
vmName,
|
||||||
"--output",
|
"--output",
|
||||||
|
|
|
@ -36,7 +36,7 @@ func (s *stepForwardSSH) Run(state map[string]interface{}) multistep.StepAction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach the disk to the controller
|
// Create a forwarded port mapping to the VM
|
||||||
ui.Say(fmt.Sprintf("Creating forwarded port mapping for SSH (host port %d)", sshHostPort))
|
ui.Say(fmt.Sprintf("Creating forwarded port mapping for SSH (host port %d)", sshHostPort))
|
||||||
command := []string{
|
command := []string{
|
||||||
"modifyvm", vmName,
|
"modifyvm", vmName,
|
||||||
|
|
Loading…
Reference in New Issue