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

-2
View File
@@ -18,7 +18,6 @@
Builtin nodes server module.
"""
from ..base_manager import BaseManager
from .builtin_node_factory import BuiltinNodeFactory, BUILTIN_NODES
@@ -28,7 +27,6 @@ log = logging.getLogger(__name__)
class Builtin(BaseManager):
_NODE_CLASS = BuiltinNodeFactory
def __init__(self):
@@ -29,7 +29,6 @@ BUILTIN_NODES = {"cloud": Cloud, "nat": Nat, "ethernet_hub": EthernetHub, "ether
class BuiltinNodeFactory:
"""
Factory to create an builtin object based on the node type.
"""
+1 -6
View File
@@ -31,7 +31,6 @@ log = logging.getLogger(__name__)
class Cloud(BaseNode):
"""
Cloud.
@@ -317,7 +316,6 @@ class Cloud(BaseNode):
await self._ubridge_apply_filters(bridge_name, nio.filters)
await self._ubridge_apply_markers(bridge_name, nio)
if port_info["type"] in ("ethernet", "tap"):
if not self.manager.has_privileged_access(self.ubridge_path):
raise NodeError(
"uBridge requires root access or the capability to interact with Ethernet and TAP adapters"
@@ -339,9 +337,7 @@ class Cloud(BaseNode):
elif port_info["type"] == "tap":
await self._ubridge_send(
'bridge add_nio_tap {name} "{interface}"'.format(
name=bridge_name, interface=port_info["interface"]
)
'bridge add_nio_tap {name} "{interface}"'.format(name=bridge_name, interface=port_info["interface"])
)
elif port_info["type"] == "udp":
@@ -367,7 +363,6 @@ class Cloud(BaseNode):
interface = port_info["interface"]
if gns3server.utils.interfaces.is_interface_bridge(interface):
network_interfaces = [interface["name"] for interface in self._interfaces()]
i = 0
while True:
@@ -24,7 +24,6 @@ log = logging.getLogger(__name__)
class EthernetHub(BaseNode):
"""
Ethernet hub
@@ -40,12 +39,7 @@ class EthernetHub(BaseNode):
def asdict(self):
return {
"name": self.name,
"usage": self.usage,
"node_id": self.id,
"project_id": self.project.id
}
return {"name": self.name, "usage": self.usage, "node_id": self.id, "project_id": self.project.id}
async def create(self):
"""
@@ -55,7 +55,6 @@ _QINQ_ETHERTYPE = "0x88a8"
class EthernetSwitch(BaseNode):
"""
Ethernet switch.
@@ -74,8 +73,8 @@ class EthernetSwitch(BaseNode):
self._ubridge_require_privileged_access = True
self._nios = {}
self._tap_by_port = {} # port_number -> kernel TAP enslaved to the bridge
self._bridge_name = None # kernel bridge interface name (allocated on start)
self._tap_by_port = {} # port_number -> kernel TAP enslaved to the bridge
self._bridge_name = None # kernel bridge interface name (allocated on start)
self._bridge_created = False
self._bridge_proto_set = False # whether ``brctl setvlanproto`` has been applied
# Idempotency flag for start(). Decoupled from ``status`` so the node can
+9 -5
View File
@@ -38,14 +38,16 @@ class Nat(Cloud):
allowed_interfaces = Config.instance().settings.Server.allowed_interfaces
if allowed_interfaces and isinstance(allowed_interfaces, str):
allowed_interfaces = allowed_interfaces.split(',')
allowed_interfaces = allowed_interfaces.split(",")
if sys.platform.startswith("linux"):
nat_interface = Config.instance().settings.Server.default_nat_interface
if not nat_interface:
nat_interface = "virbr0"
if allowed_interfaces and nat_interface not in allowed_interfaces:
raise NodeError("NAT interface {} is not allowed be used on this server. "
"Please check the server configuration file.".format(nat_interface))
raise NodeError(
"NAT interface {} is not allowed be used on this server. "
"Please check the server configuration file.".format(nat_interface)
)
if nat_interface not in [interface["name"] for interface in gns3server.utils.interfaces.interfaces()]:
raise NodeError(f"NAT interface {nat_interface} is missing, please install libvirt")
interface = nat_interface
@@ -54,8 +56,10 @@ class Nat(Cloud):
if not nat_interface:
nat_interface = "vmnet8"
if allowed_interfaces and nat_interface not in allowed_interfaces:
raise NodeError("NAT interface {} is not allowed be used on this server. "
"Please check the server configuration file.".format(nat_interface))
raise NodeError(
"NAT interface {} is not allowed be used on this server. "
"Please check the server configuration file.".format(nat_interface)
)
interfaces = list(
filter(
lambda x: nat_interface in x.lower(),