Merge pull request #4960 from rickard-von-essen/issue-4959

virtualbox: Don't add portforwarding if comm = none
This commit is contained in:
Matthew Hooker 2017-06-02 13:15:43 -07:00 committed by GitHub
commit 0c116981ab
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...")
// Clear out the Packer-created forwarding rule
if !s.SkipNatMapping {
sshPort := state.Get("sshHostPort")
if !s.SkipNatMapping && sshPort != 0 {
ui.Message(fmt.Sprintf(
"Deleting forwarded port mapping for the communicator (SSH, WinRM, etc) (host port %d)",
state.Get("sshHostPort")))
"Deleting forwarded port mapping for the communicator (SSH, WinRM, etc) (host port %d)", sshPort))
command := []string{"modifyvm", vmName, "--natpf1", "delete", "packercomm"}
if err := driver.VBoxManage(command...); err != nil {
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)
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()
sshHostPort := guestPort
if !s.SkipNatMapping {