mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-20 05:05:14 +02:00
refactor: remove platform-specific code for Darwin and Windows. Clean up Qemu options handling
This commit is contained in:
20 files changed
+77
-532
No files matched your search
@@ -92,10 +92,7 @@ class VMware(BaseManager):
|
||||
# look for vmrun
|
||||
vmrun_path = self.config.settings.VMware.vmrun_path
|
||||
if not vmrun_path:
|
||||
if sys.platform.startswith("darwin"):
|
||||
vmrun_path = "/Applications/VMware Fusion.app/Contents/Library/vmrun"
|
||||
else:
|
||||
vmrun_path = "vmrun"
|
||||
vmrun_path = "vmrun"
|
||||
|
||||
if vmrun_path and not os.path.isabs(vmrun_path):
|
||||
vmrun_path = shutil.which(vmrun_path)
|
||||
@@ -186,14 +183,6 @@ class VMware(BaseManager):
|
||||
Check VMware version
|
||||
"""
|
||||
|
||||
if sys.platform.startswith("darwin"):
|
||||
if not os.path.isdir("/Applications/VMware Fusion.app"):
|
||||
raise VMwareError(
|
||||
"VMware Fusion is not installed in the standard location /Applications/VMware Fusion.app"
|
||||
)
|
||||
self._host_type = "fusion"
|
||||
return # FIXME: no version checking on Mac OS X but we support all versions of fusion
|
||||
|
||||
vmware_path = VMware._get_linux_vmware_binary()
|
||||
if vmware_path is None:
|
||||
raise VMwareError("VMware is not installed (vmware or vmplayer executable could not be found in $PATH)")
|
||||
@@ -223,11 +212,7 @@ class VMware(BaseManager):
|
||||
@staticmethod
|
||||
def _get_vmnet_interfaces():
|
||||
|
||||
if sys.platform.startswith("darwin"):
|
||||
vmware_networking_file = "/Library/Preferences/VMware Fusion/networking"
|
||||
else:
|
||||
# location on Linux
|
||||
vmware_networking_file = "/etc/vmware/networking"
|
||||
vmware_networking_file = "/etc/vmware/networking"
|
||||
vmnet_interfaces = {}
|
||||
try:
|
||||
with open(vmware_networking_file, encoding="utf-8") as f:
|
||||
@@ -620,10 +605,7 @@ class VMware(BaseManager):
|
||||
:returns: path to the inventory file
|
||||
"""
|
||||
|
||||
if sys.platform.startswith("darwin"):
|
||||
return os.path.expanduser("~/Library/Application Support/VMware Fusion/vmInventory")
|
||||
else:
|
||||
return os.path.expanduser("~/.vmware/inventory.vmls")
|
||||
return os.path.expanduser("~/.vmware/inventory.vmls")
|
||||
|
||||
@staticmethod
|
||||
def get_vmware_preferences_path():
|
||||
@@ -633,10 +615,7 @@ class VMware(BaseManager):
|
||||
:returns: path to the preferences file
|
||||
"""
|
||||
|
||||
if sys.platform.startswith("darwin"):
|
||||
return os.path.expanduser("~/Library/Preferences/VMware Fusion/preferences")
|
||||
else:
|
||||
return os.path.expanduser("~/.vmware/preferences")
|
||||
return os.path.expanduser("~/.vmware/preferences")
|
||||
|
||||
@staticmethod
|
||||
def get_vmware_default_vm_paths():
|
||||
@@ -646,10 +625,7 @@ class VMware(BaseManager):
|
||||
:returns: path to the default VM directory
|
||||
"""
|
||||
|
||||
if sys.platform.startswith("darwin"):
|
||||
return [os.path.expanduser("~/Documents/Virtual Machines.localized")]
|
||||
else:
|
||||
return [os.path.expanduser("~/vmware")]
|
||||
return [os.path.expanduser("~/vmware")]
|
||||
|
||||
async def list_vms(self):
|
||||
"""
|
||||
|
||||
@@ -22,7 +22,6 @@ import asyncio
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
import tempfile
|
||||
from collections import OrderedDict
|
||||
|
||||
@@ -260,12 +259,7 @@ class VMwareVM(BaseNode):
|
||||
if self._get_vmx_setting(connected):
|
||||
del self._vmx_pairs[connected]
|
||||
|
||||
use_ubridge = True
|
||||
# use alternative method to find vmnet interfaces on macOS >= 11.0 (BigSur)
|
||||
# because "bridge" interfaces are used instead and they are only created on the VM starts
|
||||
if sys.platform.startswith("darwin") and parse_version(platform.mac_ver()[0]) >= parse_version("11.0.0"):
|
||||
use_ubridge = False
|
||||
self.manager.refresh_vmnet_list(ubridge=use_ubridge)
|
||||
self.manager.refresh_vmnet_list(ubridge=True)
|
||||
# then configure VMware network adapters
|
||||
for adapter_number in range(0, self._adapters):
|
||||
custom_adapter = self._get_custom_adapter_settings(adapter_number)
|
||||
@@ -350,20 +344,7 @@ class VMwareVM(BaseNode):
|
||||
await self._ubridge_send(f"bridge create {vnet}")
|
||||
vmnet_interface = os.path.basename(self._vmx_pairs[vnet])
|
||||
block_host_traffic = self.manager.config.settings.VMware.block_host_traffic
|
||||
|
||||
if sys.platform.startswith("darwin"):
|
||||
if parse_version(platform.mac_ver()[0]) >= parse_version("11.0.0"):
|
||||
# a bridge interface (bridge100, bridge101 etc.) is used instead of a vmnet interface
|
||||
# on macOS >= 11.0 (Big Sur)
|
||||
vmnet_interface = self.manager.find_bridge_interface(vmnet_interface)
|
||||
if not vmnet_interface:
|
||||
raise VMwareError(f"Could not find bridge interface linked with {vmnet_interface}")
|
||||
await self._add_ubridge_ethernet_connection(vnet, vmnet_interface, block_host_traffic)
|
||||
else:
|
||||
# special case on macOS, we cannot bind VMnet interfaces using the libpcap
|
||||
await self._ubridge_send(f'bridge add_nio_fusion_vmnet {vnet} "{vmnet_interface}"')
|
||||
else:
|
||||
await self._add_ubridge_ethernet_connection(vnet, vmnet_interface, block_host_traffic)
|
||||
await self._add_ubridge_ethernet_connection(vnet, vmnet_interface, block_host_traffic)
|
||||
|
||||
if isinstance(nio, NIOUDP):
|
||||
await self._ubridge_send(f"bridge add_nio_udp {vnet} {nio.lport} {nio.rhost} {nio.rport}")
|
||||
|
||||
Reference in new issue
Block a user