fix(links): reserve ports on add, accept port name and auto, add port_in_use code

This commit is contained in:
Mark Paronyan committed 2026-10-07 15:41:04 +03:00
1 parent 2fb7056cb9
commit a9e87df644
10 files changed
+286 -21

No files matched your search

+21
View File
@@ -1142,6 +1142,27 @@ class Node:
return port
return None
def get_port_by_name(self, name):
"""
Return the port with this name or None if the port is not found
"""
for port in self.ports:
if port.name == name:
return port
return None
def get_free_port(self, link_type=None):
"""
Return the lowest free port, optionally restricted to a link type,
or None if there is no such port
"""
free_ports = [
port for port in self.ports if port.link is None and (link_type is None or port.link_type == link_type)
]
if not free_ports:
return None
return min(free_ports, key=lambda port: (port.adapter_number, port.port_number))
def _list_ports(self):
"""
Generate the list of port display in the client