From f801c507fc33121cf6863eadafcc0e4f64adec90 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Tue, 23 May 2017 14:50:49 -0700 Subject: [PATCH] builder/vmware: make vnc probe timeout configurable --- builder/vmware/iso/driver_esx5.go | 12 +++++++++++- website/source/docs/builders/vmware-iso.html.md | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/builder/vmware/iso/driver_esx5.go b/builder/vmware/iso/driver_esx5.go index cd0002abc..bcd71cbd4 100644 --- a/builder/vmware/iso/driver_esx5.go +++ b/builder/vmware/iso/driver_esx5.go @@ -198,6 +198,16 @@ func (d *ESX5Driver) VNCAddress(_ string, portMin, portMax uint) (string, uint, } } + vncTimeout := time.Duration(15) + envTimeout := os.Getenv("PACKER_ESXI_VNC_PROBE_TIMEOUT") + if envTimeout != "" { + if parsedTimeout, err := time.ParseDuration(envTimeout); err != nil { + log.Printf("Error parsing PACKER_ESXI_VNC_PROBE_TIMEOUT. Falling back to default (15s). %s", err) + } else { + vncTimeout = parsedTimeout + } + } + for port := portMin; port <= portMax; port++ { if _, ok := listenPorts[fmt.Sprintf("%d", port)]; ok { log.Printf("Port %d in use", port) @@ -205,7 +215,7 @@ func (d *ESX5Driver) VNCAddress(_ string, portMin, portMax uint) (string, uint, } address := fmt.Sprintf("%s:%d", d.Host, port) log.Printf("Trying address: %s...", address) - l, err := net.DialTimeout("tcp", address, 30*time.Second) + l, err := net.DialTimeout("tcp", address, vncTimeout) if err != nil { if e, ok := err.(*net.OpError); ok { diff --git a/website/source/docs/builders/vmware-iso.html.md b/website/source/docs/builders/vmware-iso.html.md index 377ab9018..44a7e28e2 100644 --- a/website/source/docs/builders/vmware-iso.html.md +++ b/website/source/docs/builders/vmware-iso.html.md @@ -477,6 +477,21 @@ modify as well: format of the exported virtual machine. This defaults to "ovf". Before using this option, you need to install `ovftool`. + +### VNC port discovery + +Packer needs to decide on a port to use for VNC when building remotely. To find +an open port, we try to connect to ports in the range of `vnc_port_min` to +`vnc_port_max`. If we notice something is listening on a port in the range, we +try to connect to the next one, and so on until we find a port that has nothing +listening on it. If you have many clients building on the ESXi host, there +might be competition for the VNC ports. You can adjust how long packer waits +for a connection timeout by setting `PACKER_ESXI_VNC_PROBE_TIMEOUT`. This +defaults to 15 seconds. Set this shorter if vnc connections are refused, and +set it longer if Packer can't find an open port. This is intended as an +advanced configuration option. Please make sure your firewall settings are +correct before adjusting. + ### Using a Floppy for Linux kickstart file or preseed Depending on your network configuration, it may be difficult to use packer's