virtualbox: Don't add portforwarding if comm = none

Closes: #4959
This commit is contained in:
Rickard von Essen 2017-06-02 21:58:34 +02:00
parent 20b53f5ca3
commit 31b93a3026
2 changed files with 9 additions and 3 deletions

View File

@ -41,10 +41,10 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
ui.Say("Preparing to export machine...") ui.Say("Preparing to export machine...")
// Clear out the Packer-created forwarding rule // Clear out the Packer-created forwarding rule
if !s.SkipNatMapping { sshPort := state.Get("sshHostPort")
if !s.SkipNatMapping && sshPort != 0 {
ui.Message(fmt.Sprintf( ui.Message(fmt.Sprintf(
"Deleting forwarded port mapping for the communicator (SSH, WinRM, etc) (host port %d)", "Deleting forwarded port mapping for the communicator (SSH, WinRM, etc) (host port %d)", sshPort))
state.Get("sshHostPort")))
command := []string{"modifyvm", vmName, "--natpf1", "delete", "packercomm"} command := []string{"modifyvm", vmName, "--natpf1", "delete", "packercomm"}
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)

View File

@ -32,6 +32,12 @@ func (s *StepForwardSSH) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string) vmName := state.Get("vmName").(string)
if s.CommConfig.Type == "none" {
log.Printf("Not using a communicator, skipping setting up port forwarding...")
state.Put("sshHostPort", 0)
return multistep.ActionContinue
}
guestPort := s.CommConfig.Port() guestPort := s.CommConfig.Port()
sshHostPort := guestPort sshHostPort := guestPort
if !s.SkipNatMapping { if !s.SkipNatMapping {