mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
refactor: use explicit conversion in f-strings
This commit is contained in:
32 files changed
+65
-65
No files matched your search
@@ -334,7 +334,7 @@ class GNS3VM:
|
||||
await engine.start()
|
||||
except Exception as e:
|
||||
await self._controller.delete_compute("vm")
|
||||
log.error(f"Cannot start the GNS3 VM: {str(e)}")
|
||||
log.error(f"Cannot start the GNS3 VM: {e!s}")
|
||||
await compute.update(name=f"GNS3 VM ({engine.vmname})")
|
||||
compute.set_last_error(str(e))
|
||||
raise e
|
||||
|
||||
@@ -260,7 +260,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
await self._check_requirements()
|
||||
return await self._virtualbox_manager.list_vms()
|
||||
except VirtualBoxError as e:
|
||||
raise GNS3VMError(f"Could not list VirtualBox VMs: {str(e)}")
|
||||
raise GNS3VMError(f"Could not list VirtualBox VMs: {e!s}")
|
||||
|
||||
async def start(self):
|
||||
"""
|
||||
|
||||
@@ -116,7 +116,7 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
try:
|
||||
return await self._vmware_manager.list_vms()
|
||||
except VMwareError as e:
|
||||
raise GNS3VMError(f"Could not list VMware VMs: {str(e)}")
|
||||
raise GNS3VMError(f"Could not list VMware VMs: {e!s}")
|
||||
|
||||
async def start(self):
|
||||
"""
|
||||
@@ -143,7 +143,7 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
try:
|
||||
running = await self._is_running()
|
||||
except VMwareError as e:
|
||||
raise GNS3VMError(f"Could not list VMware VMs: {str(e)}")
|
||||
raise GNS3VMError(f"Could not list VMware VMs: {e!s}")
|
||||
if not running:
|
||||
# set the number of vCPUs and amount of RAM
|
||||
if self.allocate_vcpus_ram:
|
||||
@@ -197,7 +197,7 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
try:
|
||||
await self._execute("suspend", [self._vmx_path])
|
||||
except GNS3VMError as e:
|
||||
log.warning(f"Error when suspending the VM: {str(e)}")
|
||||
log.warning(f"Error when suspending the VM: {e!s}")
|
||||
log.info("GNS3 VM has been suspended")
|
||||
self.running = False
|
||||
|
||||
@@ -211,6 +211,6 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
try:
|
||||
await self._execute("stop", [self._vmx_path, "soft"])
|
||||
except GNS3VMError as e:
|
||||
log.warning(f"Error when stopping the VM: {str(e)}")
|
||||
log.warning(f"Error when stopping the VM: {e!s}")
|
||||
log.info("GNS3 VM has been stopped")
|
||||
self.running = False
|
||||
@@ -222,7 +222,7 @@ class Link:
|
||||
try:
|
||||
validate_all_filters(new_filters)
|
||||
except FilterValidationError as e:
|
||||
raise ControllerError(f"Invalid packet filter parameters: {str(e)}")
|
||||
raise ControllerError(f"Invalid packet filter parameters: {e!s}")
|
||||
|
||||
if new_filters != self.filters:
|
||||
self._filters = new_filters
|
||||
@@ -483,7 +483,7 @@ class Link:
|
||||
# Re-raise ControllerError to return error to client
|
||||
raise
|
||||
except Exception as e:
|
||||
error_msg = f"Error starting Web Wireshark: {str(e)}"
|
||||
error_msg = f"Error starting Web Wireshark: {e!s}"
|
||||
log.error(error_msg)
|
||||
raise ControllerError(error_msg)
|
||||
finally:
|
||||
@@ -532,7 +532,7 @@ class Link:
|
||||
except ControllerError:
|
||||
raise
|
||||
except Exception as e:
|
||||
error_msg = f"Error restarting Web Wireshark: {str(e)}"
|
||||
error_msg = f"Error restarting Web Wireshark: {e!s}"
|
||||
log.error(error_msg)
|
||||
raise ControllerError(error_msg)
|
||||
finally:
|
||||
|
||||
@@ -1050,7 +1050,7 @@ class Node:
|
||||
with open(image, "rb") as f:
|
||||
await self._compute.post(f"/{self._node_type}/images/{os.path.basename(img)}", data=f, timeout=None)
|
||||
except OSError as e:
|
||||
raise ControllerError(f"Can't upload {image}: {str(e)}")
|
||||
raise ControllerError(f"Can't upload {image}: {e!s}")
|
||||
self.project.emit_notification("log.info", {"message": f"Upload finished for {img}"})
|
||||
return True
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class StandardPortFactory:
|
||||
**cls._generate_replacement(interface_number, segment_number),
|
||||
)
|
||||
except (IndexError, ValueError, KeyError) as e:
|
||||
raise ControllerError(f"Invalid port name format {port_name_format}: {str(e)}")
|
||||
raise ControllerError(f"Invalid port name format {port_name_format}: {e!s}")
|
||||
|
||||
port_name = custom_adapter_settings.get("port_name", port_name)
|
||||
port = PortFactory(port_name, segment_number, adapter_number, port_number, "ethernet")
|
||||
|
||||
@@ -1731,7 +1731,7 @@ class Project:
|
||||
)
|
||||
shutil.rmtree(self.path)
|
||||
except OSError as e:
|
||||
raise ControllerError(f"Cannot delete project directory {self.path}: {str(e)}")
|
||||
raise ControllerError(f"Cannot delete project directory {self.path}: {e!s}")
|
||||
self.emit_controller_notification("project.deleted", self.asdict())
|
||||
|
||||
def _get_disconnected_computes(self):
|
||||
@@ -2081,7 +2081,7 @@ class Project:
|
||||
else:
|
||||
log.info("Fast duplication failed, fallback to normal duplication")
|
||||
except Exception as e:
|
||||
raise ControllerError(f"Cannot duplicate project: {str(e)}")
|
||||
raise ControllerError(f"Cannot duplicate project: {e!s}")
|
||||
|
||||
try:
|
||||
begin = time.time()
|
||||
@@ -2119,7 +2119,7 @@ class Project:
|
||||
|
||||
log.info(f"Project '{project.name}' duplicated in {time.time() - begin:.4f} seconds")
|
||||
except (ValueError, OSError, UnicodeEncodeError) as e:
|
||||
raise ControllerError(f"Cannot duplicate project: {str(e)}")
|
||||
raise ControllerError(f"Cannot duplicate project: {e!s}")
|
||||
|
||||
if previous_status == "closed":
|
||||
await self.close()
|
||||
|
||||
@@ -139,7 +139,7 @@ def load_topology(path):
|
||||
with open(path, encoding="utf-8") as f:
|
||||
topo = json.load(f)
|
||||
except (OSError, UnicodeDecodeError, ValueError) as e:
|
||||
raise ControllerError(f"Could not load topology {path}: {str(e)}")
|
||||
raise ControllerError(f"Could not load topology {path}: {e!s}")
|
||||
|
||||
if topo.get("revision", 0) > GNS3_FILE_FORMAT_REVISION:
|
||||
raise ControllerError(
|
||||
@@ -154,7 +154,7 @@ def load_topology(path):
|
||||
try:
|
||||
shutil.copy(path, path + ".backup{}".format(topo.get("revision", 0)))
|
||||
except OSError as e:
|
||||
raise ControllerError(f"Can't write backup of the topology {path}: {str(e)}")
|
||||
raise ControllerError(f"Can't write backup of the topology {path}: {e!s}")
|
||||
changed = True
|
||||
# update the version because we converted the topology
|
||||
topo["version"] = __version__
|
||||
@@ -210,7 +210,7 @@ def load_topology(path):
|
||||
with open(path, "w+", encoding="utf-8") as f:
|
||||
json.dump(topo, f, indent=4, sort_keys=True)
|
||||
except OSError as e:
|
||||
raise ControllerError(f"Can't write the topology {path}: {str(e)}")
|
||||
raise ControllerError(f"Can't write the topology {path}: {e!s}")
|
||||
return topo
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ def _convert_2_0_0_beta_2(topo, topo_path):
|
||||
for path in glob.glob(os.path.join(glob.escape(dynamips_dir), "configs", f"i{dynamips_id}_*")):
|
||||
shutil.move(path, os.path.join(node_dir, "configs", os.path.basename(path)))
|
||||
except OSError as e:
|
||||
raise ControllerError(f"Can't convert project {topo_path}: {str(e)}")
|
||||
raise ControllerError(f"Can't convert project {topo_path}: {e!s}")
|
||||
return topo
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user