Move bad-net colour outside of string

This just trashed the formatting of the string if the network didn't
exist, despite several previous attempts to get this to align. Give up;
set the colour for the whole net list if any one network is invalid.
This is not as nice as per-network colouring but saves the hassle and
complexity.
This commit is contained in:
Joshua Boniface 2019-07-12 12:22:41 -04:00
parent 50367c9190
commit 1da7462e0d
1 changed files with 5 additions and 6 deletions

View File

@ -782,19 +782,17 @@ def format_list(zk_conn, vm_list, raw):
# Handle colouring for an invalid network config # Handle colouring for an invalid network config
raw_net_list = getNiceNetID(domain_information) raw_net_list = getNiceNetID(domain_information)
net_list = [] net_list = []
vm_net_colour = ''
for net_vni in raw_net_list: for net_vni in raw_net_list:
net_exists = zkhandler.exists(zk_conn, '/networks/{}'.format(net_vni)) net_exists = zkhandler.exists(zk_conn, '/networks/{}'.format(net_vni))
if not net_exists and net_vni != 'cluster': if not net_exists and net_vni != 'cluster':
net_list.append(ansiprint.red() + net_vni + ansiprint.end()) vm_net_colour = ansiprint.red()
# Add 9 characters (the ANSI control chars) to the length so everything lines up net_list.append(net_vni)
vm_nets_length += 9
else:
net_list.append(net_vni)
vm_list_output.append( vm_list_output.append(
'{bold}{vm_name: <{vm_name_length}} {vm_uuid: <{vm_uuid_length}} \ '{bold}{vm_name: <{vm_name_length}} {vm_uuid: <{vm_uuid_length}} \
{vm_state_colour}{vm_state: <{vm_state_length}}{end_colour} \ {vm_state_colour}{vm_state: <{vm_state_length}}{end_colour} \
{vm_networks: <{vm_nets_length}} \ {vm_net_colour}{vm_networks: <{vm_nets_length}}{end_colour} \
{vm_memory: <{vm_ram_length}} {vm_vcpu: <{vm_vcpu_length}} \ {vm_memory: <{vm_ram_length}} {vm_vcpu: <{vm_vcpu_length}} \
{vm_node: <{vm_node_length}} \ {vm_node: <{vm_node_length}} \
{vm_migrated: <{vm_migrated_length}}{end_bold}'.format( {vm_migrated: <{vm_migrated_length}}{end_bold}'.format(
@ -813,6 +811,7 @@ def format_list(zk_conn, vm_list, raw):
vm_name=domain_information['name'], vm_name=domain_information['name'],
vm_uuid=domain_information['uuid'], vm_uuid=domain_information['uuid'],
vm_state=domain_information['state'], vm_state=domain_information['state'],
vm_net_colour=vm_net_colour,
vm_networks=','.join(net_list), vm_networks=','.join(net_list),
vm_memory=domain_information['memory'], vm_memory=domain_information['memory'],
vm_vcpu=domain_information['vcpu'], vm_vcpu=domain_information['vcpu'],