chore: clean up Windows specific code

This commit is contained in:
grossmj committed 2026-10-20 11:51:29 +07:00
1 parent 9e9f1316aa
commit 437f68961b
7 files changed
+16 -177

No files matched your search

+6 -13
View File
@@ -26,7 +26,6 @@ import re
import shutil
import socket
import subprocess
import sys
import tempfile
import time
@@ -253,11 +252,6 @@ class Dynamips(BaseManager):
# look for Dynamips
dynamips_path = self.config.settings.Dynamips.dynamips_path
if not os.path.isabs(dynamips_path):
if sys.platform.startswith("win") and hasattr(sys, "frozen"):
dynamips_dir = os.path.normpath(
os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "dynamips")
)
os.environ["PATH"] = os.pathsep.join(dynamips_dir) + os.pathsep + os.environ.get("PATH", "")
dynamips_path = shutil.which(dynamips_path)
if not dynamips_path:
@@ -311,13 +305,12 @@ class Dynamips(BaseManager):
if parse_version(dynamips_version) < parse_version("0.2.11"):
raise DynamipsError(f"Dynamips version must be >= 0.2.11, detected version is {dynamips_version}")
if not sys.platform.startswith("win"):
# Hypervisor should always listen to 127.0.0.1
# See https://github.com/GNS3/dynamips/issues/62
# This was fixed in Dynamips v0.2.23 which hasn't been built for Windows
if parse_version(dynamips_version) >= parse_version("0.2.23"):
server_host = "127.0.0.1"
bind_console_host = True
# Hypervisor should always listen to 127.0.0.1
# See https://github.com/GNS3/dynamips/issues/62
# This was fixed in Dynamips v0.2.23
if parse_version(dynamips_version) >= parse_version("0.2.23"):
server_host = "127.0.0.1"
bind_console_host = True
try:
info = socket.getaddrinfo(server_host, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
-32
View File
@@ -242,38 +242,6 @@ class Qemu(BaseManager):
except (OSError, subprocess.SubprocessError) as e:
raise QemuError(f"Error while looking for the swtpm version: {e}")
@staticmethod
def get_haxm_windows_version():
"""
Gets the HAXM version number (Windows).
:returns: HAXM version number. Returns None if HAXM is not installed.
"""
assert sys.platform.startswith("win")
import winreg
hkey = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
)
version = None
for index in range(winreg.QueryInfoKey(hkey)[0]):
product_id = winreg.EnumKey(hkey, index)
try:
product_key = winreg.OpenKey(hkey, rf"{product_id}\InstallProperties")
try:
if winreg.QueryValueEx(product_key, "DisplayName")[0].endswith(
"Hardware Accelerated Execution Manager"
):
version = winreg.QueryValueEx(product_key, "DisplayVersion")[0]
break
finally:
winreg.CloseKey(product_key)
except OSError:
continue
winreg.CloseKey(hkey)
return version
@staticmethod
def get_legacy_vm_workdir(legacy_vm_id, name):
"""
+1 -10
View File
@@ -1128,15 +1128,8 @@ class QemuVM(KernelDatapathMixin, BaseNode):
return
try:
if sys.platform.startswith("win") and hasattr(sys, "frozen"):
cpulimit_exec = os.path.join(
os.path.dirname(os.path.abspath(sys.executable)), "cpulimit", "cpulimit.exe"
)
else:
cpulimit_exec = "cpulimit"
command = [
cpulimit_exec,
"cpulimit",
"--lazy",
f"--pid={self._process.pid}",
f"--limit={self._cpu_throttling}",
@@ -2599,8 +2592,6 @@ class QemuVM(KernelDatapathMixin, BaseNode):
Start swtpm (TPM emulator)
"""
if sys.platform.startswith("win"):
raise QemuError("swtpm (TPM emulator) is not supported on Windows")
tpm_dir = os.path.join(self.working_dir, "tpm")
os.makedirs(tpm_dir, exist_ok=True)
tpm_sock = os.path.join(self.temporary_directory, "swtpm.sock")
-3
View File
@@ -162,9 +162,6 @@ class VPCSVM(KernelDatapathMixin, BaseNode):
vpcs_path = self._manager.config.settings.VPCS.vpcs_path
if not os.path.isabs(vpcs_path):
if sys.platform.startswith("win") and hasattr(sys, "frozen"):
vpcs_dir = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "vpcs"))
os.environ["PATH"] = os.pathsep.join(vpcs_dir) + os.pathsep + os.environ.get("PATH", "")
vpcs_path = shutil.which(vpcs_path)
return vpcs_path