mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 07:11:13 +02:00
Use pyupgrade with --py36-plus param.
This commit is contained in:
1 parent
a9eb035b7d
commit
f928738bd5
235 files changed
+1501
-1638
No files matched your search
@@ -63,7 +63,7 @@ class GNS3VM:
|
||||
download_url = "https://github.com/GNS3/gns3-gui/releases/download/v{version}/GNS3.VM.VMware.Workstation.{version}.zip".format(version=__version__)
|
||||
vmware_info = {
|
||||
"engine_id": "vmware",
|
||||
"description": 'VMware is the recommended choice for best performances.<br>The GNS3 VM can be <a href="{}">downloaded here</a>.'.format(download_url),
|
||||
"description": f'VMware is the recommended choice for best performances.<br>The GNS3 VM can be <a href="{download_url}">downloaded here</a>.',
|
||||
"support_when_exit": True,
|
||||
"support_headless": True,
|
||||
"support_ram": True
|
||||
@@ -77,7 +77,7 @@ class GNS3VM:
|
||||
hyperv_info = {
|
||||
"engine_id": "hyper-v",
|
||||
"name": "Hyper-V",
|
||||
"description": 'Hyper-V support (Windows 10/Server 2016 and above). Nested virtualization must be supported and enabled (Intel processor only)<br>The GNS3 VM can be <a href="{}">downloaded here</a>'.format(download_url),
|
||||
"description": f'Hyper-V support (Windows 10/Server 2016 and above). Nested virtualization must be supported and enabled (Intel processor only)<br>The GNS3 VM can be <a href="{download_url}">downloaded here</a>',
|
||||
"support_when_exit": True,
|
||||
"support_headless": False,
|
||||
"support_ram": True
|
||||
@@ -87,7 +87,7 @@ class GNS3VM:
|
||||
virtualbox_info = {
|
||||
"engine_id": "virtualbox",
|
||||
"name": "VirtualBox",
|
||||
"description": 'VirtualBox support. Nested virtualization for both Intel and AMD processors is supported since version 6.1<br>The GNS3 VM can be <a href="{}">downloaded here</a>'.format(download_url),
|
||||
"description": f'VirtualBox support. Nested virtualization for both Intel and AMD processors is supported since version 6.1<br>The GNS3 VM can be <a href="{download_url}">downloaded here</a>',
|
||||
"support_when_exit": True,
|
||||
"support_headless": True,
|
||||
"support_ram": True
|
||||
@@ -246,7 +246,7 @@ class GNS3VM:
|
||||
elif engine == "remote":
|
||||
self._engines["remote"] = RemoteGNS3VM(self._controller)
|
||||
return self._engines["remote"]
|
||||
raise NotImplementedError("The engine {} for the GNS3 VM is not supported".format(engine))
|
||||
raise NotImplementedError(f"The engine {engine} for the GNS3 VM is not supported")
|
||||
|
||||
def __json__(self):
|
||||
return self._settings
|
||||
@@ -281,14 +281,14 @@ class GNS3VM:
|
||||
# User will receive the error later when they will try to use the node
|
||||
try:
|
||||
compute = await self._controller.add_compute(compute_id="vm",
|
||||
name="GNS3 VM ({})".format(self.current_engine().vmname),
|
||||
name=f"GNS3 VM ({self.current_engine().vmname})",
|
||||
host=None,
|
||||
force=True)
|
||||
compute.set_last_error(str(e))
|
||||
|
||||
except ControllerError:
|
||||
pass
|
||||
log.error("Cannot start the GNS3 VM: {}".format(e))
|
||||
log.error(f"Cannot start the GNS3 VM: {e}")
|
||||
|
||||
async def exit_vm(self):
|
||||
|
||||
@@ -319,7 +319,7 @@ class GNS3VM:
|
||||
engine.headless = self._settings["headless"]
|
||||
engine.port = self._settings["port"]
|
||||
compute = await self._controller.add_compute(compute_id="vm",
|
||||
name="GNS3 VM is starting ({})".format(engine.vmname),
|
||||
name=f"GNS3 VM is starting ({engine.vmname})",
|
||||
host=None,
|
||||
force=True,
|
||||
connect=False)
|
||||
@@ -328,12 +328,12 @@ class GNS3VM:
|
||||
await engine.start()
|
||||
except Exception as e:
|
||||
await self._controller.delete_compute("vm")
|
||||
log.error("Cannot start the GNS3 VM: {}".format(str(e)))
|
||||
await compute.update(name="GNS3 VM ({})".format(engine.vmname))
|
||||
log.error(f"Cannot start the GNS3 VM: {str(e)}")
|
||||
await compute.update(name=f"GNS3 VM ({engine.vmname})")
|
||||
compute.set_last_error(str(e))
|
||||
raise e
|
||||
await compute.connect() # we can connect now that the VM has started
|
||||
await compute.update(name="GNS3 VM ({})".format(engine.vmname),
|
||||
await compute.update(name=f"GNS3 VM ({engine.vmname})",
|
||||
protocol=self.protocol,
|
||||
host=self.ip_address,
|
||||
port=self.port,
|
||||
@@ -357,7 +357,7 @@ class GNS3VM:
|
||||
vm_interface_netmask = interface["netmask"]
|
||||
break
|
||||
if vm_interface_netmask:
|
||||
vm_network = ipaddress.ip_interface("{}/{}".format(compute.host_ip, vm_interface_netmask)).network
|
||||
vm_network = ipaddress.ip_interface(f"{compute.host_ip}/{vm_interface_netmask}").network
|
||||
for compute_id in self._controller.computes:
|
||||
if compute_id == "local":
|
||||
compute = self._controller.get_compute(compute_id)
|
||||
@@ -368,7 +368,7 @@ class GNS3VM:
|
||||
netmask = interface["netmask"]
|
||||
break
|
||||
if netmask:
|
||||
compute_network = ipaddress.ip_interface("{}/{}".format(compute.host_ip, netmask)).network
|
||||
compute_network = ipaddress.ip_interface(f"{compute.host_ip}/{netmask}").network
|
||||
if vm_network.compare_networks(compute_network) != 0:
|
||||
msg = "The GNS3 VM (IP={}, NETWORK={}) is not on the same network as the {} server (IP={}, NETWORK={}), please make sure the local server binding is in the same network as the GNS3 VM".format(self.ip_address,
|
||||
vm_network,
|
||||
@@ -377,9 +377,9 @@ class GNS3VM:
|
||||
compute_network)
|
||||
self._controller.notification.controller_emit("log.warning", {"message": msg})
|
||||
except ComputeError as e:
|
||||
log.warning("Could not check the VM is in the same subnet as the local server: {}".format(e))
|
||||
log.warning(f"Could not check the VM is in the same subnet as the local server: {e}")
|
||||
except ControllerError as e:
|
||||
log.warning("Could not check the VM is in the same subnet as the local server: {}".format(e))
|
||||
log.warning(f"Could not check the VM is in the same subnet as the local server: {e}")
|
||||
|
||||
@locking
|
||||
async def _suspend(self):
|
||||
|
||||
@@ -26,4 +26,4 @@ class GNS3VMError(Exception):
|
||||
return self._message
|
||||
|
||||
def __str__(self):
|
||||
return "GNS3VM: {}".format(self._message)
|
||||
return f"GNS3VM: {self._message}"
|
||||
@@ -55,7 +55,7 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
raise GNS3VMError("Hyper-V is only supported on Windows")
|
||||
|
||||
if sys.getwindowsversion().platform_version[0] < 10:
|
||||
raise GNS3VMError("Windows 10/Windows Server 2016 or a later version is required to run Hyper-V with nested virtualization enabled (version {} detected)".format(sys.getwindowsversion().platform_version[0]))
|
||||
raise GNS3VMError(f"Windows 10/Windows Server 2016 or a later version is required to run Hyper-V with nested virtualization enabled (version {sys.getwindowsversion().platform_version[0]} detected)")
|
||||
|
||||
is_windows_10 = sys.getwindowsversion().platform_version[0] == 10 and sys.getwindowsversion().platform_version[1] == 0
|
||||
|
||||
@@ -69,7 +69,7 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
self._wmi = wmi
|
||||
conn = self._wmi.WMI()
|
||||
except self._wmi.x_wmi as e:
|
||||
raise GNS3VMError("Could not connect to WMI: {}".format(e))
|
||||
raise GNS3VMError(f"Could not connect to WMI: {e}")
|
||||
|
||||
if not conn.Win32_ComputerSystem()[0].HypervisorPresent:
|
||||
raise GNS3VMError("Hyper-V is not installed or activated")
|
||||
@@ -95,7 +95,7 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
try:
|
||||
self._conn = self._wmi.WMI(namespace=r"root\virtualization\v2")
|
||||
except self._wmi.x_wmi as e:
|
||||
raise GNS3VMError("Could not connect to WMI: {}".format(e))
|
||||
raise GNS3VMError(f"Could not connect to WMI: {e}")
|
||||
|
||||
if not self._conn.Msvm_VirtualSystemManagementService():
|
||||
raise GNS3VMError("The Windows account running GNS3 does not have the required permissions for Hyper-V")
|
||||
@@ -114,7 +114,7 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
if nb_vms == 0:
|
||||
return None
|
||||
elif nb_vms > 1:
|
||||
raise GNS3VMError("Duplicate VM name found for {}".format(vm_name))
|
||||
raise GNS3VMError(f"Duplicate VM name found for {vm_name}")
|
||||
else:
|
||||
return vms[0]
|
||||
|
||||
@@ -158,7 +158,7 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
|
||||
available_vcpus = psutil.cpu_count(logical=False)
|
||||
if vcpus > available_vcpus:
|
||||
raise GNS3VMError("You have allocated too many vCPUs for the GNS3 VM! (max available is {} vCPUs)".format(available_vcpus))
|
||||
raise GNS3VMError(f"You have allocated too many vCPUs for the GNS3 VM! (max available is {available_vcpus} vCPUs)")
|
||||
|
||||
try:
|
||||
mem_settings = self._get_vm_resources(self._vm, 'Msvm_MemorySettingData')[0]
|
||||
@@ -175,9 +175,9 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
cpu_settings.ExposeVirtualizationExtensions = True # allow the VM to use nested virtualization
|
||||
self._management.ModifyResourceSettings(ResourceSettings=[cpu_settings.GetText_(1)])
|
||||
|
||||
log.info("GNS3 VM vCPU count set to {} and RAM amount set to {}".format(vcpus, ram))
|
||||
log.info(f"GNS3 VM vCPU count set to {vcpus} and RAM amount set to {ram}")
|
||||
except Exception as e:
|
||||
raise GNS3VMError("Could not set to {} and RAM amount set to {}: {}".format(vcpus, ram, e))
|
||||
raise GNS3VMError(f"Could not set to {vcpus} and RAM amount set to {ram}: {e}")
|
||||
|
||||
async def list(self):
|
||||
"""
|
||||
@@ -193,7 +193,7 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
if vm.ElementName != self._management.SystemName:
|
||||
vms.append({"vmname": vm.ElementName})
|
||||
except self._wmi.x_wmi as e:
|
||||
raise GNS3VMError("Could not list Hyper-V VMs: {}".format(e))
|
||||
raise GNS3VMError(f"Could not list Hyper-V VMs: {e}")
|
||||
return vms
|
||||
|
||||
def _get_wmi_obj(self, path):
|
||||
@@ -211,7 +211,7 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
if not self._vm:
|
||||
self._vm = self._find_vm(self.vmname)
|
||||
if not self._vm:
|
||||
raise GNS3VMError("Could not find Hyper-V VM {}".format(self.vmname))
|
||||
raise GNS3VMError(f"Could not find Hyper-V VM {self.vmname}")
|
||||
job_path, ret = self._vm.RequestStateChange(state)
|
||||
if ret == HyperVGNS3VM._WMI_JOB_STATUS_STARTED:
|
||||
job = self._get_wmi_obj(job_path)
|
||||
@@ -219,9 +219,9 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
await asyncio.sleep(0.1)
|
||||
job = self._get_wmi_obj(job_path)
|
||||
if job.JobState != HyperVGNS3VM._WMI_JOB_STATE_COMPLETED:
|
||||
raise GNS3VMError("Error while changing state: {}".format(job.ErrorSummaryDescription))
|
||||
raise GNS3VMError(f"Error while changing state: {job.ErrorSummaryDescription}")
|
||||
elif ret != 0 or ret != 32775:
|
||||
raise GNS3VMError("Failed to change state to {}".format(state))
|
||||
raise GNS3VMError(f"Failed to change state to {state}")
|
||||
|
||||
async def _is_vm_network_active(self):
|
||||
"""
|
||||
@@ -248,7 +248,7 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
|
||||
self._vm = self._find_vm(self.vmname)
|
||||
if not self._vm:
|
||||
raise GNS3VMError("Could not find Hyper-V VM {}".format(self.vmname))
|
||||
raise GNS3VMError(f"Could not find Hyper-V VM {self.vmname}")
|
||||
|
||||
if not self._is_running():
|
||||
if self.allocate_vcpus_ram:
|
||||
@@ -260,7 +260,7 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
try:
|
||||
await self._set_state(HyperVGNS3VM._HYPERV_VM_STATE_ENABLED)
|
||||
except GNS3VMError as e:
|
||||
raise GNS3VMError("Failed to start the GNS3 VM: {}".format(e))
|
||||
raise GNS3VMError(f"Failed to start the GNS3 VM: {e}")
|
||||
log.info("GNS3 VM has been started")
|
||||
|
||||
# check if VM network is active
|
||||
@@ -296,10 +296,10 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
if guest_ip_address:
|
||||
break
|
||||
elif trial == 0:
|
||||
raise GNS3VMError("Could not find guest IP address for {}".format(self.vmname))
|
||||
raise GNS3VMError(f"Could not find guest IP address for {self.vmname}")
|
||||
await asyncio.sleep(1)
|
||||
self.ip_address = guest_ip_address
|
||||
log.info("GNS3 VM IP address set to {}".format(guest_ip_address))
|
||||
log.info(f"GNS3 VM IP address set to {guest_ip_address}")
|
||||
self.running = True
|
||||
|
||||
async def suspend(self):
|
||||
@@ -310,7 +310,7 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
try:
|
||||
await self._set_state(HyperVGNS3VM._HYPERV_VM_STATE_PAUSED)
|
||||
except GNS3VMError as e:
|
||||
raise GNS3VMError("Failed to suspend the GNS3 VM: {}".format(e))
|
||||
raise GNS3VMError(f"Failed to suspend the GNS3 VM: {e}")
|
||||
log.info("GNS3 VM has been suspended")
|
||||
self.running = False
|
||||
|
||||
@@ -322,6 +322,6 @@ class HyperVGNS3VM(BaseGNS3VM):
|
||||
try:
|
||||
await self._set_state(HyperVGNS3VM._HYPERV_VM_STATE_SHUTDOWN)
|
||||
except GNS3VMError as e:
|
||||
raise GNS3VMError("Failed to stop the GNS3 VM: {}".format(e))
|
||||
raise GNS3VMError(f"Failed to stop the GNS3 VM: {e}")
|
||||
log.info("GNS3 VM has been stopped")
|
||||
self.running = False
|
||||
@@ -58,7 +58,7 @@ class RemoteGNS3VM(BaseGNS3VM):
|
||||
self.user = compute.user
|
||||
self.password = compute.password
|
||||
return
|
||||
raise GNS3VMError("Can't start the GNS3 VM remote VM {} not found".format(self.vmname))
|
||||
raise GNS3VMError(f"Can't start the GNS3 VM remote VM {self.vmname} not found")
|
||||
|
||||
async def suspend(self):
|
||||
"""
|
||||
|
||||
@@ -50,7 +50,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
result = await self._virtualbox_manager.execute(subcommand, args, timeout)
|
||||
return ("\n".join(result))
|
||||
except VirtualBoxError as e:
|
||||
raise GNS3VMError("Error while executing VBoxManage command: {}".format(e))
|
||||
raise GNS3VMError(f"Error while executing VBoxManage command: {e}")
|
||||
|
||||
async def _get_state(self):
|
||||
"""
|
||||
@@ -90,7 +90,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
if not self._system_properties:
|
||||
await self._get_system_properties()
|
||||
if "API version" not in self._system_properties:
|
||||
raise VirtualBoxError("Can't access to VirtualBox API version:\n{}".format(self._system_properties))
|
||||
raise VirtualBoxError(f"Can't access to VirtualBox API version:\n{self._system_properties}")
|
||||
from cpuinfo import get_cpu_info
|
||||
cpu_info = await wait_run_in_executor(get_cpu_info)
|
||||
vendor_id = cpu_info.get('vendor_id_raw')
|
||||
@@ -101,7 +101,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
if parse_version(self._system_properties["API version"]) < parse_version("6_0"):
|
||||
raise VirtualBoxError("VirtualBox version 6.0 or above is required to run the GNS3 VM with nested virtualization enabled on AMD processors")
|
||||
else:
|
||||
log.warning("Could not determine CPU vendor: {}".format(vendor_id))
|
||||
log.warning(f"Could not determine CPU vendor: {vendor_id}")
|
||||
|
||||
async def _look_for_interface(self, network_backend):
|
||||
"""
|
||||
@@ -134,7 +134,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
for info in result.splitlines():
|
||||
if '=' in info:
|
||||
name, value = info.split('=', 1)
|
||||
if name == "hostonlyadapter{}".format(interface_number):
|
||||
if name == f"hostonlyadapter{interface_number}":
|
||||
return value.strip('"')
|
||||
return None
|
||||
|
||||
@@ -217,7 +217,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
await self._check_requirements()
|
||||
return await self._virtualbox_manager.list_vms()
|
||||
except VirtualBoxError as e:
|
||||
raise GNS3VMError("Could not list VirtualBox VMs: {}".format(str(e)))
|
||||
raise GNS3VMError(f"Could not list VirtualBox VMs: {str(e)}")
|
||||
|
||||
async def start(self):
|
||||
"""
|
||||
@@ -229,15 +229,15 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
# get a NAT interface number
|
||||
nat_interface_number = await self._look_for_interface("nat")
|
||||
if nat_interface_number < 0:
|
||||
raise GNS3VMError('VM "{}" must have a NAT interface configured in order to start'.format(self.vmname))
|
||||
raise GNS3VMError(f'VM "{self.vmname}" must have a NAT interface configured in order to start')
|
||||
|
||||
hostonly_interface_number = await self._look_for_interface("hostonly")
|
||||
if hostonly_interface_number < 0:
|
||||
raise GNS3VMError('VM "{}" must have a host-only interface configured in order to start'.format(self.vmname))
|
||||
raise GNS3VMError(f'VM "{self.vmname}" must have a host-only interface configured in order to start')
|
||||
|
||||
vboxnet = await self._look_for_vboxnet(hostonly_interface_number)
|
||||
if vboxnet is None:
|
||||
raise GNS3VMError('A VirtualBox host-only network could not be found on network adapter {} for "{}"'.format(hostonly_interface_number, self._vmname))
|
||||
raise GNS3VMError(f'A VirtualBox host-only network could not be found on network adapter {hostonly_interface_number} for "{self._vmname}"')
|
||||
|
||||
if not (await self._check_vboxnet_exists(vboxnet)):
|
||||
if sys.platform.startswith("win") and vboxnet == "vboxnet0":
|
||||
@@ -245,7 +245,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
# on Windows. Try to patch this with the first available vboxnet we find.
|
||||
first_available_vboxnet = await self._find_first_available_vboxnet()
|
||||
if first_available_vboxnet is None:
|
||||
raise GNS3VMError('Please add a VirtualBox host-only network with DHCP enabled and attached it to network adapter {} for "{}"'.format(hostonly_interface_number, self._vmname))
|
||||
raise GNS3VMError(f'Please add a VirtualBox host-only network with DHCP enabled and attached it to network adapter {hostonly_interface_number} for "{self._vmname}"')
|
||||
await self.set_hostonly_network(hostonly_interface_number, first_available_vboxnet)
|
||||
vboxnet = first_available_vboxnet
|
||||
else:
|
||||
@@ -254,10 +254,10 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
self._vmname))
|
||||
|
||||
if not (await self._check_dhcp_server(vboxnet)):
|
||||
raise GNS3VMError('DHCP must be enabled on VirtualBox host-only network "{}"'.format(vboxnet))
|
||||
raise GNS3VMError(f'DHCP must be enabled on VirtualBox host-only network "{vboxnet}"')
|
||||
|
||||
vm_state = await self._get_state()
|
||||
log.info('"{}" state is {}'.format(self._vmname, vm_state))
|
||||
log.info(f'"{self._vmname}" state is {vm_state}')
|
||||
|
||||
if vm_state == "poweroff":
|
||||
if self.allocate_vcpus_ram:
|
||||
@@ -285,20 +285,20 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
s.bind((ip_address, 0))
|
||||
api_port = s.getsockname()[1]
|
||||
except OSError as e:
|
||||
raise GNS3VMError("Error while getting random port: {}".format(e))
|
||||
raise GNS3VMError(f"Error while getting random port: {e}")
|
||||
|
||||
if (await self._check_vbox_port_forwarding()):
|
||||
# delete the GNS3VM NAT port forwarding rule if it exists
|
||||
log.info("Removing GNS3VM NAT port forwarding rule from interface {}".format(nat_interface_number))
|
||||
await self._execute("controlvm", [self._vmname, "natpf{}".format(nat_interface_number), "delete", "GNS3VM"])
|
||||
log.info(f"Removing GNS3VM NAT port forwarding rule from interface {nat_interface_number}")
|
||||
await self._execute("controlvm", [self._vmname, f"natpf{nat_interface_number}", "delete", "GNS3VM"])
|
||||
|
||||
# add a GNS3VM NAT port forwarding rule to redirect 127.0.0.1 with random port to the port in the VM
|
||||
log.info("Adding GNS3VM NAT port forwarding rule with port {} to interface {}".format(api_port, nat_interface_number))
|
||||
await self._execute("controlvm", [self._vmname, "natpf{}".format(nat_interface_number),
|
||||
"GNS3VM,tcp,{},{},,{}".format(ip_address, api_port, self.port)])
|
||||
log.info(f"Adding GNS3VM NAT port forwarding rule with port {api_port} to interface {nat_interface_number}")
|
||||
await self._execute("controlvm", [self._vmname, f"natpf{nat_interface_number}",
|
||||
f"GNS3VM,tcp,{ip_address},{api_port},,{self.port}"])
|
||||
|
||||
self.ip_address = await self._get_ip(hostonly_interface_number, api_port)
|
||||
log.info("GNS3 VM has been started with IP {}".format(self.ip_address))
|
||||
log.info(f"GNS3 VM has been started with IP {self.ip_address}")
|
||||
self.running = True
|
||||
|
||||
async def _get_ip(self, hostonly_interface_number, api_port):
|
||||
@@ -329,7 +329,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
pass
|
||||
remaining_try -= 1
|
||||
await asyncio.sleep(1)
|
||||
raise GNS3VMError("Could not find guest IP address for {}".format(self.vmname))
|
||||
raise GNS3VMError(f"Could not find guest IP address for {self.vmname}")
|
||||
|
||||
async def suspend(self):
|
||||
"""
|
||||
@@ -377,7 +377,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
"""
|
||||
|
||||
await self._execute("modifyvm", [self._vmname, "--cpus", str(vcpus)], timeout=3)
|
||||
log.info("GNS3 VM vCPU count set to {}".format(vcpus))
|
||||
log.info(f"GNS3 VM vCPU count set to {vcpus}")
|
||||
|
||||
async def set_ram(self, ram):
|
||||
"""
|
||||
@@ -387,7 +387,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
"""
|
||||
|
||||
await self._execute("modifyvm", [self._vmname, "--memory", str(ram)], timeout=3)
|
||||
log.info("GNS3 VM RAM amount set to {}".format(ram))
|
||||
log.info(f"GNS3 VM RAM amount set to {ram}")
|
||||
|
||||
async def enable_nested_hw_virt(self):
|
||||
"""
|
||||
@@ -405,7 +405,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
:param hostonly_network_name: name of the VirtualBox host-only network
|
||||
"""
|
||||
|
||||
await self._execute("modifyvm", [self._vmname, "--hostonlyadapter{}".format(adapter_number), hostonly_network_name], timeout=3)
|
||||
await self._execute("modifyvm", [self._vmname, f"--hostonlyadapter{adapter_number}", hostonly_network_name], timeout=3)
|
||||
log.info('VirtualBox host-only network "{}" set on network adapter {} for "{}"'.format(hostonly_network_name,
|
||||
adapter_number,
|
||||
self._vmname))
|
||||
@@ -49,7 +49,7 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
result = await self._vmware_manager.execute(subcommand, args, timeout, log_level=log_level)
|
||||
return (''.join(result))
|
||||
except VMwareError as e:
|
||||
raise GNS3VMError("Error while executing VMware command: {}".format(e))
|
||||
raise GNS3VMError(f"Error while executing VMware command: {e}")
|
||||
|
||||
async def _is_running(self):
|
||||
result = await self._vmware_manager.execute("list", [])
|
||||
@@ -67,13 +67,13 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
|
||||
# memory must be a multiple of 4 (VMware requirement)
|
||||
if ram % 4 != 0:
|
||||
raise GNS3VMError("Allocated memory {} for the GNS3 VM must be a multiple of 4".format(ram))
|
||||
raise GNS3VMError(f"Allocated memory {ram} for the GNS3 VM must be a multiple of 4")
|
||||
|
||||
available_vcpus = psutil.cpu_count(logical=True)
|
||||
if not float(vcpus).is_integer():
|
||||
raise GNS3VMError("The allocated vCPUs value is not an integer: {}".format(vcpus))
|
||||
raise GNS3VMError(f"The allocated vCPUs value is not an integer: {vcpus}")
|
||||
if vcpus > available_vcpus:
|
||||
raise GNS3VMError("You have allocated too many vCPUs for the GNS3 VM! (max available is {} vCPUs)".format(available_vcpus))
|
||||
raise GNS3VMError(f"You have allocated too many vCPUs for the GNS3 VM! (max available is {available_vcpus} vCPUs)")
|
||||
|
||||
try:
|
||||
pairs = VMware.parse_vmware_file(self._vmx_path)
|
||||
@@ -84,9 +84,9 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
pairs["cpuid.corespersocket"] = str(cores_per_sockets)
|
||||
pairs["memsize"] = str(ram)
|
||||
VMware.write_vmx_file(self._vmx_path, pairs)
|
||||
log.info("GNS3 VM vCPU count set to {} and RAM amount set to {}".format(vcpus, ram))
|
||||
log.info(f"GNS3 VM vCPU count set to {vcpus} and RAM amount set to {ram}")
|
||||
except OSError as e:
|
||||
raise GNS3VMError('Could not read/write VMware VMX file "{}": {}'.format(self._vmx_path, e))
|
||||
raise GNS3VMError(f'Could not read/write VMware VMX file "{self._vmx_path}": {e}')
|
||||
|
||||
async def _set_extra_options(self):
|
||||
try:
|
||||
@@ -103,13 +103,13 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
if key not in pairs.keys():
|
||||
pairs[key] = value
|
||||
updated = True
|
||||
log.info("GNS3 VM VMX `{}` set to `{}`".format(key, value))
|
||||
log.info(f"GNS3 VM VMX `{key}` set to `{value}`")
|
||||
|
||||
if updated:
|
||||
VMware.write_vmx_file(self._vmx_path, pairs)
|
||||
log.info("GNS3 VM VMX has been updated.")
|
||||
except OSError as e:
|
||||
raise GNS3VMError('Could not read/write VMware VMX file "{}": {}'.format(self._vmx_path, e))
|
||||
raise GNS3VMError(f'Could not read/write VMware VMX file "{self._vmx_path}": {e}')
|
||||
|
||||
async def list(self):
|
||||
"""
|
||||
@@ -119,7 +119,7 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
try:
|
||||
return (await self._vmware_manager.list_vms())
|
||||
except VMwareError as e:
|
||||
raise GNS3VMError("Could not list VMware VMs: {}".format(str(e)))
|
||||
raise GNS3VMError(f"Could not list VMware VMs: {str(e)}")
|
||||
|
||||
async def start(self):
|
||||
"""
|
||||
@@ -134,19 +134,19 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
|
||||
# check we have a valid VMX file path
|
||||
if not self._vmx_path:
|
||||
raise GNS3VMError("VMWare VM {} not found".format(self.vmname))
|
||||
raise GNS3VMError(f"VMWare VM {self.vmname} not found")
|
||||
if not os.path.exists(self._vmx_path):
|
||||
raise GNS3VMError("VMware VMX file {} doesn't exist".format(self._vmx_path))
|
||||
raise GNS3VMError(f"VMware VMX file {self._vmx_path} doesn't exist")
|
||||
|
||||
# check if the VMware guest tools are installed
|
||||
vmware_tools_state = await self._execute("checkToolsState", [self._vmx_path])
|
||||
if vmware_tools_state not in ("installed", "running"):
|
||||
raise GNS3VMError("VMware tools are not installed in {}".format(self.vmname))
|
||||
raise GNS3VMError(f"VMware tools are not installed in {self.vmname}")
|
||||
|
||||
try:
|
||||
running = await self._is_running()
|
||||
except VMwareError as e:
|
||||
raise GNS3VMError("Could not list VMware VMs: {}".format(str(e)))
|
||||
raise GNS3VMError(f"Could not list VMware VMs: {str(e)}")
|
||||
if not running:
|
||||
# set the number of vCPUs and amount of RAM
|
||||
if self.allocate_vcpus_ram:
|
||||
@@ -180,12 +180,12 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
guest_ip_address = await self._execute("getGuestIPAddress", [self._vmx_path, "-wait"], timeout=120)
|
||||
break
|
||||
except GNS3VMError as e:
|
||||
log.debug("{}".format(e))
|
||||
log.debug(f"{e}")
|
||||
await asyncio.sleep(1)
|
||||
if not guest_ip_address:
|
||||
raise GNS3VMError("Could not find guest IP address for {}".format(self.vmname))
|
||||
raise GNS3VMError(f"Could not find guest IP address for {self.vmname}")
|
||||
self.ip_address = guest_ip_address
|
||||
log.info("GNS3 VM IP address set to {}".format(guest_ip_address))
|
||||
log.info(f"GNS3 VM IP address set to {guest_ip_address}")
|
||||
self.running = True
|
||||
|
||||
async def suspend(self):
|
||||
@@ -198,7 +198,7 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
try:
|
||||
await self._execute("suspend", [self._vmx_path])
|
||||
except GNS3VMError as e:
|
||||
log.warning("Error when suspending the VM: {}".format(str(e)))
|
||||
log.warning(f"Error when suspending the VM: {str(e)}")
|
||||
log.info("GNS3 VM has been suspended")
|
||||
self.running = False
|
||||
|
||||
@@ -212,6 +212,6 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
try:
|
||||
await self._execute("stop", [self._vmx_path, "soft"])
|
||||
except GNS3VMError as e:
|
||||
log.warning("Error when stopping the VM: {}".format(str(e)))
|
||||
log.warning(f"Error when stopping the VM: {str(e)}")
|
||||
log.info("GNS3 VM has been stopped")
|
||||
self.running = False
|
||||
Reference in new issue
Block a user