builder/vmware: Ability to specify the SSH port with "ssh_port"
This commit is contained in:
parent
0c59ad8087
commit
62406b5ab5
|
@ -40,6 +40,7 @@ type config struct {
|
||||||
ShutdownTimeout time.Duration ``
|
ShutdownTimeout time.Duration ``
|
||||||
SSHUser string `mapstructure:"ssh_username"`
|
SSHUser string `mapstructure:"ssh_username"`
|
||||||
SSHPassword string `mapstructure:"ssh_password"`
|
SSHPassword string `mapstructure:"ssh_password"`
|
||||||
|
SSHPort uint `mapstructure:"ssh_port"`
|
||||||
SSHWaitTimeout time.Duration ``
|
SSHWaitTimeout time.Duration ``
|
||||||
VMXData map[string]string `mapstructure:"vmx_data"`
|
VMXData map[string]string `mapstructure:"vmx_data"`
|
||||||
VNCPortMin uint `mapstructure:"vnc_port_min"`
|
VNCPortMin uint `mapstructure:"vnc_port_min"`
|
||||||
|
@ -92,6 +93,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
||||||
b.config.OutputDir = "vmware"
|
b.config.OutputDir = "vmware"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.config.SSHPort == 0 {
|
||||||
|
b.config.SSHPort = 22
|
||||||
|
}
|
||||||
|
|
||||||
// Accumulate any errors
|
// Accumulate any errors
|
||||||
var err error
|
var err error
|
||||||
errs := make([]error, 0)
|
errs := make([]error, 0)
|
||||||
|
|
|
@ -200,6 +200,34 @@ func TestBuilderPrepare_SSHUser(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuilderPrepare_SSHPort(t *testing.T) {
|
||||||
|
var b Builder
|
||||||
|
config := testConfig()
|
||||||
|
|
||||||
|
// Test with a bad value
|
||||||
|
delete(config, "ssh_port")
|
||||||
|
err := b.Prepare(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("bad err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.config.SSHPort != 22 {
|
||||||
|
t.Fatalf("bad ssh port: %d", b.config.SSHPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test with a good one
|
||||||
|
config["ssh_port"] = 44
|
||||||
|
b = Builder{}
|
||||||
|
err = b.Prepare(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not have error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.config.SSHPort != 44 {
|
||||||
|
t.Fatalf("bad ssh port: %d", b.config.SSHPort)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
|
func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
|
||||||
var b Builder
|
var b Builder
|
||||||
config := testConfig()
|
config := testConfig()
|
||||||
|
|
|
@ -144,7 +144,7 @@ func (s *stepWaitForSSH) waitForSSH(state map[string]interface{}) (packer.Commun
|
||||||
log.Printf("Detected IP: %s", ip)
|
log.Printf("Detected IP: %s", ip)
|
||||||
|
|
||||||
// Attempt to connect to SSH port
|
// Attempt to connect to SSH port
|
||||||
nc, err = net.Dial("tcp", fmt.Sprintf("%s:22", ip))
|
nc, err = net.Dial("tcp", fmt.Sprintf("%s:%d", ip, config.SSHPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("TCP connection to SSH ip/port failed: %s", err)
|
log.Printf("TCP connection to SSH ip/port failed: %s", err)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue