mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Fix VMware support on macOS BigSur
This commit is contained in:
1 parent
bfd30f3547
commit
c892cf371b
3 files changed
+62
-11
No files matched your search
@@ -27,6 +27,7 @@ import asyncio
|
||||
import subprocess
|
||||
import logging
|
||||
import codecs
|
||||
import ipaddress
|
||||
|
||||
from collections import OrderedDict
|
||||
from gns3server.utils.interfaces import interfaces
|
||||
@@ -51,6 +52,7 @@ class VMware(BaseManager):
|
||||
self._vmrun_path = None
|
||||
self._host_type = None
|
||||
self._vmnets = []
|
||||
self._vmnets_info = {}
|
||||
self._vmnet_start_range = 2
|
||||
if sys.platform.startswith("win"):
|
||||
self._vmnet_end_range = 19
|
||||
@@ -273,7 +275,7 @@ class VMware(BaseManager):
|
||||
else:
|
||||
# location on Linux
|
||||
vmware_networking_file = "/etc/vmware/networking"
|
||||
vmnet_interfaces = []
|
||||
vmnet_interfaces = {}
|
||||
try:
|
||||
with open(vmware_networking_file, "r", encoding="utf-8") as f:
|
||||
for line in f.read().splitlines():
|
||||
@@ -281,7 +283,20 @@ class VMware(BaseManager):
|
||||
if match:
|
||||
vmnet = "vmnet{}".format(match.group(1))
|
||||
if vmnet not in ("vmnet0", "vmnet1", "vmnet8"):
|
||||
vmnet_interfaces.append(vmnet)
|
||||
vmnet_interfaces[vmnet] = {}
|
||||
with open(vmware_networking_file, "r", encoding="utf-8") as f:
|
||||
for line in f.read().splitlines():
|
||||
match = re.search(r"VNET_([0-9]+)_HOSTONLY_SUBNET\s+(.*)", line)
|
||||
if match:
|
||||
vmnet = "vmnet{}".format(match.group(1))
|
||||
if vmnet in vmnet_interfaces.keys():
|
||||
vmnet_interfaces[vmnet]["subnet"] = match.group(2)
|
||||
match = re.search(r"VNET_([0-9]+)_HOSTONLY_NETMASK\s+(.*)", line)
|
||||
if match:
|
||||
vmnet = "vmnet{}".format(match.group(1))
|
||||
if vmnet in vmnet_interfaces.keys():
|
||||
vmnet_interfaces[vmnet]["netmask"] = match.group(2)
|
||||
|
||||
except OSError as e:
|
||||
raise VMwareError("Cannot open {}: {}".format(vmware_networking_file, e))
|
||||
return vmnet_interfaces
|
||||
@@ -324,6 +339,25 @@ 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 find_bridge_interface(self, vmnet_interface):
|
||||
"""
|
||||
Find the bridge interface that is used for the vmnet interface in VMware.
|
||||
"""
|
||||
|
||||
if vmnet_interface in self._vmnets_info.keys():
|
||||
subnet = self._vmnets_info[vmnet_interface].get("subnet", None)
|
||||
netmask = self._vmnets_info[vmnet_interface].get("netmask", None)
|
||||
if subnet and netmask:
|
||||
for interface in interfaces():
|
||||
try:
|
||||
network = ipaddress.ip_network(f"{subnet}/{netmask}")
|
||||
ip = ipaddress.ip_address(interface["ip_address"])
|
||||
except ValueError:
|
||||
continue
|
||||
if ip in network:
|
||||
return interface["name"]
|
||||
return None
|
||||
|
||||
def refresh_vmnet_list(self, ubridge=True):
|
||||
|
||||
if ubridge:
|
||||
@@ -332,6 +366,8 @@ class VMware(BaseManager):
|
||||
else:
|
||||
vmnet_interfaces = self._get_vmnet_interfaces()
|
||||
|
||||
self._vmnets_info = vmnet_interfaces.copy()
|
||||
vmnet_interfaces = list(vmnet_interfaces.keys())
|
||||
# remove vmnets already in use
|
||||
for vmware_vm in self._nodes.values():
|
||||
for used_vmnet in vmware_vm.vmnets:
|
||||
@@ -734,5 +770,4 @@ class VMware(BaseManager):
|
||||
if __name__ == '__main__':
|
||||
loop = asyncio.get_event_loop()
|
||||
vmware = VMware.instance()
|
||||
print("=> Check version")
|
||||
loop.run_until_complete(asyncio.ensure_future(vmware.check_vmware_version()))
|
||||
Reference in new issue
Block a user