55import re
66
77
8- def process_interfaces (interfaces , ports_chassis , dev = 1 ):
8+ def process_interfaces (interfaces , ports_chassis , dev ):
99 if interfaces is not None :
1010 for itf in interfaces :
11- regex = r"^(?P<type>([a-z]+))((?P<dev>[0-9]+)\/)?((?P<module>[0-9]+)\/)?((?P<port>[0-9]+))$"
11+ if itf .type == "virtual" or itf .type == "lag" :
12+ continue
13+ regex = r"^(?P<type>([a-zA-Z\-_]*))(\/|(?P<dev>[0-9]+).|\s)?((?P<module>[0-9]+).|\s)?((?P<port>[0-9]+))$"
1214 matches = re .search (regex , itf .name .lower ())
1315 if matches :
1416 itf .stylename = (
@@ -17,37 +19,24 @@ def process_interfaces(interfaces, ports_chassis, dev=1):
1719 + "-"
1820 + matches ["port" ]
1921 )
20- sw = int (matches ["dev" ] or 999 )
21- if (
22- hasattr (itf , "mgmt_only" )
23- and itf .mgmt_only
24- and itf .type != "virtual"
25- ) or hasattr (itf , "mgmt_only" ) == False :
26- sw = dev
27- if sw not in ports_chassis and sw != 999 :
28- ports_chassis [sw ] = []
29- if sw != 999 :
30- ports_chassis [sw ].append (itf )
22+ else :
23+ itf .stylename = re .sub (r"[^.a-zA-Z\d]" , "-" , itf .name .lower ())
24+ if dev not in ports_chassis :
25+ ports_chassis [dev ] = []
26+ ports_chassis [dev ].append (itf )
3127 return ports_chassis
3228
3329
34- def process_ports (ports , ports_chassis , where ):
30+ def process_ports (ports , ports_chassis , dev ):
3531 if ports is not None :
3632 for port in ports :
37- regex = r"^(?P<type>([A-Za-z]+))[\s]?((?P<port>[0-9]+))$"
38- matches = re .search (regex , port .name .lower ())
39- port .is_port = True
40- if matches :
41- port .stylename = (matches ["type" ] or "" ) + "-" + matches ["port" ]
42- else :
43- port .stylename = re .sub (r"[^.a-zA-Z\d]" , "-" , port .name .lower ())
44- sw = where
4533 if port .type == "virtual" :
46- sw = 999
47- if sw not in ports_chassis and sw != 999 :
48- ports_chassis [sw ] = []
49- if sw != 999 :
50- ports_chassis [sw ].append (port )
34+ continue
35+ port .is_port = True
36+ port .stylename = re .sub (r"[^.a-zA-Z\d]" , "-" , port .name .lower ())
37+ if dev not in ports_chassis :
38+ ports_chassis [dev ] = []
39+ ports_chassis [dev ].append (port )
5140 return ports_chassis
5241
5342
@@ -62,7 +51,7 @@ def prepare(obj):
6251 device_type = obj .device_type
6352 ).grid_template_area
6453 modules [1 ] = obj .modules .all ()
65- ports_chassis = process_interfaces (obj .interfaces .all (), ports_chassis )
54+ ports_chassis = process_interfaces (obj .interfaces .all (), ports_chassis , 1 )
6655 ports_chassis = process_ports (obj .frontports .all (), ports_chassis , "Front" )
6756 ports_chassis = process_ports (obj .rearports .all (), ports_chassis , "Rear" )
6857 ports_chassis = process_ports (
0 commit comments