ynl: support hex display_hint for integer
Some times it would be convenient to read the integer as hex, like mask values. Suggested-by: Donald Hunter <donald.hunter@gmail.com> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Link: https://lore.kernel.org/r/20240327123130.1322921-2-liuhangbin@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
51cf49f626
commit
b334f5ed3d
@@ -819,6 +819,9 @@ class YnlFamily(SpecFamily):
|
|||||||
if display_hint == 'mac':
|
if display_hint == 'mac':
|
||||||
formatted = ':'.join('%02x' % b for b in raw)
|
formatted = ':'.join('%02x' % b for b in raw)
|
||||||
elif display_hint == 'hex':
|
elif display_hint == 'hex':
|
||||||
|
if isinstance(raw, int):
|
||||||
|
formatted = hex(raw)
|
||||||
|
else:
|
||||||
formatted = bytes.hex(raw, ' ')
|
formatted = bytes.hex(raw, ' ')
|
||||||
elif display_hint in [ 'ipv4', 'ipv6' ]:
|
elif display_hint in [ 'ipv4', 'ipv6' ]:
|
||||||
formatted = format(ipaddress.ip_address(raw))
|
formatted = format(ipaddress.ip_address(raw))
|
||||||
|
Reference in New Issue
Block a user