From 9b1d31cee7c5378e6ebe40c3217410f69413d876 Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Tue, 5 Jan 2021 11:18:21 -0600 Subject: [PATCH 1/2] Added a fallback to the vmware builder when trying to determine the networkmapping configuration. Some instances of VMWare will not generate the networkmapping configuration (netmap.conf) at the time of installation. To deal with this issue, we check for the networkmapping file first, and then fallback to the networking file which also might exist and contain the interface information that we require. This fixes issue #10009. --- builder/vmware/common/driver_player5.go | 23 +++++++++++++++--- builder/vmware/common/driver_workstation9.go | 25 ++++++++++++++++---- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/builder/vmware/common/driver_player5.go b/builder/vmware/common/driver_player5.go index 4ce3b5c7a..0abfa9c53 100644 --- a/builder/vmware/common/driver_player5.go +++ b/builder/vmware/common/driver_player5.go @@ -205,11 +205,28 @@ func (d *Player5Driver) Verify() error { d.VmwareDriver.NetworkMapper = func() (NetworkNameMapper, error) { pathNetmap := playerNetmapConfPath() 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) + return ReadNetmapConfig(pathNetmap) } - log.Printf("Located networkmapper configuration file using Player: %s", pathNetmap) - return ReadNetmapConfig(pathNetmap) + // If we weren't able to find the networkmapper configuration file, then fall back + // to the networking file which might also be in the configuration directory. + libpath, _ := playerVMwareRoot() + pathNetworking := filepath.Join(libpath, "networking") + if _, err := os.Stat(pathNetworking); err != nil { + return nil, fmt.Errorf("Could not determine network mappings from files in path: %s", libpath) + } + + // We were able to successfully stat the file.. So, now we can open a handle to it. + log.Printf("Located networking configuration file using Player: %s", pathNetworking) + fd, err := os.Open(pathNetworking) + if err != nil { + return nil, err + } + defer fd.Close() + + // Then we pass the handle to the networking configuration parser. + return ReadNetworkingConfig(fd) } return nil } diff --git a/builder/vmware/common/driver_workstation9.go b/builder/vmware/common/driver_workstation9.go index a64543b2e..5637b7fa5 100644 --- a/builder/vmware/common/driver_workstation9.go +++ b/builder/vmware/common/driver_workstation9.go @@ -165,12 +165,29 @@ func (d *Workstation9Driver) Verify() error { d.VmwareDriver.NetworkMapper = func() (NetworkNameMapper, error) { pathNetmap := workstationNetmapConfPath() - if _, err := os.Stat(pathNetmap); err != nil { - return nil, fmt.Errorf("Could not find netmap conf file: %s", pathNetmap) + if _, err := os.Stat(pathNetmap); err == nil { + log.Printf("Located networkmapper configuration file using Workstation: %s", pathNetmap) + return ReadNetmapConfig(pathNetmap) } - log.Printf("Located networkmapper configuration file using Workstation: %s", pathNetmap) - return ReadNetmapConfig(pathNetmap) + // If we weren't able to find the networkmapper configuration file, then fall back + // to the networking file which might also be in the configuration directory. + libpath, _ := workstationVMwareRoot() + pathNetworking := filepath.Join(libpath, "networking") + if _, err := os.Stat(pathNetworking); err != nil { + return nil, fmt.Errorf("Could not determine network mappings from files in path: %s", libpath) + } + + // We were able to successfully stat the file.. So, now we can open a handle to it. + log.Printf("Located networking configuration file using Workstation: %s", pathNetworking) + fd, err := os.Open(pathNetworking) + if err != nil { + return nil, err + } + defer fd.Close() + + // Then we pass the handle to the networking configuration parser. + return ReadNetworkingConfig(fd) } return nil } From c7545c37dd504b2baac35616fcf936c71e7f9a64 Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Sun, 21 Feb 2021 05:32:30 -0600 Subject: [PATCH 2/2] Fixed an issue identified by @SwampDragons when checking if the networkmapper configuration file exists. --- builder/vmware/common/driver_player5.go | 5 ++++- builder/vmware/common/driver_workstation9.go | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/builder/vmware/common/driver_player5.go b/builder/vmware/common/driver_player5.go index 0abfa9c53..7081b7a8a 100644 --- a/builder/vmware/common/driver_player5.go +++ b/builder/vmware/common/driver_player5.go @@ -204,7 +204,10 @@ func (d *Player5Driver) Verify() error { d.VmwareDriver.NetworkMapper = func() (NetworkNameMapper, error) { pathNetmap := playerNetmapConfPath() - if _, err := os.Stat(pathNetmap); err != nil { + + // If we were able to find the file (no error), then we can proceed with reading + // the networkmapper configuration. + if _, err := os.Stat(pathNetmap); err == nil { log.Printf("Located networkmapper configuration file using Player: %s", pathNetmap) return ReadNetmapConfig(pathNetmap) } diff --git a/builder/vmware/common/driver_workstation9.go b/builder/vmware/common/driver_workstation9.go index 5637b7fa5..cf272ac2f 100644 --- a/builder/vmware/common/driver_workstation9.go +++ b/builder/vmware/common/driver_workstation9.go @@ -165,6 +165,9 @@ func (d *Workstation9Driver) Verify() error { d.VmwareDriver.NetworkMapper = func() (NetworkNameMapper, error) { pathNetmap := workstationNetmapConfPath() + + // Check that the file for the networkmapper configuration exists. If there's no + // error, then the file exists and we can proceed to read the configuration out of it. if _, err := os.Stat(pathNetmap); err == nil { log.Printf("Located networkmapper configuration file using Workstation: %s", pathNetmap) return ReadNetmapConfig(pathNetmap)