Commit 1bb25c65 authored by Kristopher Ruzic's avatar Kristopher Ruzic

support connecting to vnc over ips other than localhost

the ssh support is not finished... Still working on this, but wanted to commit some progress
parent 5b6140b2
...@@ -105,10 +105,10 @@ type Config struct { ...@@ -105,10 +105,10 @@ type Config struct {
ShutdownCommand string `mapstructure:"shutdown_command"` ShutdownCommand string `mapstructure:"shutdown_command"`
SSHHostPortMin uint `mapstructure:"ssh_host_port_min"` SSHHostPortMin uint `mapstructure:"ssh_host_port_min"`
SSHHostPortMax uint `mapstructure:"ssh_host_port_max"` SSHHostPortMax uint `mapstructure:"ssh_host_port_max"`
VncIP string `mapstructure:"vnc_ip"`
VNCPortMin uint `mapstructure:"vnc_port_min"` VNCPortMin uint `mapstructure:"vnc_port_min"`
VNCPortMax uint `mapstructure:"vnc_port_max"` VNCPortMax uint `mapstructure:"vnc_port_max"`
VMName string `mapstructure:"vm_name"` VMName string `mapstructure:"vm_name"`
VncIP string `mapstructure:"vnc_ip"`
// These are deprecated, but we keep them around for BC // These are deprecated, but we keep them around for BC
// TODO(@mitchellh): remove // TODO(@mitchellh): remove
...@@ -359,8 +359,8 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { ...@@ -359,8 +359,8 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
warnings = append(warnings, warnings = append(warnings,
"No VNC IP address specified, will default to 127.0.0.1") "No VNC IP address specified, will default to 127.0.0.1")
b.config.VncIP = "127.0.0.1" b.config.VncIP = "127.0.0.1"
} }
if errs != nil && len(errs.Errors) > 0 { if errs != nil && len(errs.Errors) > 0 {
return warnings, errs return warnings, errs
} }
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
) )
func commHost(state multistep.StateBag) (string, error) { func commHost(state multistep.StateBag) (string, error) {
return "127.0.0.1", nil return state.Get("vnc_ip").(string), nil
} }
func commPort(state multistep.StateBag) (int, error) { func commPort(state multistep.StateBag) (int, error) {
......
...@@ -50,7 +50,7 @@ func (s *stepForwardSSH) Run(state multistep.StateBag) multistep.StepAction { ...@@ -50,7 +50,7 @@ func (s *stepForwardSSH) Run(state multistep.StateBag) multistep.StepAction {
// 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)
state.Put("vnc_ip", config.VncIP)
return multistep.ActionContinue return multistep.ActionContinue
} }
......
...@@ -30,6 +30,7 @@ type bootCommandTemplateData struct { ...@@ -30,6 +30,7 @@ type bootCommandTemplateData struct {
// http_port int // http_port int
// ui packer.Ui // ui packer.Ui
// vnc_port uint // vnc_port uint
// vnc_ip string
// //
// Produces: // Produces:
// <nothing> // <nothing>
...@@ -39,13 +40,13 @@ func (s *stepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction ...@@ -39,13 +40,13 @@ func (s *stepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
httpPort := state.Get("http_port").(uint) httpPort := state.Get("http_port").(uint)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
vncPort := state.Get("vnc_port").(uint)
vncAddr := state.Get("vnc_ip").(string)
vncIP := state.Get("vnc_ip").(string)
vncPort := state.Get("vnc_port").(uint)
// Connect to VNC // Connect to VNC
ui.Say("Connecting to VM via VNC") ui.Say("Connecting to VM via VNC")
// tbh why is this hardcoded anyway? // tbh why is this hardcoded anyway?
nc, err := net.Dial("tcp", fmt.Sprintf("%s:%d", vncAddr, vncPort)) nc, err := net.Dial("tcp", fmt.Sprintf("%s:%d", vncIP, vncPort))
if err != nil { if err != nil {
err := fmt.Errorf("Error connecting to VNC: %s", err) err := fmt.Errorf("Error connecting to VNC: %s", err)
state.Put("error", err) state.Put("error", err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment