diff --git a/builder/vmware/common/driver_player5.go b/builder/vmware/common/driver_player5.go index 617fece72..f107b9e03 100644 --- a/builder/vmware/common/driver_player5.go +++ b/builder/vmware/common/driver_player5.go @@ -204,12 +204,32 @@ 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) + + // 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) + } + + // 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 } - log.Printf("Located networkmapper configuration file using Player: %s", pathNetmap) + defer fd.Close() - return ReadNetmapConfig(pathNetmap) + // 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 4f34ab669..dd1c40993 100644 --- a/builder/vmware/common/driver_workstation9.go +++ b/builder/vmware/common/driver_workstation9.go @@ -165,12 +165,32 @@ 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) + + // 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) + } + + // 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 } - log.Printf("Located networkmapper configuration file using Workstation: %s", pathNetmap) + defer fd.Close() - return ReadNetmapConfig(pathNetmap) + // Then we pass the handle to the networking configuration parser. + return ReadNetworkingConfig(fd) } return nil }