Skip to content

Commit

Permalink
status: improve diff presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
daniloegea committed Aug 1, 2023
1 parent cce700f commit 0429439
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions netplan_cli/cli/commands/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def pretty_print(self, data: JSON, total: int, _console_width=None, diff_state:
pad = '18'
global_state = data.get('netplan-global-state', {})
interfaces = [(key, data[key]) for key in data if key != 'netplan-global-state']
full_state = diff_state.get_full_state() if diff_state else None

# Global state
pprint(('{title:>'+pad+'} {value}').format(
Expand Down Expand Up @@ -123,7 +124,7 @@ def pretty_print(self, data: JSON, total: int, _console_width=None, diff_state:
status = ''
if missing_interfaces_netplan:
if ifname in missing_interfaces_netplan:
status = ' [highlight](+ missing in Netplan)[/highlight]'
status = ' [highlight][purple](+ missing in Netplan)[/purple][/highlight]'
if full_type == 'wifi' and ssid:
full_type += ('/"' + ssid + '"')
elif full_type == 'tunnel' and tunnel_mode:
Expand Down Expand Up @@ -164,7 +165,8 @@ def pretty_print(self, data: JSON, total: int, _console_width=None, diff_state:
if missing_netplan := interface_diff.get('netplan_state', {}).get('missing_addresses'):
prefix = extra.get('prefix', '')
if f'{ip}/{prefix}' in missing_netplan:
highlight_end = highlight_end + ' (+)'
highlight_start = highlight_start + '[purple]'
highlight_end = ' (+)[/purple]' + highlight_end
pprint(('{title:>'+pad+'} {start}{ip}/{prefix}{end}[muted]{extra}[/muted]').format(
title='Addresses:' if i == 0 else '',
ip=ip,
Expand All @@ -177,8 +179,8 @@ def pretty_print(self, data: JSON, total: int, _console_width=None, diff_state:
if diff_state:
if netdef_id := data.get('id'):
interface_diff = diff_state.get_diff().get('interfaces', {}).get(netdef_id)
highlight_start = '[muted]'
highlight_end = '[/muted] (-)'
highlight_start = '[red]'
highlight_end = ' (-)[/red]'
if missing_system := interface_diff.get('system_state', {}).get('missing_addresses'):
for addr in missing_system:
pprint(('{title:>'+pad+'} {start}{ip}{end}').format(
Expand All @@ -188,17 +190,17 @@ def pretty_print(self, data: JSON, total: int, _console_width=None, diff_state:
end=highlight_end,
))
if interface_diff.get('missing_dhcp4_address', False):
highlight_start = '[muted]'
highlight_end = '[/muted]'
highlight_start = '[red]'
highlight_end = '[/red]'
pprint(('{title:>'+pad+'} {start}{ip}{end}').format(
title='',
ip='DHCPv4: missing IP',
start=highlight_start,
end=highlight_end,
))
if interface_diff.get('missing_dhcp6_address', False):
highlight_start = '[muted]'
highlight_end = '[/muted]'
highlight_start = '[red]'
highlight_end = '[/red]'
pprint(('{title:>'+pad+'} {start}{ip}{end}').format(
title='',
ip='DHCPv6: missing IP',
Expand All @@ -217,14 +219,14 @@ def pretty_print(self, data: JSON, total: int, _console_width=None, diff_state:

for i, val in enumerate(lst):
if val in missing_netplan:
val = f'[highlight]{val} (+)[/highlight]'
val = f'[highlight bold][purple]{val} (+)[/purple][/highlight bold]'
pprint(('{title:>'+pad+'} {value}').format(
title='DNS Addresses:' if i == 0 else '',
value=val,
))

for i, val in enumerate(missing_system):
val = f'[muted]{val} (-)[/muted]'
val = f'[red]{val} (-)[/red]'
pprint(('{title:>'+pad+'} {value}').format(
title='',
value=val,
Expand All @@ -240,14 +242,14 @@ def pretty_print(self, data: JSON, total: int, _console_width=None, diff_state:
missing_system = interface_diff.get('system_state', {}).get('missing_search_domains', [])
for i, val in enumerate(lst):
if val in missing_netplan:
val = f'[highlight]{val} (+)[/highlight]'
val = f'[highlight][purple]{val} (+)[/purple][/highlight]'
pprint(('{title:>'+pad+'} {value}').format(
title='DNS Search:' if i == 0 else '',
value=val,
))

for i, val in enumerate(missing_system):
val = f'[muted]{val} (-)[/muted]'
val = f'[red]{val} (-)[/red]'
pprint(('{title:>'+pad+'} {value}').format(
title='',
value=val,
Expand Down Expand Up @@ -301,11 +303,14 @@ def pretty_print(self, data: JSON, total: int, _console_width=None, diff_state:
pprint()

if missing_interfaces_system:
for ifname in missing_interfaces_system:
pprint('[{col}]●[/{col}] ??: {name} MISSING (found only in Netplan)'.format(
for ifname in sorted(missing_interfaces_system):
pprint('[{col}]●[/{col}] ??: {name} {type} [red][bold]MISSING[/bold][/red]'.format(
col='muted',
name=ifname,
type=full_state.get('interfaces', {}).get(ifname, {}).get('netplan_state', {}).get('type')
))
pprint()

hidden = total - len(interfaces)
if (hidden > 0):
pprint('{} inactive interfaces hidden. Use "--all" to show all.'.format(hidden))
Expand Down

0 comments on commit 0429439

Please sign in to comment.