0.1
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
# models/base_switch.py
|
||||
from typing import List, Optional
|
||||
import re
|
||||
|
||||
def normalize_port_name(port: str) -> str:
|
||||
port = port.upper()
|
||||
port = port.replace("GE", "GIGABITETHERNET")
|
||||
port = port.replace("XGE", "TEN-GIGABITETHERNET")
|
||||
port = port.replace("BAGG", "BRIDGE-AGGREGATION")
|
||||
return port
|
||||
|
||||
class PowerSupply:
|
||||
def __init__(self, id: int, state: str, mode: Optional[str] = None):
|
||||
@@ -55,14 +62,20 @@ class Port:
|
||||
self.speed = None
|
||||
self.vlan = None
|
||||
self.link_type = None
|
||||
self.trunk_vlans = []
|
||||
self.trunk_vlans: List[int] = []
|
||||
self.bpdu_protection = False
|
||||
self.portfast = False
|
||||
self.loopback_detection = None
|
||||
self.mac_addresses = []
|
||||
self.mac_addresses: List[str] = []
|
||||
self.summary = ""
|
||||
|
||||
def to_dict(self):
|
||||
mac_count = len(self.mac_addresses)
|
||||
mac_info = f", {mac_count} MAC" if mac_count else ""
|
||||
vlan_info = f"TRUNK ({', '.join(map(str, sorted(self.trunk_vlans)))})" if self.link_type == "trunk" else f"VLAN {self.vlan or '?'}"
|
||||
status = self.status.upper() if self.status else "INCONNU"
|
||||
speed = self.speed or "vitesse inconnue"
|
||||
self.summary = f"Port {self.name} est {status} à {speed}, {vlan_info}{mac_info}"
|
||||
return {
|
||||
"object": "port",
|
||||
"name": self.name,
|
||||
@@ -70,11 +83,11 @@ class Port:
|
||||
"speed": self.speed,
|
||||
"vlan": self.vlan,
|
||||
"link_type": self.link_type,
|
||||
"trunk_vlans": self.trunk_vlans if self.link_type == "trunk" else None,
|
||||
"trunk_vlans": ", ".join(map(str, self.trunk_vlans)) if self.link_type == "trunk" else None,
|
||||
"bpdu_protection": self.bpdu_protection,
|
||||
"portfast": self.portfast,
|
||||
"loopback_detection": self.loopback_detection,
|
||||
"mac_addresses": [m.to_dict() for m in self.mac_addresses],
|
||||
"mac_addresses": self.mac_addresses,
|
||||
"summary": self.summary,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user