From 2c2904c0958be0dfb9ef800480685dcf01a3be9d Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Fri, 30 Mar 2018 18:19:25 -0500 Subject: [PATCH] Modified the path finders for the Player driver in the vmware-builders to search through all the possible variations for dhcp configuration and leases.. --- builder/vmware/common/driver_player_unix.go | 39 +++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/builder/vmware/common/driver_player_unix.go b/builder/vmware/common/driver_player_unix.go index 068720a6c..a963c60fa 100644 --- a/builder/vmware/common/driver_player_unix.go +++ b/builder/vmware/common/driver_player_unix.go @@ -7,6 +7,7 @@ import ( "bytes" "fmt" "log" + "os" "os/exec" "path/filepath" "regexp" @@ -44,7 +45,24 @@ func playerDhcpLeasesPath(device string) string { log.Printf("Error finding VMware root: %s", err) return "" } - return filepath.Join(base, device, "dhcpd/dhcpd.leases") + + // Build the base path to VMware configuration for specified device: `/etc/vmware/${device}` + devicebase := filepath.Join(base, device) + + // Walk through a list of paths searching for the correct permutation... + // ...as it appears that in >= WS14 and < WS14, the leases file may be labelled differently. + + // Docs say we should expect: dhcpd/dhcpd.leases + paths := []string{"dhcpd/dhcpd.leases", "dhcpd/dhcp.leases", "dhcp/dhcpd.leases", "dhcp/dhcp.leases"} + for _, p := range paths { + fp := filepath.Join(devicebase, p) + if _, err := os.Stat(fp); !os.IsNotExist(err) { + return fp + } + } + + log.Printf("Error finding VMWare DHCP Server Leases (dhcpd.leases) under device path: %s", devicebase) + return "" } func playerVmDhcpConfPath(device string) string { @@ -53,7 +71,24 @@ func playerVmDhcpConfPath(device string) string { log.Printf("Error finding VMware root: %s", err) return "" } - return filepath.Join(base, device, "dhcp/dhcp.conf") + + // Build the base path to VMware configuration for specified device: `/etc/vmware/${device}` + devicebase := filepath.Join(base, device) + + // Walk through a list of paths searching for the correct permutation... + // ...as it appears that in >= WS14 and < WS14, the dhcp config may be labelled differently. + + // Docs say we should expect: dhcp/dhcp.conf + paths := []string{"dhcp/dhcp.conf", "dhcp/dhcpd.conf", "dhcpd/dhcp.conf", "dhcpd/dhcpd.conf"} + for _, p := range paths { + fp := filepath.Join(devicebase, p) + if _, err := os.Stat(fp); !os.IsNotExist(err) { + return fp + } + } + + log.Printf("Error finding VMWare DHCP Server Configuration (dhcp.conf) under device path: %s", devicebase) + return "" } func playerVmnetnatConfPath(device string) string {