Merge branch '2.2' into 3.0

# Conflicts:
#	README.md
#	gns3server/compute/base_node.py
#	gns3server/compute/dynamips/__init__.py
#	gns3server/compute/dynamips/hypervisor.py
#	gns3server/compute/qemu/__init__.py
#	gns3server/compute/qemu/qemu_vm.py
#	gns3server/controller/__init__.py
#	gns3server/crash_report.py
#	gns3server/handlers/api/controller/node_handler.py
#	gns3server/schemas/qemu_template.py
#	gns3server/static/web-ui/index.html
#	gns3server/static/web-ui/main.11410ae4eaf4d4c08cd0.js
#	gns3server/version.py
#	requirements.txt
This commit is contained in:
grossmj committed 2023-03-17 17:44:32 +10:00
commit 267c4cbbbb
175 files changed
+702 -287

No files matched your search

+8 -5
View File
@@ -527,14 +527,17 @@ class BaseNode:
if data:
await websocket.send_bytes(data)
# keep forwarding WebSocket data in both direction
done, pending = await asyncio.wait(
[ws_forward(telnet_writer), telnet_forward(telnet_reader)], return_when=asyncio.FIRST_COMPLETED
)
# keep forwarding websocket data in both direction
if sys.version_info >= (3, 11, 0):
# Starting with Python 3.11, passing coroutine objects to wait() directly is forbidden.
aws = [asyncio.create_task(ws_forward(telnet_writer)), asyncio.create_task(telnet_forward(telnet_reader))]
else:
aws = [ws_forward(telnet_writer), telnet_forward(telnet_reader)]
done, pending = await asyncio.wait(aws, return_when=asyncio.FIRST_COMPLETED)
for task in done:
if task.exception():
log.warning(f"Exception while forwarding WebSocket data to Telnet server {task.exception()}")
for task in pending:
task.cancel()
+32 -10
View File
@@ -26,13 +26,14 @@ import time
import asyncio
import tempfile
import logging
import subprocess
import glob
import re
log = logging.getLogger(__name__)
from gns3server.utils.interfaces import interfaces, is_interface_up
from gns3server.utils.asyncio import wait_run_in_executor
from gns3server.utils.asyncio import wait_run_in_executor, subprocess_check_output
from gns3server.utils import parse_version
from uuid import uuid4
from ..base_manager import BaseManager
@@ -263,6 +264,25 @@ class Dynamips(BaseManager):
self._dynamips_path = dynamips_path
return dynamips_path
@staticmethod
async def dynamips_version(dynamips_path):
"""
Gets the Dynamips version
:param dynamips_path: path to Dynamips executable.
"""
try:
output = await subprocess_check_output(dynamips_path, "-P", "none")
match = re.search(r"Cisco Router Simulation Platform \(version\s+([\d.]+)", output)
if match:
version = match.group(1)
return version
else:
raise DynamipsError("Could not determine the Dynamips version for {}".format(dynamips_path))
except (OSError, subprocess.SubprocessError) as e:
raise DynamipsError("Error while looking for the Dynamips version: {}".format(e))
async def start_new_hypervisor(self, working_dir=None):
"""
Creates a new Dynamips process and start it.
@@ -278,13 +298,20 @@ class Dynamips(BaseManager):
if not working_dir:
working_dir = tempfile.gettempdir()
server_host = self.config.settings.Server.host
bind_console_host = False
dynamips_version = await self.dynamips_version(self.dynamips_path)
if parse_version(dynamips_version) < parse_version('0.2.11'):
raise DynamipsError("Dynamips version must be >= 0.2.11, detected version is {}".format(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
server_host = "127.0.0.1"
else:
server_host = self.config.settings.Server.host
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)
@@ -301,17 +328,12 @@ class Dynamips(BaseManager):
raise DynamipsError(f"Could not find free port for the Dynamips hypervisor: {e}")
port_manager = PortManager.instance()
hypervisor = Hypervisor(self._dynamips_path, working_dir, server_host, port, port_manager.console_host)
hypervisor = Hypervisor(self._dynamips_path, working_dir, server_host, port, port_manager.console_host, bind_console_host)
log.info(f"Creating new hypervisor {hypervisor.host}:{hypervisor.port} with working directory {working_dir}")
await hypervisor.start()
log.info(f"Hypervisor {hypervisor.host}:{hypervisor.port} has successfully started")
await hypervisor.connect()
if parse_version(hypervisor.version) < parse_version("0.2.11"):
raise DynamipsError(f"Dynamips version must be >= 0.2.11, detected version is {hypervisor.version}")
if not sys.platform.startswith("win") and parse_version(hypervisor.version) < parse_version('0.2.23'):
raise DynamipsError(f"Dynamips version must be >= 0.2.23 on Linux/macOS, detected version is {hypervisor.version}")
return hypervisor
async def ghost_ios_support(self, vm):
+9 -4
View File
@@ -46,7 +46,7 @@ class Hypervisor(DynamipsHypervisor):
_instance_count = 1
def __init__(self, path, working_dir, host, port, console_host):
def __init__(self, path, working_dir, host, port, console_host, bind_console_host=False):
super().__init__(working_dir, host, port)
@@ -55,6 +55,7 @@ class Hypervisor(DynamipsHypervisor):
Hypervisor._instance_count += 1
self._console_host = console_host
self._bind_console_host = bind_console_host
self._path = path
self._command = []
self._process = None
@@ -196,9 +197,13 @@ class Hypervisor(DynamipsHypervisor):
command = [self._path]
command.extend(["-N1"]) # use instance IDs for filenames
command.extend(["-l", f"dynamips_i{self._id}_log.txt"]) # log file
if not sys.platform.startswith("win"):
command.extend(["-H", f"{self._host}:{self._port}", "--console-binding-addr", self._console_host])
command.extend(["-l", "dynamips_i{}_log.txt".format(self._id)]) # log file
if self._bind_console_host:
# support was added in Dynamips version 0.2.23
command.extend(["-H", "{}:{}".format(self._host, self._port), "--console-binding-addr", self._console_host])
elif self._console_host != "0.0.0.0" and self._console_host != "::":
command.extend(["-H", "{}:{}".format(self._host, self._port)])
else:
command.extend(["-H", str(self._port)])
+49 -2
View File
@@ -193,9 +193,56 @@ class Qemu(BaseManager):
version = match.group(1)
return version
else:
raise QemuError(f"Could not determine the Qemu-img version for {qemu_img_path}")
raise QemuError("Could not determine the Qemu-img version for '{}'".format(qemu_img_path))
except (OSError, subprocess.SubprocessError) as e:
raise QemuError(f"Error while looking for the Qemu-img version: {e}")
raise QemuError("Error while looking for the Qemu-img version: {}".format(e))
@staticmethod
async def get_swtpm_version(swtpm_path):
"""
Gets the swtpm version.
:param swtpm_path: path to swtpm executable.
"""
try:
output = await subprocess_check_output(swtpm_path, "--version")
match = re.search(r"version\s+([\d.]+)", output)
if match:
version = match.group(1)
return version
else:
raise QemuError("Could not determine the swtpm version for '{}'".format(swtpm_path))
except (OSError, subprocess.SubprocessError) as e:
raise QemuError("Error while looking for the swtpm version: {}".format(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, r"{}\InstallProperties".format(product_id))
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):
+12 -5
View File
@@ -255,7 +255,7 @@ class QemuVM(BaseNode):
if qemu_bin == "qemu":
self._platform = "i386"
else:
self._platform = re.sub(r"^qemu-system-(.*)$", r"\1", qemu_bin, re.IGNORECASE)
self._platform = re.sub(r'^qemu-system-(\w+).*$', r'\1', qemu_bin, re.IGNORECASE)
try:
QemuPlatform(self._platform.split(".")[0])
@@ -1136,6 +1136,10 @@ class QemuVM(BaseNode):
# check if there is enough RAM to run
self.check_available_ram(self.ram)
# start swtpm (TPM emulator) first if TPM is enabled
if self._tpm:
await self._start_swtpm()
command = await self._build_command()
command_string = " ".join(shlex.quote(s) for s in command)
try:
@@ -1160,8 +1164,6 @@ class QemuVM(BaseNode):
await self._set_process_priority()
if self._cpu_throttling:
self._set_cpu_throttling()
if self._tpm:
self._start_swtpm()
if "-enable-kvm" in command_string or "-enable-hax" in command_string:
self._hw_virtualization = True
@@ -2276,10 +2278,9 @@ class QemuVM(BaseNode):
options.extend(["-kernel", self._kernel_image.replace(",", ",,")])
if self._kernel_command_line:
options.extend(["-append", self._kernel_command_line])
return options
def _start_swtpm(self):
async def _start_swtpm(self):
"""
Start swtpm (TPM emulator)
"""
@@ -2292,6 +2293,10 @@ class QemuVM(BaseNode):
swtpm = shutil.which("swtpm")
if not swtpm:
raise QemuError("Could not find swtpm (TPM emulator)")
swtpm_version = await self.manager.get_swtpm_version(swtpm)
if swtpm_version and parse_version(swtpm_version) < parse_version("0.8.0"):
# swtpm >= version 0.8.0 is required
raise QemuError("swtpm version 0.8.0 or above must be installed (detected version is {})".format(swtpm_version))
try:
command = [
swtpm,
@@ -2323,6 +2328,8 @@ class QemuVM(BaseNode):
"""
tpm_sock = os.path.join(self.temporary_directory, "swtpm.sock")
if not os.path.exists(tpm_sock):
raise QemuError("swtpm socket file '{}' does not exist".format(tpm_sock))
options = [
"-chardev",
"socket,id=chrtpm,path={}".format(tpm_sock),