@@ -452,7 +452,10 @@ def get_timestamp_from_junos_time(in_data, timestamp: int):
452452
453453
454454def convert_macaddr_format_to_colon (macaddr : str ) -> str :
455- """Convert NXOS/EOS . macaddr form to standard : format, lowecase
455+ """Convert various macaddr forms to standard ':' format, lowecase
456+
457+ One unexpected side-effect, it'll convert the given string to lowercase
458+ even if it doesn't match a macaddr.
456459
457460 :param macaddr: str, the macaddr string to convert
458461 :returns: the converted macaddr string or all 0s string if arg not str
@@ -471,15 +474,16 @@ def convert_macaddr_format_to_colon(macaddr: str) -> str:
471474 if re .match (r'[0-9a-f]{4}:[0-9a-f]{4}:[0-9a-f]{4}' , macaddr ):
472475 return (':' .join ([f'{ x [:2 ]} :{ x [2 :]} '
473476 for x in macaddr .split (':' )]))
474- if re .match (r'[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}' , macaddr ):
475- return (':' .join ([f'{ x [:2 ]} :{ x [2 :]} '
476- for x in macaddr .split ('-' )]))
477477 if ':' not in macaddr and re .match (r'[0-9a-f]{12}' , macaddr ):
478478 newmac = ''
479479 for i in range (0 , 12 , 2 ):
480480 newmac += f'{ macaddr [i :i + 2 ]} :'
481481 newmac = newmac [:- 1 ] # remove the trailing ':'
482482 return newmac
483+ if re .match (r'[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}' , macaddr ):
484+ return (':' .join ([f'{ x [:2 ]} :{ x [2 :]} '
485+ for x in macaddr .split ('-' )]))
486+ return macaddr
483487
484488 return '00:00:00:00:00:00'
485489
0 commit comments