From ecbb0e84986cb404c6fa5a2b2d4b4b4745162ebc Mon Sep 17 00:00:00 2001 From: asatara Date: Fri, 28 Mar 2014 15:22:37 -0700 Subject: [PATCH] Added ssh_address variable to vmware builders --- builder/vmware/common/ssh.go | 4 ++++ builder/vmware/common/ssh_config.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/builder/vmware/common/ssh.go b/builder/vmware/common/ssh.go index 7bf8bac72..0d2fdce0d 100644 --- a/builder/vmware/common/ssh.go +++ b/builder/vmware/common/ssh.go @@ -17,6 +17,10 @@ func SSHAddressFunc(config *SSHConfig) func(multistep.StateBag) (string, error) driver := state.Get("driver").(Driver) vmxPath := state.Get("vmx_path").(string) + if config.SSHHost != "" { + return fmt.Sprintf("%s:%d", config.SSHHost, config.SSHPort), nil + } + log.Println("Lookup up IP information...") f, err := os.Open(vmxPath) if err != nil { diff --git a/builder/vmware/common/ssh_config.go b/builder/vmware/common/ssh_config.go index 0eab2ac3c..b036133cc 100644 --- a/builder/vmware/common/ssh_config.go +++ b/builder/vmware/common/ssh_config.go @@ -3,6 +3,7 @@ package common import ( "errors" "fmt" + "net" "os" "time" @@ -13,6 +14,7 @@ type SSHConfig struct { SSHUser string `mapstructure:"ssh_username"` SSHKeyPath string `mapstructure:"ssh_key_path"` SSHPassword string `mapstructure:"ssh_password"` + SSHHost string `mapstructure:"ssh_host"` SSHPort uint `mapstructure:"ssh_port"` SSHSkipRequestPty bool `mapstructure:"ssh_skip_request_pty"` RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"` @@ -53,6 +55,14 @@ func (c *SSHConfig) Prepare(t *packer.ConfigTemplate) []error { } } + if c.SSHHost != "" { + if ip := net.ParseIP(c.SSHHost); ip == nil { + if _, err := net.LookupHost(c.SSHHost); err != nil { + errs = append(errs, errors.New("ssh_host is an invalid IP or hostname")) + } + } + } + if c.SSHUser == "" { errs = append(errs, errors.New("An ssh_username must be specified.")) }