refactor: ruff autofixes

This commit is contained in:
Mark Paronyan committed 2026-09-27 15:55:10 +03:00
1 parent 2ac637c662
commit a0450b6bce
455 files changed
+12322 -14762

No files matched your search

+16 -7
View File
@@ -110,7 +110,6 @@ PLATFORMS_DEFAULT_RAM = {
class Dynamips(BaseManager):
_NODE_CLASS = DynamipsFactory
_NODE_TYPE = "dynamips"
_ghost_ios_lock = None
@@ -253,7 +252,9 @@ class Dynamips(BaseManager):
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"))
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)
@@ -305,14 +306,14 @@ class Dynamips(BaseManager):
bind_console_host = False
dynamips_version = await self.dynamips_version(self.dynamips_path)
if parse_version(dynamips_version) < parse_version('0.2.11'):
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
if parse_version(dynamips_version) >= parse_version('0.2.23'):
if parse_version(dynamips_version) >= parse_version("0.2.23"):
server_host = "127.0.0.1"
bind_console_host = True
@@ -331,7 +332,9 @@ 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, bind_console_host)
hypervisor = Hypervisor(
self._dynamips_path, working_dir, server_host, port, port_manager.console_host, bind_console_host
)
log.debug(f"Creating new hypervisor {hypervisor.host}:{hypervisor.port} with working directory {working_dir}")
await hypervisor.start()
@@ -482,7 +485,9 @@ class Dynamips(BaseManager):
if vm.slots[slot_id].removable():
await vm.slot_remove_binding(slot_id)
else:
log.warning(f"Slot {slot_id} on router '{vm.name}' has a non-removable adapter, skipping replacement")
log.warning(
f"Slot {slot_id} on router '{vm.name}' has a non-removable adapter, skipping replacement"
)
continue
if not isinstance(vm.slots[slot_id], type(adapter)):
await vm.slot_add_binding(slot_id, adapter)
@@ -500,7 +505,11 @@ class Dynamips(BaseManager):
wic_name = value
wic = WIC_MATRIX[wic_name]()
try:
if vm.slots[0] and vm.slots[0].wics[wic_slot_id] and not isinstance(vm.slots[0].wics[wic_slot_id], type(wic)):
if (
vm.slots[0]
and vm.slots[0].wics[wic_slot_id]
and not isinstance(vm.slots[0].wics[wic_slot_id], type(wic))
):
await vm.uninstall_wic(wic_slot_id)
if vm.slots[0] and not isinstance(vm.slots[0].wics[wic_slot_id], type(wic)):
await vm.install_wic(wic_slot_id, wic)
@@ -16,7 +16,6 @@
class Adapter:
"""
Base class for adapters.
@@ -18,7 +18,6 @@ from .adapter import Adapter
class C1700_MB_1FE(Adapter):
"""
Integrated 1 port FastEthernet adapter for c1700 platform.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class C1700_MB_WIC1(Adapter):
"""
Fake module to provide a placeholder for slot 1 interfaces when WICs
are inserted into WIC slot 1.
@@ -18,7 +18,6 @@ from .adapter import Adapter
class C2600_MB_1E(Adapter):
"""
Integrated 1 port Ethernet adapter for the c2600 platform.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class C2600_MB_1FE(Adapter):
"""
Integrated 1 port FastEthernet adapter for the c2600 platform.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class C2600_MB_2E(Adapter):
"""
Integrated 2 port Ethernet adapter for the c2600 platform.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class C2600_MB_2FE(Adapter):
"""
Integrated 2 port FastEthernet adapter for the c2600 platform.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class C7200_IO_2FE(Adapter):
"""
C7200-IO-2FE FastEthernet Input/Ouput controller.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class C7200_IO_FE(Adapter):
"""
C7200-IO-FE FastEthernet Input/Ouput controller.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class C7200_IO_GE_E(Adapter):
"""
C7200-IO-GE-E GigabitEthernet Input/Ouput controller.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class Leopard_2FE(Adapter):
"""
Integrated 2 port FastEthernet adapter for c3660 router.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class NM_16ESW(Adapter):
"""
NM-16ESW FastEthernet network module.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class NM_1E(Adapter):
"""
NM-1E Ethernet network module.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class NM_1FE_TX(Adapter):
"""
NM-1FE-TX FastEthernet network module.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class NM_4E(Adapter):
"""
NM-4E Ethernet network module.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class NM_4T(Adapter):
"""
NM-4T Serial network module.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class PA_2FE_TX(Adapter):
"""
PA-2FE-TX FastEthernet port adapter.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class PA_4E(Adapter):
"""
PA-4E Ethernet port adapter.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class PA_4T(Adapter):
"""
PA-4T+ Serial port adapter.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class PA_8E(Adapter):
"""
PA-8E Ethernet port adapter.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class PA_8T(Adapter):
"""
PA-8T Serial port adapter.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class PA_A1(Adapter):
"""
PA-A1 ATM port adapter.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class PA_FE_TX(Adapter):
"""
PA-FE-TX FastEthernet port adapter.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class PA_GE(Adapter):
"""
PA-GE GigabitEthernet port adapter.
"""
@@ -18,7 +18,6 @@ from .adapter import Adapter
class PA_POS_OC3(Adapter):
"""
PA-POS-OC3 port adapter.
"""
@@ -16,7 +16,6 @@
class WIC_1ENET:
"""
WIC-1ENET Ethernet
"""
@@ -16,7 +16,6 @@
class WIC_1T:
"""
WIC-1T Serial
"""
@@ -16,7 +16,6 @@
class WIC_2T:
"""
WIC-2T Serial
"""
@@ -22,5 +22,4 @@ from ..error import NodeError
class DynamipsError(NodeError):
pass
@@ -52,7 +52,6 @@ DEVICES = {
class DynamipsFactory:
"""
Factory to create an Router object based on the correct platform.
"""
@@ -30,7 +30,6 @@ log = logging.getLogger(__name__)
class DynamipsHypervisor:
"""
Creates a new connection to a Dynamips server (also called hypervisor)
@@ -90,7 +89,9 @@ class DynamipsHypervisor:
if not connection_success:
raise DynamipsError(f"Couldn't connect to hypervisor on {host}:{self._port} :{last_exception}")
else:
log.debug(f"Connected to Dynamips hypervisor on {host}:{self._port} after {time.time() - begin:.4f} seconds")
log.debug(
f"Connected to Dynamips hypervisor on {host}:{self._port} after {time.time() - begin:.4f} seconds"
)
try:
version = await self.send("hypervisor version")
@@ -33,7 +33,6 @@ log = logging.getLogger(__name__)
class Hypervisor(DynamipsHypervisor):
"""
Hypervisor.
-1
View File
@@ -28,7 +28,6 @@ log = logging.getLogger(__name__)
class NIO:
"""
Base NIO class
@@ -28,7 +28,6 @@ log = logging.getLogger(__name__)
class NIOGenericEthernet(NIO):
"""
Dynamips generic Ethernet NIO.
@@ -67,7 +66,4 @@ class NIOGenericEthernet(NIO):
def asdict(self):
return {
"type": "nio_generic_ethernet",
"ethernet_device": self._ethernet_device
}
return {"type": "nio_generic_ethernet", "ethernet_device": self._ethernet_device}
@@ -28,7 +28,6 @@ log = logging.getLogger(__name__)
class NIOLinuxEthernet(NIO):
"""
Dynamips Linux Ethernet NIO.
@@ -66,7 +65,4 @@ class NIOLinuxEthernet(NIO):
def asdict(self):
return {
"type": "nio_linux_ethernet",
"ethernet_device": self._ethernet_device
}
return {"type": "nio_linux_ethernet", "ethernet_device": self._ethernet_device}
@@ -28,7 +28,6 @@ log = logging.getLogger(__name__)
class NIONull(NIO):
"""
Dynamips NULL NIO.
+1 -5
View File
@@ -28,7 +28,6 @@ log = logging.getLogger(__name__)
class NIOTAP(NIO):
"""
Dynamips TAP NIO.
@@ -60,7 +59,4 @@ class NIOTAP(NIO):
def asdict(self):
return {
"type": "nio_tap",
"tap_device": self._tap_device
}
return {"type": "nio_tap", "tap_device": self._tap_device}
+1 -7
View File
@@ -31,7 +31,6 @@ log = logging.getLogger(__name__)
class NIOUDP(NIO):
"""
Dynamips UDP NIO.
@@ -130,9 +129,4 @@ class NIOUDP(NIO):
def asdict(self):
return {
"type": "nio_udp",
"lport": self._lport,
"rport": self._rport,
"rhost": self._rhost
}
return {"type": "nio_udp", "lport": self._lport, "rport": self._rport, "rhost": self._rhost}
+1 -6
View File
@@ -28,7 +28,6 @@ log = logging.getLogger(__name__)
class NIOUNIX(NIO):
"""
Dynamips UNIX NIO.
@@ -81,8 +80,4 @@ class NIOUNIX(NIO):
def asdict(self):
return {
"type": "nio_unix",
"local_file": self._local_file,
"remote_file": self._remote_file
}
return {"type": "nio_unix", "local_file": self._local_file, "remote_file": self._remote_file}
+1 -6
View File
@@ -28,7 +28,6 @@ log = logging.getLogger(__name__)
class NIOVDE(NIO):
"""
Dynamips VDE NIO.
@@ -81,8 +80,4 @@ class NIOVDE(NIO):
def asdict(self):
return {
"type": "nio_vde",
"local_file": self._local_file,
"control_file": self._control_file
}
return {"type": "nio_vde", "local_file": self._local_file, "control_file": self._control_file}
@@ -32,7 +32,6 @@ log = logging.getLogger(__name__)
class ATMSwitch(Device):
"""
Dynamips ATM switch.
@@ -24,7 +24,6 @@ from .device import Device
class Bridge(Device):
"""
Dynamips bridge.
@@ -30,7 +30,6 @@ log = logging.getLogger(__name__)
class C1700(Router):
"""
Dynamips c1700 router.
@@ -32,7 +32,6 @@ log = logging.getLogger(__name__)
class C2600(Router):
"""
Dynamips c2600 router.
@@ -30,7 +30,6 @@ log = logging.getLogger(__name__)
class C2691(Router):
"""
Dynamips c2691 router.
@@ -29,7 +29,6 @@ log = logging.getLogger(__name__)
class C3600(Router):
"""
Dynamips c3600 router.
@@ -30,7 +30,6 @@ log = logging.getLogger(__name__)
class C3725(Router):
"""
Dynamips c3725 router.
@@ -30,7 +30,6 @@ log = logging.getLogger(__name__)
class C3745(Router):
"""
Dynamips c3745 router.
@@ -32,7 +32,6 @@ log = logging.getLogger(__name__)
class C7200(Router):
"""
Dynamips c7200 router (model is 7206).
@@ -16,7 +16,6 @@
class Device:
"""
Base device for switches and hubs
@@ -29,7 +29,6 @@ log = logging.getLogger(__name__)
class EthernetHub(Bridge):
"""
Dynamips Ethernet hub (based on Bridge)
@@ -68,7 +68,6 @@ log = logging.getLogger(__name__)
class EthernetSwitch(Device):
"""
Dynamips Ethernet switch.
@@ -31,7 +31,6 @@ log = logging.getLogger(__name__)
class FrameRelaySwitch(Device):
"""
Dynamips Frame Relay switch.
+23 -13
View File
@@ -42,7 +42,6 @@ from gns3server.utils.images import md5sum
class Router(BaseNode):
"""
Dynamips router implementation.
@@ -80,7 +79,14 @@ class Router(BaseNode):
raise DynamipsError(f"{name} is an invalid name to create a Dynamips node")
super().__init__(
name, node_id, project, manager, console=console, console_type=console_type, aux=aux, aux_type=aux_type,
name,
node_id,
project,
manager,
console=console,
console_type=console_type,
aux=aux,
aux_type=aux_type,
wrap_console=(console_type == "ssh"),
wrap_aux=(aux_type == "ssh"),
)
@@ -242,7 +248,6 @@ class Router(BaseNode):
)
if not self._ghost_flag:
log.debug(
'Router {platform} "{name}" [{id}] has been created'.format(
name=self._name, platform=self._platform, id=self._id
@@ -252,7 +257,9 @@ class Router(BaseNode):
if self._console is not None:
# For SSH console, tell Dynamips to listen on the internal port so that
# the AsyncioSSHServer proxy can wrap it on the external console port.
con_port = self._internal_console_port if self._wrap_console and self._internal_console_port else self._console
con_port = (
self._internal_console_port if self._wrap_console and self._internal_console_port else self._console
)
await self._hypervisor.send(f'vm set_con_tcp_port "{self._name}" {con_port}')
if self.aux is not None:
@@ -287,7 +294,6 @@ class Router(BaseNode):
if status == "suspended":
await self.resume()
elif status == "inactive":
if not os.path.isfile(self._image) or not os.path.exists(self._image):
if os.path.islink(self._image):
raise DynamipsError(
@@ -1026,8 +1032,11 @@ class Router(BaseNode):
if self.console_type != console_type:
status = await self.get_status()
if status == "running":
raise DynamipsError('"{name}" must be stopped to change the console type to {console_type}'.format(name=self._name,
console_type=console_type))
raise DynamipsError(
'"{name}" must be stopped to change the console type to {console_type}'.format(
name=self._name, console_type=console_type
)
)
self.console_type = console_type
@@ -1068,9 +1077,10 @@ class Router(BaseNode):
if self.aux_type != aux_type:
status = await self.get_status()
if status == "running":
raise DynamipsError('"{name}" must be stopped to change the auxiliary console type to {aux_type}'.format(
name=self._name,
aux_type=aux_type)
raise DynamipsError(
'"{name}" must be stopped to change the auxiliary console type to {aux_type}'.format(
name=self._name, aux_type=aux_type
)
)
self.aux_type = aux_type
@@ -1228,7 +1238,6 @@ class Router(BaseNode):
# Generate an OIR event if the router is running
if is_running:
await self._hypervisor.send(
'vm slot_oir_start "{name}" {slot_number} 0'.format(name=self._name, slot_number=slot_number)
)
@@ -1274,7 +1283,6 @@ class Router(BaseNode):
# Generate an OIR event if the router is running
if is_running:
await self._hypervisor.send(
'vm slot_oir_stop "{name}" {slot_number} 0'.format(name=self._name, slot_number=slot_number)
)
@@ -1722,7 +1730,9 @@ class Router(BaseNode):
"""
if not is_ios_hostname_valid(new_name):
raise DynamipsError(f"{new_name} is an invalid name to rename router '{self._name}'. Allowed characters: letters (a-z, A-Z), digits (0-9), and hyphens (-). The name must start with a letter, end with a letter or digit, and be 63 characters or fewer.")
raise DynamipsError(
f"{new_name} is an invalid name to rename router '{self._name}'. Allowed characters: letters (a-z, A-Z), digits (0-9), and hyphens (-). The name must start with a letter, end with a letter or digit, and be 63 characters or fewer."
)
await self._hypervisor.send(f'vm rename "{self._name}" "{new_name}"')