From 646523c5f4e2dd1791160434df557b7427288a09 Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Thu, 29 Mar 2018 13:04:25 -0500 Subject: [PATCH 1/4] Replaced the call to os.Open and ReadNetworkMap to just a single call to ReadNetmapConfig in both the Workstation9 and Player5 VMware drivers. --- builder/vmware/common/driver_player5.go | 9 ++------- builder/vmware/common/driver_workstation9.go | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/builder/vmware/common/driver_player5.go b/builder/vmware/common/driver_player5.go index fb14dcb52..5f492e6be 100644 --- a/builder/vmware/common/driver_player5.go +++ b/builder/vmware/common/driver_player5.go @@ -201,14 +201,9 @@ func (d *Player5Driver) Verify() error { if _, err := os.Stat(pathNetmap); err != nil { return nil, fmt.Errorf("Could not find netmap conf file: %s", pathNetmap) } + log.Printf("Located networkmapper configuration file using Player: %s", pathNetmap) - fd, err := os.Open(pathNetmap) - if err != nil { - return nil, err - } - defer fd.Close() - - return ReadNetworkMap(fd) + return ReadNetmapConfig(pathNetmap) } return nil } diff --git a/builder/vmware/common/driver_workstation9.go b/builder/vmware/common/driver_workstation9.go index 25b4ddd2c..8186ac83f 100644 --- a/builder/vmware/common/driver_workstation9.go +++ b/builder/vmware/common/driver_workstation9.go @@ -162,14 +162,9 @@ func (d *Workstation9Driver) Verify() error { if _, err := os.Stat(pathNetmap); err != nil { return nil, fmt.Errorf("Could not find netmap conf file: %s", pathNetmap) } + log.Printf("Located networkmapper configuration file using Workstation: %s", pathNetmap) - fd, err := os.Open(pathNetmap) - if err != nil { - return nil, err - } - defer fd.Close() - - return ReadNetworkMap(fd) + return ReadNetmapConfig(pathNetmap) } return nil } From 6e176f97a0dfb6666023a36c2549f9f8d728a57a Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Thu, 29 Mar 2018 13:06:41 -0500 Subject: [PATCH 2/4] Added logs to all of the VMware drivers that emits each detected network device that gets enumerated for a network. --- builder/vmware/common/driver.go | 19 +++++++++++++++++++ builder/vmware/common/driver_fusion5.go | 2 ++ builder/vmware/common/driver_fusion6.go | 1 + 3 files changed, 22 insertions(+) diff --git a/builder/vmware/common/driver.go b/builder/vmware/common/driver.go index 47dc6e8b6..fb69b015d 100644 --- a/builder/vmware/common/driver.go +++ b/builder/vmware/common/driver.go @@ -296,6 +296,7 @@ func (d *VmwareDriver) GuestAddress(state multistep.StateBag) (string, error) { return "", errors.New("couldn't find MAC address in VMX") } } + log.Printf("GuestAddress: Found MAC address in VMX: %s", macAddress) res, err := net.ParseMAC(macAddress) if err != nil { @@ -317,6 +318,11 @@ func (d *VmwareDriver) GuestIP(state multistep.StateBag) (string, error) { network := state.Get("vmnetwork").(string) devices, err := netmap.NameIntoDevices(network) + // log them to see what was detected + for _, device := range devices { + log.Printf("GuestIP(%s): Discovered device: %s", network, device) + } + // we were unable to find the device, maybe it's a custom one... // so, check to see if it's in the .vmx configuration if err != nil || network == "custom" { @@ -332,6 +338,7 @@ func (d *VmwareDriver) GuestIP(state multistep.StateBag) (string, error) { if err != nil { return "", err } + log.Printf("GuestIP(%s): Discovered custom device: %s", network, device) } // figure out our MAC address for looking up the guest address @@ -415,6 +422,11 @@ func (d *VmwareDriver) HostAddress(state multistep.StateBag) (string, error) { network := state.Get("vmnetwork").(string) devices, err := netmap.NameIntoDevices(network) + // log them to see what was detected + for _, device := range devices { + log.Printf("HostAddress(%s): Discovered device: %s", network, device) + } + // we were unable to find the device, maybe it's a custom one... // so, check to see if it's in the .vmx configuration if err != nil || network == "custom" { @@ -430,6 +442,7 @@ func (d *VmwareDriver) HostAddress(state multistep.StateBag) (string, error) { if err != nil { return "", err } + log.Printf("HostAddress(%s): Discovered custom device: %s", network, device) } var lastError error @@ -488,6 +501,11 @@ func (d *VmwareDriver) HostIP(state multistep.StateBag) (string, error) { network := state.Get("vmnetwork").(string) devices, err := netmap.NameIntoDevices(network) + // log them to see what was detected + for _, device := range devices { + log.Printf("HostIP(%s): Discovered device: %s", network, device) + } + // we were unable to find the device, maybe it's a custom one... // so, check to see if it's in the .vmx configuration if err != nil || network == "custom" { @@ -503,6 +521,7 @@ func (d *VmwareDriver) HostIP(state multistep.StateBag) (string, error) { if err != nil { return "", err } + log.Printf("HostIP(%s): Discovered custom device: %s", network, device) } var lastError error diff --git a/builder/vmware/common/driver_fusion5.go b/builder/vmware/common/driver_fusion5.go index 9c81efd4a..bfc7803e7 100644 --- a/builder/vmware/common/driver_fusion5.go +++ b/builder/vmware/common/driver_fusion5.go @@ -3,6 +3,7 @@ package common import ( "errors" "fmt" + "log" "io/ioutil" "os" "os/exec" @@ -157,6 +158,7 @@ func (d *Fusion5Driver) Verify() error { if _, err := os.Stat(pathNetworking); err != nil { return nil, fmt.Errorf("Could not find networking conf file: %s", pathNetworking) } + log.Printf("Located networkmapper configuration file using Fusion5: %s", pathNetworking) fd, err := os.Open(pathNetworking) if err != nil { diff --git a/builder/vmware/common/driver_fusion6.go b/builder/vmware/common/driver_fusion6.go index 1f959d35d..002d4227a 100644 --- a/builder/vmware/common/driver_fusion6.go +++ b/builder/vmware/common/driver_fusion6.go @@ -83,6 +83,7 @@ func (d *Fusion6Driver) Verify() error { if _, err := os.Stat(pathNetworking); err != nil { return nil, fmt.Errorf("Could not find networking conf file: %s", pathNetworking) } + log.Printf("Located networkmapper configuration file using Fusion6: %s", pathNetworking) fd, err := os.Open(pathNetworking) if err != nil { From 7e9699675f45b1b5a241e4821c61d49c24525222 Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Fri, 30 Mar 2018 18:13:02 -0500 Subject: [PATCH 3/4] Modified device matching logs to look more consistent. --- builder/vmware/common/driver.go | 14 +++++++------- builder/vmware/common/driver_fusion5.go | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/builder/vmware/common/driver.go b/builder/vmware/common/driver.go index fb69b015d..8ceb393ff 100644 --- a/builder/vmware/common/driver.go +++ b/builder/vmware/common/driver.go @@ -296,7 +296,7 @@ func (d *VmwareDriver) GuestAddress(state multistep.StateBag) (string, error) { return "", errors.New("couldn't find MAC address in VMX") } } - log.Printf("GuestAddress: Found MAC address in VMX: %s", macAddress) + log.Printf("GuestAddress found MAC address in VMX: %s", macAddress) res, err := net.ParseMAC(macAddress) if err != nil { @@ -320,7 +320,7 @@ func (d *VmwareDriver) GuestIP(state multistep.StateBag) (string, error) { // log them to see what was detected for _, device := range devices { - log.Printf("GuestIP(%s): Discovered device: %s", network, device) + log.Printf("GuestIP discovered device matching %s: %s", network, device) } // we were unable to find the device, maybe it's a custom one... @@ -338,7 +338,7 @@ func (d *VmwareDriver) GuestIP(state multistep.StateBag) (string, error) { if err != nil { return "", err } - log.Printf("GuestIP(%s): Discovered custom device: %s", network, device) + log.Printf("GuestIP discovered custom device matching %s: %s", network, device) } // figure out our MAC address for looking up the guest address @@ -424,7 +424,7 @@ func (d *VmwareDriver) HostAddress(state multistep.StateBag) (string, error) { // log them to see what was detected for _, device := range devices { - log.Printf("HostAddress(%s): Discovered device: %s", network, device) + log.Printf("HostAddress discovered device matching %s: %s", network, device) } // we were unable to find the device, maybe it's a custom one... @@ -442,7 +442,7 @@ func (d *VmwareDriver) HostAddress(state multistep.StateBag) (string, error) { if err != nil { return "", err } - log.Printf("HostAddress(%s): Discovered custom device: %s", network, device) + log.Printf("HostAddress discovered custom device matching %s: %s", network, device) } var lastError error @@ -503,7 +503,7 @@ func (d *VmwareDriver) HostIP(state multistep.StateBag) (string, error) { // log them to see what was detected for _, device := range devices { - log.Printf("HostIP(%s): Discovered device: %s", network, device) + log.Printf("HostIP discovered device matching %s: %s", network, device) } // we were unable to find the device, maybe it's a custom one... @@ -521,7 +521,7 @@ func (d *VmwareDriver) HostIP(state multistep.StateBag) (string, error) { if err != nil { return "", err } - log.Printf("HostIP(%s): Discovered custom device: %s", network, device) + log.Printf("HostIP discovered custom device matching %s: %s", network, device) } var lastError error diff --git a/builder/vmware/common/driver_fusion5.go b/builder/vmware/common/driver_fusion5.go index bfc7803e7..63211f99a 100644 --- a/builder/vmware/common/driver_fusion5.go +++ b/builder/vmware/common/driver_fusion5.go @@ -3,8 +3,8 @@ package common import ( "errors" "fmt" - "log" "io/ioutil" + "log" "os" "os/exec" "path/filepath" From 2c2904c0958be0dfb9ef800480685dcf01a3be9d Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Fri, 30 Mar 2018 18:19:25 -0500 Subject: [PATCH 4/4] 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 {