<s> from novaclient . v2 import client <EOL> import neat . common as common <EOL> import neat . globals . manager as manager <EOL> from neat . config import * <EOL> import sys <EOL> def vm_hostname ( vm ) : <EOL> return str ( getattr ( vm , '<STR_LIT>' ) ) <EOL> config = read_and_validate_config ( [ DEFAILT_CONFIG_PATH , CONFIG_PATH ] , <EOL> REQUIRED_FIELDS ) <EOL> db = manager . init_db ( config [ '<STR_LIT>' ] ) <EOL> nova = client . Client ( config [ '<STR_LIT>' ] , <EOL> config [ '<STR_LIT>' ] , <EOL> config [ '<STR_LIT>' ] , <EOL> config [ '<STR_LIT>' ] , <EOL> service_type = "<STR_LIT>" ) <EOL> hosts = common . parse_compute_hosts ( config [ '<STR_LIT>' ] ) <EOL> hosts_cpu_total , hosts_cpu_cores , hosts_ram_total = db . select_host_characteristics ( ) <EOL> hosts_cpu_core = dict ( ( host , int ( hosts_cpu_total [ host ] / hosts_cpu_cores [ host ] ) ) <EOL> for host in hosts_cpu_total . keys ( ) ) <EOL> hosts_to_vms = manager . vms_by_hosts ( nova , hosts ) <EOL> vms = [ item for sublist in hosts_to_vms . values ( ) for item in sublist ] <EOL> vms_names = [ ] <EOL> vms_status = { } <EOL> for uuid in vms : <EOL> vm = nova . servers . get ( uuid ) <EOL> vms_names . append ( ( vm . human_id , uuid ) ) <EOL> vms_status [ uuid ] = str ( vm . status ) <EOL> vms_names = sorted ( vms_names ) <EOL> vms_cpu_usage = db . select_last_cpu_mhz_for_vms ( ) <EOL> for vm in vms : <EOL> if not vm in vms_cpu_usage : <EOL> vms_cpu_usage [ vm ] = <NUM_LIT:0> <EOL> vms_ram_usage = manager . vms_ram_limit ( nova , vms ) <EOL> hosts_cpu_usage_hypervisor = db . select_last_cpu_mhz_for_hosts ( ) <EOL> hosts_cpu_usage = { } <EOL> hosts_ram_usage = { } <EOL> for host , vms in hosts_to_vms . items ( ) : <EOL> hosts_cpu_usage [ host ] = hosts_cpu_usage_hypervisor [ host ] + sum ( vms_cpu_usage [ x ] for x in vms ) <EOL> hosts_ram_usage [ host ] = manager . host_used_ram ( nova , host ) <EOL> first = True <EOL> for host in sorted ( hosts_to_vms . keys ( ) ) : <EOL> if not first : <EOL> print "<STR_LIT>" <EOL> first = False <EOL> vms = hosts_to_vms [ host ] <EOL> print '<STR_LIT>' . format ( host , <EOL> hosts_cpu_usage [ host ] , <EOL> hosts_cpu_total [ host ] , <EOL> hosts_ram_usage [ host ] , <EOL> hosts_ram_total [ host ] ) <EOL> for vm , uuid in vms_names : <EOL> if uuid in vms : <EOL> if uuid not in vms_ram_usage : <EOL> vms_ram = <NUM_LIT:0> <EOL> else : <EOL> vms_ram = vms_ram_usage [ uuid ] <EOL> print '<STR_LIT>' . format ( vm , <EOL> vms_status [ uuid ] , <EOL> vms_cpu_usage [ uuid ] , <EOL> hosts_cpu_core [ host ] , <EOL> vms_ram , <EOL> vms_ram ) </s>
