mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-13 20:08:55 +00:00
Use custom VMnet interfaces without host adapter when uBridge is not used. Fixes #673.
This commit is contained in:
parent
c5ce6af872
commit
5bcabc705f
@ -359,7 +359,7 @@ class VMwareHandler:
|
||||
def allocate_vmnet(request, response):
|
||||
|
||||
vmware_manager = VMware.instance()
|
||||
vmware_manager.refresh_vmnet_list()
|
||||
vmware_manager.refresh_vmnet_list(ubridge=False)
|
||||
vmnet = vmware_manager.allocate_vmnet()
|
||||
response.set_status(201)
|
||||
response.json({"vmnet": vmnet})
|
||||
|
@ -197,7 +197,52 @@ class VMware(BaseManager):
|
||||
log.error("Error while looking for the VMware version: {}".format(e))
|
||||
|
||||
@staticmethod
|
||||
def get_vmnet_interfaces():
|
||||
def _get_vmnet_interfaces_registry():
|
||||
|
||||
import winreg
|
||||
vmnet_interfaces = []
|
||||
regkey = r"SOFTWARE\Wow6432Node\VMware, Inc.\VMnetLib\VMnetConfig"
|
||||
try:
|
||||
hkey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, regkey)
|
||||
for index in range(winreg.QueryInfoKey(hkey)[0]):
|
||||
vmnet = winreg.EnumKey(hkey, index)
|
||||
hkeyvmnet = winreg.OpenKey(hkey, vmnet)
|
||||
if winreg.QueryInfoKey(hkeyvmnet)[1]:
|
||||
# the vmnet has not been configure if the key has no values
|
||||
vmnet = vmnet.replace("vm", "VM")
|
||||
if vmnet not in ("VMnet1", "VMnet8"):
|
||||
vmnet_interfaces.append(vmnet)
|
||||
winreg.CloseKey(hkeyvmnet)
|
||||
winreg.CloseKey(hkey)
|
||||
except OSError as e:
|
||||
raise VMwareError("Could not read registry key {}: {}".format(regkey, e))
|
||||
return vmnet_interfaces
|
||||
|
||||
@staticmethod
|
||||
def _get_vmnet_interfaces():
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
return VMware._get_vmnet_interfaces_registry()
|
||||
elif sys.platform.startswith("darwin"):
|
||||
vmware_networking_file = "/Library/Preferences/VMware Fusion/networking"
|
||||
else:
|
||||
# location on Linux
|
||||
vmware_networking_file = "/etc/vmware/networking"
|
||||
vmnet_interfaces = []
|
||||
try:
|
||||
with open(vmware_networking_file, "r", encoding="utf-8") as f:
|
||||
for line in f.read().splitlines():
|
||||
match = re.search("VNET_([0-9]+)_VIRTUAL_ADAPTER", line)
|
||||
if match:
|
||||
vmnet = "vmnet{}".format(match.group(1))
|
||||
if vmnet not in ("vmnet1", "vmnet8"):
|
||||
vmnet_interfaces.append(vmnet)
|
||||
except OSError as e:
|
||||
raise VMwareError("Cannot open {}: {}".format(vmware_networking_file, e))
|
||||
return vmnet_interfaces
|
||||
|
||||
@staticmethod
|
||||
def _get_vmnet_interfaces_ubridge():
|
||||
|
||||
vmnet_interfaces = []
|
||||
for interface in interfaces():
|
||||
@ -234,9 +279,13 @@ class VMware(BaseManager):
|
||||
raise VMwareError("No VMnet interface available between vmnet{} and vmnet{}. Go to preferences VMware / Network / Configure to add more interfaces.".format(self._vmnet_start_range, self._vmnet_end_range))
|
||||
return self._vmnets.pop(0)
|
||||
|
||||
def refresh_vmnet_list(self):
|
||||
def refresh_vmnet_list(self, ubridge=True):
|
||||
|
||||
vmnet_interfaces = self.get_vmnet_interfaces()
|
||||
if ubridge:
|
||||
# VMnet host adapters must be present when uBridge is used
|
||||
vmnet_interfaces = self._get_vmnet_interfaces_ubridge()
|
||||
else:
|
||||
vmnet_interfaces = self._get_vmnet_interfaces()
|
||||
|
||||
# remove vmnets already in use
|
||||
for vm in self._vms.values():
|
||||
|
@ -236,7 +236,7 @@ class VMwareVM(BaseVM):
|
||||
# raise VMwareError("Network adapter {} is already associated with VMnet interface {} which is managed by GNS3, please remove".format(adapter_number, vmnet))
|
||||
|
||||
# then configure VMware network adapters
|
||||
self.manager.refresh_vmnet_list()
|
||||
self.manager.refresh_vmnet_list(ubridge=self._use_ubridge)
|
||||
for adapter_number in range(0, self._adapters):
|
||||
|
||||
# add/update the interface
|
||||
|
@ -33,7 +33,7 @@ else:
|
||||
if sys.platform.startswith("win"):
|
||||
DEFAULT_RANGE = [1, 19]
|
||||
else:
|
||||
DEFAULT_RANGE = [10, 100]
|
||||
DEFAULT_RANGE = [10, 99]
|
||||
|
||||
|
||||
def parse_networking_file():
|
||||
|
Loading…
Reference in New Issue
Block a user