From 7fc2ea8422e492af5e6204d1f685c1c346dca4b3 Mon Sep 17 00:00:00 2001 From: Joshua Foster Date: Wed, 17 Jun 2020 01:46:30 -0400 Subject: [PATCH] add a fallback to an ipv4 address if the the range can't find one --- builder/vsphere/common/step_http_ip_discover.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/builder/vsphere/common/step_http_ip_discover.go b/builder/vsphere/common/step_http_ip_discover.go index 04fe4f775..363c9d472 100644 --- a/builder/vsphere/common/step_http_ip_discover.go +++ b/builder/vsphere/common/step_http_ip_discover.go @@ -43,6 +43,7 @@ func getHostIP(s string, network *net.IPNet) (string, error) { return "", err } + // look for an IP that is contained in the ip_wait_address range for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if ok && !ipnet.IP.IsLoopback() { @@ -51,5 +52,15 @@ func getHostIP(s string, network *net.IPNet) (string, error) { } } } + + // fallback to an ipv4 address if an IP is not found in the range + for _, a := range addrs { + ipnet, ok := a.(*net.IPNet) + if ok && !ipnet.IP.IsLoopback() { + if ipnet.IP.To4() != nil { + return ipnet.IP.String(), nil + } + } + } return "", fmt.Errorf("IP not found") }