Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Dante Su <dante.su@broadcom.com>
  • Loading branch information
ds952811 committed May 10, 2022
1 parent 63c6b47 commit 3d2f5c3
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions scripts/intfutil
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ def appl_db_port_status_get(appl_db, intf_name, status_type):
status = ','.join(new_speed_list)
return status

def get_port_speed_pretty(speed):
spd = int(speed)
if spd < 1000:
ret = '{}M'.format(spd)
elif spd % 1000 >= 100:
ret = '{:.1f}G'.format(spd / 1000)
else:
ret = '{:.0f}G'.format(spd / 1000)
return ret

def state_db_port_status_get(db, intf_name, field):
"""
Get the port status
Expand All @@ -174,21 +184,11 @@ def state_db_port_status_get(db, intf_name, field):
status = db.get(db.STATE_DB, full_table_id, field)
if not status:
return "N/A"
if field == PORT_SPEED and status != "N/A":
speed = int(status)
if speed >= 1000:
status = '{}G'.format(int(speed / 1000))
else:
status = '{}M'.format(speed)
elif field in [PORT_RMT_ADV_SPEEDS] and status not in ["N/A", "all"]:
if field in [PORT_RMT_ADV_SPEEDS] and status not in ["N/A", "all"]:
speed_list = status.split(',')
new_speed_list = []
for s in natsorted(speed_list):
speed = int(s)
if speed >= 1000:
new_speed_list.append('{}G'.format(int(speed / 1000)))
else:
new_speed_list.append('{}M'.format(speed))
new_speed_list.append(get_port_speed_pretty(s))
status = ','.join(new_speed_list)
return status

Expand All @@ -201,7 +201,7 @@ def port_oper_speed_get(db, intf_name):
if oper_speed is None or oper_speed == "N/A" or oper_status != "up":
return appl_db_port_status_get(db, intf_name, PORT_SPEED)

return '{}G'.format(oper_speed[:-3])
return get_port_speed_pretty(oper_speed)

def port_oper_speed_get_raw(db, intf_name):
"""
Expand Down

0 comments on commit 3d2f5c3

Please sign in to comment.