Merge pull request #1078 from pleschev/skip_nat_port
Adding the ability to skip nat port forwarding for ssh connectivity
This commit is contained in:
commit
8d6a99457a
|
@ -18,6 +18,7 @@ type SSHConfig struct {
|
||||||
SSHPort uint `mapstructure:"ssh_port"`
|
SSHPort uint `mapstructure:"ssh_port"`
|
||||||
SSHUser string `mapstructure:"ssh_username"`
|
SSHUser string `mapstructure:"ssh_username"`
|
||||||
RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"`
|
RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"`
|
||||||
|
SSHSkipNatMapping bool `mapstructure:"ssh_skip_nat_mapping"`
|
||||||
|
|
||||||
SSHWaitTimeout time.Duration
|
SSHWaitTimeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ type StepExport struct {
|
||||||
Format string
|
Format string
|
||||||
OutputDir string
|
OutputDir string
|
||||||
ExportOpts []string
|
ExportOpts []string
|
||||||
|
SkipNatMapping bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
|
func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
@ -33,6 +34,9 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
|
||||||
// Clear out the Packer-created forwarding rule
|
// Clear out the Packer-created forwarding rule
|
||||||
ui.Say("Preparing to export machine...")
|
ui.Say("Preparing to export machine...")
|
||||||
|
var command []string
|
||||||
|
|
||||||
|
if s.SkipNatMapping == false {
|
||||||
ui.Message(fmt.Sprintf(
|
ui.Message(fmt.Sprintf(
|
||||||
"Deleting forwarded port mapping for SSH (host port %d)",
|
"Deleting forwarded port mapping for SSH (host port %d)",
|
||||||
state.Get("sshHostPort")))
|
state.Get("sshHostPort")))
|
||||||
|
@ -43,6 +47,7 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Export the VM to an OVF
|
// Export the VM to an OVF
|
||||||
outputPath := filepath.Join(s.OutputDir, vmName+"."+s.Format)
|
outputPath := filepath.Join(s.OutputDir, vmName+"."+s.Format)
|
||||||
|
|
|
@ -22,6 +22,7 @@ type StepForwardSSH struct {
|
||||||
GuestPort uint
|
GuestPort uint
|
||||||
HostPortMin uint
|
HostPortMin uint
|
||||||
HostPortMax uint
|
HostPortMax uint
|
||||||
|
SkipNatMapping bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepForwardSSH) Run(state multistep.StateBag) multistep.StepAction {
|
func (s *StepForwardSSH) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
@ -29,9 +30,13 @@ 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)
|
||||||
|
|
||||||
|
var sshHostPort uint
|
||||||
|
if s.SkipNatMapping {
|
||||||
|
sshHostPort = s.GuestPort
|
||||||
|
log.Printf("Skipping SSH NAT mapping and using SSH port %d", sshHostPort)
|
||||||
|
} else {
|
||||||
log.Printf("Looking for available SSH port between %d and %d",
|
log.Printf("Looking for available SSH port between %d and %d",
|
||||||
s.HostPortMin, s.HostPortMax)
|
s.HostPortMin, s.HostPortMax)
|
||||||
var sshHostPort uint
|
|
||||||
var offset uint = 0
|
var offset uint = 0
|
||||||
|
|
||||||
portRange := int(s.HostPortMax - s.HostPortMin)
|
portRange := int(s.HostPortMax - s.HostPortMin)
|
||||||
|
@ -63,6 +68,7 @@ func (s *StepForwardSSH) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Save the port we're using so that future steps can use it
|
// Save the port we're using so that future steps can use it
|
||||||
state.Put("sshHostPort", sshHostPort)
|
state.Put("sshHostPort", sshHostPort)
|
||||||
|
|
|
@ -256,6 +256,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
GuestPort: b.config.SSHPort,
|
GuestPort: b.config.SSHPort,
|
||||||
HostPortMin: b.config.SSHHostPortMin,
|
HostPortMin: b.config.SSHHostPortMin,
|
||||||
HostPortMax: b.config.SSHHostPortMax,
|
HostPortMax: b.config.SSHHostPortMax,
|
||||||
|
SkipNatMapping: b.config.SSHSkipNatMapping,
|
||||||
},
|
},
|
||||||
&vboxcommon.StepVBoxManage{
|
&vboxcommon.StepVBoxManage{
|
||||||
Commands: b.config.VBoxManage,
|
Commands: b.config.VBoxManage,
|
||||||
|
@ -297,6 +298,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
Format: b.config.Format,
|
Format: b.config.Format,
|
||||||
OutputDir: b.config.OutputDir,
|
OutputDir: b.config.OutputDir,
|
||||||
ExportOpts: b.config.ExportOpts.ExportOpts,
|
ExportOpts: b.config.ExportOpts.ExportOpts,
|
||||||
|
SkipNatMapping: b.config.SSHSkipNatMapping,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
GuestPort: b.config.SSHPort,
|
GuestPort: b.config.SSHPort,
|
||||||
HostPortMin: b.config.SSHHostPortMin,
|
HostPortMin: b.config.SSHHostPortMin,
|
||||||
HostPortMax: b.config.SSHHostPortMax,
|
HostPortMax: b.config.SSHHostPortMax,
|
||||||
|
SkipNatMapping: b.config.SSHSkipNatMapping,
|
||||||
},
|
},
|
||||||
&vboxcommon.StepVBoxManage{
|
&vboxcommon.StepVBoxManage{
|
||||||
Commands: b.config.VBoxManage,
|
Commands: b.config.VBoxManage,
|
||||||
|
@ -126,6 +127,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
Format: b.config.Format,
|
Format: b.config.Format,
|
||||||
OutputDir: b.config.OutputDir,
|
OutputDir: b.config.OutputDir,
|
||||||
ExportOpts: b.config.ExportOpts.ExportOpts,
|
ExportOpts: b.config.ExportOpts.ExportOpts,
|
||||||
|
SkipNatMapping: b.config.SSHSkipNatMapping,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,6 +209,10 @@ each category, the available options are alphabetized and described.
|
||||||
available. By default this is "20m", or 20 minutes. Note that this should
|
available. By default this is "20m", or 20 minutes. Note that this should
|
||||||
be quite long since the timer begins as soon as the virtual machine is booted.
|
be quite long since the timer begins as soon as the virtual machine is booted.
|
||||||
|
|
||||||
|
* `ssh_skip_nat_mapping` (bool) - Defaults to false. When enabled, Packer does
|
||||||
|
not setup forwarded port mapping for SSH requests and uses `ssh_port` on the
|
||||||
|
host to communicate to the virtual machine
|
||||||
|
|
||||||
* `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to
|
* `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to
|
||||||
execute in order to further customize the virtual machine being created.
|
execute in order to further customize the virtual machine being created.
|
||||||
The value of this is an array of commands to execute. The commands are executed
|
The value of this is an array of commands to execute. The commands are executed
|
||||||
|
|
|
@ -184,6 +184,10 @@ each category, the available options are alphabetized and described.
|
||||||
available. By default this is "20m", or 20 minutes. Note that this should
|
available. By default this is "20m", or 20 minutes. Note that this should
|
||||||
be quite long since the timer begins as soon as the virtual machine is booted.
|
be quite long since the timer begins as soon as the virtual machine is booted.
|
||||||
|
|
||||||
|
* `ssh_skip_nat_mapping` (bool) - Defaults to false. When enabled, Packer does
|
||||||
|
not setup forwarded port mapping for SSH requests and uses `ssh_port` on the
|
||||||
|
host to communicate to the virtual machine
|
||||||
|
|
||||||
* `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to
|
* `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to
|
||||||
execute in order to further customize the virtual machine being created.
|
execute in order to further customize the virtual machine being created.
|
||||||
The value of this is an array of commands to execute. The commands are executed
|
The value of this is an array of commands to execute. The commands are executed
|
||||||
|
|
Loading…
Reference in New Issue