From 720469d38950757e777bf23c617802d92449fced Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Fri, 2 Nov 2018 00:42:44 -0400 Subject: [PATCH] Standardize the layout of lists (dynamic fields) --- client-common/ceph.py | 2 +- client-common/network.py | 65 +++++++++++++++++++++++----------------- client-common/node.py | 61 +++++++++++++++++++++++++++++++++---- client-common/vm.py | 43 +++++++++++++++++--------- 4 files changed, 123 insertions(+), 48 deletions(-) diff --git a/client-common/ceph.py b/client-common/ceph.py index 4c05bafa..1486a46f 100644 --- a/client-common/ceph.py +++ b/client-common/ceph.py @@ -259,7 +259,7 @@ Sp: {osd_used: <{osd_used_length}} \ {osd_var: <{osd_var_length}} \ Rd: {osd_rdops: <{osd_rdops_length}} \ {osd_rddata: <{osd_rddata_length}} \ -Wt: {osd_wrops: <{osd_wrops_length}} \ +Wr: {osd_wrops: <{osd_wrops_length}} \ {osd_wrdata: <{osd_wrdata_length}} \ {end_bold}'.format( bold=ansiprint.bold(), diff --git a/client-common/network.py b/client-common/network.py index 5b147089..75674ae7 100644 --- a/client-common/network.py +++ b/client-common/network.py @@ -120,7 +120,7 @@ def getNetworkACLs(zk_conn, vni, _direction): full_acl_list = [] for direction in directions: unordered_acl_list = zkhandler.listchildren(zk_conn, '/networks/{}/firewall_rules/{}'.format(vni, direction)) - ordered_acls = {} + ordered_acls = dict() for acl in unordered_acl_list: order = zkhandler.readdata(zk_conn, '/networks/{}/firewall_rules/{}/{}/order'.format(vni, direction, acl)) ordered_acls[order] = acl @@ -207,15 +207,15 @@ def formatNetworkInformation(zk_conn, vni, long_output): def formatNetworkList(zk_conn, net_list): net_list_output = [] - description = {} - domain = {} - ip_network = {} - ip_gateway = {} - dhcp_flag = {} - dhcp_flag_colour = {} - dhcp_start = {} - dhcp_end = {} - dhcp_range = {} + description = dict() + domain = dict() + ip_network = dict() + ip_gateway = dict() + dhcp_flag = dict() + dhcp_flag_colour = dict() + dhcp_start = dict() + dhcp_end = dict() + dhcp_range = dict() colour_off = ansiprint.end() # Gather information for printing @@ -237,6 +237,7 @@ def formatNetworkList(zk_conn, net_list): net_domain_length = 8 net_ip_network_length = 12 net_ip_gateway_length = 9 + net_dhcp_flag_length = 5 net_dhcp_range_length = 12 for net in net_list: # vni column @@ -259,6 +260,10 @@ def formatNetworkList(zk_conn, net_list): _net_ip_gateway_length = len(ip_gateway[net]) + 1 if _net_ip_gateway_length > net_ip_gateway_length: net_ip_gateway_length = _net_ip_gateway_length + # dhcp_flag column + _net_dhcp_flag_length = len(dhcp_flag[net]) + 1 + if _net_dhcp_flag_length > net_dhcp_flag_length: + net_dhcp_flag_length = _net_dhcp_flag_length # dhcp_range column _net_dhcp_range_length = len(dhcp_range[net]) + 1 if _net_dhcp_range_length > net_dhcp_range_length: @@ -271,7 +276,7 @@ def formatNetworkList(zk_conn, net_list): {net_domain: <{net_domain_length}} \ {net_ip_network: <{net_ip_network_length}} \ {net_ip_gateway: <{net_ip_gateway_length}} \ -{net_dhcp_flag: <6} \ +{net_dhcp_flag: <{net_dhcp_flag_length}} \ {net_dhcp_range: <{net_dhcp_range_length}} \ {end_bold}'.format( bold=ansiprint.bold(), @@ -281,6 +286,7 @@ def formatNetworkList(zk_conn, net_list): net_domain_length=net_domain_length, net_ip_network_length=net_ip_network_length, net_ip_gateway_length=net_ip_gateway_length, + net_dhcp_flag_length=net_dhcp_flag_length, net_dhcp_range_length=net_dhcp_range_length, net_vni='VNI', net_description='Description', @@ -299,7 +305,7 @@ def formatNetworkList(zk_conn, net_list): {net_domain: <{net_domain_length}} \ {net_ip_network: <{net_ip_network_length}} \ {net_ip_gateway: <{net_ip_gateway_length}} \ -{dhcp_flag_colour}{net_dhcp_flag: <6}{colour_off} \ +{dhcp_flag_colour}{net_dhcp_flag: <{net_dhcp_flag_length}}{colour_off} \ {net_dhcp_range: <{net_dhcp_range_length}} \ {end_bold}'.format( bold='', @@ -309,6 +315,7 @@ def formatNetworkList(zk_conn, net_list): net_domain_length=net_domain_length, net_ip_network_length=net_ip_network_length, net_ip_gateway_length=net_ip_gateway_length, + net_dhcp_flag_length=net_dhcp_flag_length, net_dhcp_range_length=net_dhcp_range_length, net_vni=net, net_description=description[net], @@ -327,10 +334,10 @@ def formatNetworkList(zk_conn, net_list): def formatDHCPLeaseList(zk_conn, vni, dhcp_leases_list, reservations=False): dhcp_lease_list_output = [] - hostname = {} - ip_address = {} - mac_address = {} - timestamp = {} + hostname = dict() + ip_address = dict() + mac_address = dict() + timestamp = dict() # Gather information for printing for dhcp_lease in dhcp_leases_list: @@ -340,9 +347,10 @@ def formatDHCPLeaseList(zk_conn, vni, dhcp_leases_list, reservations=False): hostname[dhcp_lease], ip_address[dhcp_lease], mac_address[dhcp_lease], timestamp[dhcp_lease] = getDHCPLeaseInformation(zk_conn, vni, dhcp_lease) # Determine optimal column widths - lease_hostname_length = 13 + lease_hostname_length = 9 lease_ip_address_length = 11 lease_mac_address_length = 13 + lease_timestamp_length = 13 for dhcp_lease in dhcp_leases_list: # hostname column _lease_hostname_length = len(hostname[dhcp_lease]) + 1 @@ -369,7 +377,7 @@ def formatDHCPLeaseList(zk_conn, vni, dhcp_leases_list, reservations=False): lease_hostname_length=lease_hostname_length, lease_ip_address_length=lease_ip_address_length, lease_mac_address_length=lease_mac_address_length, - lease_timestamp_length=12, + lease_timestamp_length=lease_timestamp_length, lease_hostname='Hostname', lease_ip_address='IP Address', lease_mac_address='MAC Address', @@ -401,10 +409,10 @@ def formatDHCPLeaseList(zk_conn, vni, dhcp_leases_list, reservations=False): def formatACLList(zk_conn, vni, _direction, acl_list): acl_list_output = [] - direction = {} - order = {} - description = {} - rule = {} + direction = dict() + order = dict() + description = dict() + rule = dict() if _direction is None: directions = ['in', 'out'] @@ -418,6 +426,7 @@ def formatACLList(zk_conn, vni, _direction, acl_list): direction[acld] = acl['direction'] # Determine optimal column widths + acl_direction_length = 10 acl_order_length = 6 acl_description_length = 12 acl_rule_length = 5 @@ -438,13 +447,14 @@ def formatACLList(zk_conn, vni, _direction, acl_list): # Format the string (header) acl_list_output_header = '{bold}\ -{acl_direction: <10} \ +{acl_direction: <{acl_direction_length}} \ {acl_order: <{acl_order_length}} \ {acl_description: <{acl_description_length}} \ {acl_rule: <{acl_rule_length}} \ {end_bold}'.format( bold=ansiprint.bold(), end_bold=ansiprint.end(), + acl_direction_length=acl_direction_length, acl_order_length=acl_order_length, acl_description_length=acl_description_length, acl_rule_length=acl_rule_length, @@ -457,13 +467,14 @@ def formatACLList(zk_conn, vni, _direction, acl_list): for acl in acl_list: acld = acl['description'] acl_list_output.append('{bold}\ -{acl_direction: <10} \ +{acl_direction: <{acl_direction_length}} \ {acl_order: <{acl_order_length}} \ {acl_description: <{acl_description_length}} \ {acl_rule: <{acl_rule_length}} \ {end_bold}'.format( bold='', end_bold='', + acl_direction_length=acl_direction_length, acl_order_length=acl_order_length, acl_description_length=acl_description_length, acl_rule_length=acl_rule_length, @@ -538,7 +549,7 @@ def add_network(zk_conn, vni, description, domain, ip_network, ip_gateway, dhcp_ def modify_network(zk_conn, vni, **parameters): # Add the new network to Zookeeper - zk_data = {} + zk_data = dict() if parameters['description'] != None: zk_data.update({'/networks/{}'.format(vni): parameters['description']}) if parameters['domain'] != None: @@ -657,7 +668,7 @@ def add_acl(zk_conn, network, direction, description, rule, order): full_acl_list.insert(order, {'direction': direction, 'description': description}) # Update the existing ordering - updated_orders = {} + updated_orders = dict() for idx, acl in enumerate(full_acl_list): if acl['description'] == description: continue @@ -715,7 +726,7 @@ def remove_acl(zk_conn, network, rule, direction): # Update the existing ordering updated_acl_list = getNetworkACLs(zk_conn, net_vni, direction) - updated_orders = {} + updated_orders = dict() for idx, acl in enumerate(updated_acl_list): updated_orders[ '/networks/{}/firewall_rules/{}/{}/order'.format(net_vni, direction, acl['description']) diff --git a/client-common/node.py b/client-common/node.py index 62939a30..d1286598 100644 --- a/client-common/node.py +++ b/client-common/node.py @@ -240,9 +240,9 @@ def get_list(zk_conn, limit): node_mem_used = {} node_mem_free = {} node_mem_total = {} + node_mem_allocated = {} node_domains_count = {} node_running_domains = {} - node_mem_allocated = {} node_load = {} # Gather information for printing @@ -264,7 +264,14 @@ def get_list(zk_conn, limit): node_name_length = 5 daemon_state_length = 7 router_state_length = 7 - domain_state_length = 8 + domain_state_length = 7 + domains_count_length = 4 + cpu_count_length = 5 + load_length = 5 + mem_total_length = 6 + mem_used_length = 5 + mem_free_length = 5 + mem_alloc_length = 4 for node_name in node_list: # node_name column _node_name_length = len(node_name) + 1 @@ -282,17 +289,52 @@ def get_list(zk_conn, limit): _domain_state_length = len(node_domain_state[node_name]) + 1 if _domain_state_length > domain_state_length: domain_state_length = _domain_state_length + # domains_count column + _domains_count_length = len(node_domains_count[node_name]) + 1 + if _domains_count_length > domains_count_length: + domains_count_length = _domains_count_length + # cpu_count column + _cpu_count_length = len(node_cpu_count[node_name]) + 1 + if _cpu_count_length > cpu_count_length: + cpu_count_length = _cpu_count_length + # load column + _load_length = len(node_load[node_name]) + 1 + if _load_length > load_length: + load_length = _load_length + # mem_total column + _mem_total_length = len(str(node_mem_total[node_name])) + 1 + if _mem_total_length > mem_total_length: + mem_total_length = _mem_total_length + # mem_used column + _mem_used_length = len(str(node_mem_used[node_name])) + 1 + if _mem_used_length > mem_used_length: + mem_used_length = _mem_used_length + # mem_free column + _mem_free_length = len(str(node_mem_free[node_name])) + 1 + if _mem_free_length > mem_free_length: + mem_free_length = _mem_free_length + # mem_alloc column + _mem_alloc_length = len(str(node_mem_allocated[node_name])) + 1 + if _mem_alloc_length > mem_alloc_length: + mem_alloc_length = _mem_alloc_length # Format the string (header) node_list_output.append( '{bold}{node_name: <{node_name_length}} \ St: {daemon_state_colour}{node_daemon_state: <{daemon_state_length}}{end_colour} {router_state_colour}{node_router_state: <{router_state_length}}{end_colour} {domain_state_colour}{node_domain_state: <{domain_state_length}}{end_colour} \ -Res: {node_domains_count: <4} {node_cpu_count: <5} {node_load: <5} \ -Mem (M): {node_mem_total: <6} {node_mem_used: <6} {node_mem_free: <6} {node_mem_allocated: <6}{end_bold}'.format( +Res: {node_domains_count: <{domains_count_length}} {node_cpu_count: <{cpu_count_length}} {node_load: <{load_length}} \ +Mem (M): {node_mem_total: <{mem_total_length}} {node_mem_used: <{mem_used_length}} {node_mem_free: <{mem_free_length}} {node_mem_allocated: <{mem_alloc_length}}{end_bold}'.format( node_name_length=node_name_length, daemon_state_length=daemon_state_length, router_state_length=router_state_length, domain_state_length=domain_state_length, + domains_count_length=domains_count_length, + cpu_count_length=cpu_count_length, + load_length=load_length, + mem_total_length=mem_total_length, + mem_used_length=mem_used_length, + mem_free_length=mem_free_length, + mem_alloc_length=mem_alloc_length, bold=ansiprint.bold(), end_bold=ansiprint.end(), daemon_state_colour='', @@ -344,12 +386,19 @@ Mem (M): {node_mem_total: <6} {node_mem_used: <6} {node_mem_free: <6} {node_mem_ node_list_output.append( '{bold}{node_name: <{node_name_length}} \ {daemon_state_colour}{node_daemon_state: <{daemon_state_length}}{end_colour} {router_state_colour}{node_router_state: <{router_state_length}}{end_colour} {domain_state_colour}{node_domain_state: <{domain_state_length}}{end_colour} \ - {node_domains_count: <4} {node_cpu_count: <5} {node_load: <5} \ - {node_mem_total: <6} {node_mem_used: <6} {node_mem_free: <6} {node_mem_allocated: <6}{end_bold}'.format( + {node_domains_count: <{domains_count_length}} {node_cpu_count: <{cpu_count_length}} {node_load: <{load_length}} \ + {node_mem_total: <{mem_total_length}} {node_mem_used: <{mem_used_length}} {node_mem_free: <{mem_free_length}} {node_mem_allocated: <{mem_alloc_length}}{end_bold}'.format( node_name_length=node_name_length, daemon_state_length=daemon_state_length, router_state_length=router_state_length, domain_state_length=domain_state_length, + domains_count_length=domains_count_length, + cpu_count_length=cpu_count_length, + load_length=load_length, + mem_total_length=mem_total_length, + mem_used_length=mem_used_length, + mem_free_length=mem_free_length, + mem_alloc_length=mem_alloc_length, bold='', end_bold='', daemon_state_colour=daemon_state_colour, diff --git a/client-common/vm.py b/client-common/vm.py index 97a90285..fb96553d 100644 --- a/client-common/vm.py +++ b/client-common/vm.py @@ -561,23 +561,30 @@ def get_list(zk_conn, node, limit): # Determine optimal column widths # Dynamic columns: node_name, node, migrated vm_name_length = 5 - vm_node_length = 8 + vm_uuid_length = 37 + vm_state_length = 6 vm_nets_length = 9 + vm_ram_length = 8 + vm_vcpu_length = 6 + vm_node_length = 8 vm_migrated_length = 10 for vm in vm_list: # vm_name column _vm_name_length = len(vm_name[vm]) + 1 if _vm_name_length > vm_name_length: vm_name_length = _vm_name_length + # vm_state column + _vm_state_length = len(vm_state[vm]) + 1 + if _vm_state_length > vm_state_length: + vm_state_length = _vm_state_length + # vm_nets column + _vm_nets_length = len(','.join(vm_nets[vm])) + 1 + if _vm_nets_length > vm_nets_length: + vm_nets_length = _vm_nets_length # vm_node column _vm_node_length = len(vm_node[vm]) + 1 if _vm_node_length > vm_node_length: vm_node_length = _vm_node_length - # vm_nets column - # Strip off any ANSII chars - _vm_nets_length = len(','.join(vm_nets[vm])) + 1 - if _vm_nets_length > vm_nets_length: - vm_nets_length = _vm_nets_length # vm_migrated column _vm_migrated_length = len(vm_migrated[vm]) + 1 if _vm_migrated_length > vm_migrated_length: @@ -585,15 +592,19 @@ def get_list(zk_conn, node, limit): # Format the string (header) vm_list_output.append( - '{bold}{vm_name: <{vm_name_length}} {vm_uuid: <37} \ -{vm_state_colour}{vm_state: <8}{end_colour} \ + '{bold}{vm_name: <{vm_name_length}} {vm_uuid: <{vm_uuid_length}} \ +{vm_state_colour}{vm_state: <{vm_state_length}}{end_colour} \ {vm_networks: <{vm_nets_length}} \ -{vm_memory: <8} {vm_vcpu: <6} \ +{vm_memory: <{vm_ram_length}} {vm_vcpu: <{vm_vcpu_length}} \ {vm_node: <{vm_node_length}} \ {vm_migrated: <{vm_migrated_length}}{end_bold}'.format( vm_name_length=vm_name_length, - vm_node_length=vm_node_length, + vm_uuid_length=vm_uuid_length, + vm_state_length=vm_state_length, vm_nets_length=vm_nets_length, + vm_ram_length=vm_ram_length, + vm_vcpu_length=vm_vcpu_length, + vm_node_length=vm_node_length, vm_migrated_length=vm_migrated_length, bold=ansiprint.bold(), end_bold=ansiprint.end(), @@ -636,15 +647,19 @@ def get_list(zk_conn, node, limit): vm_nets[vm] = ','.join(net_list) vm_list_output.append( - '{bold}{vm_name: <{vm_name_length}} {vm_uuid: <37} \ -{vm_state_colour}{vm_state: <8}{end_colour} \ + '{bold}{vm_name: <{vm_name_length}} {vm_uuid: <{vm_uuid_length}} \ +{vm_state_colour}{vm_state: <{vm_state_length}}{end_colour} \ {vm_nets_colour}{vm_networks: <{vm_nets_length}}{end_colour} \ -{vm_memory: <8} {vm_vcpu: <6} \ +{vm_memory: <{vm_ram_length}} {vm_vcpu: <{vm_vcpu_length}} \ {vm_node: <{vm_node_length}} \ {vm_migrated: <{vm_migrated_length}}{end_bold}'.format( vm_name_length=vm_name_length, - vm_node_length=vm_node_length, + vm_uuid_length=vm_uuid_length, + vm_state_length=vm_state_length, vm_nets_length=vm_nets_length, + vm_ram_length=vm_ram_length, + vm_vcpu_length=vm_vcpu_length, + vm_node_length=vm_node_length, vm_migrated_length=vm_migrated_length, bold='', end_bold='',