Comment 3 for bug 1793569

Revision history for this message
Chris Dent (cdent) wrote :

Somewhat related to this, some folks @vmware are making a script that talks to the database directly for some "placement audit" needs. Mostly because that's SOP for them and doesn't require dealing with tokens and such. I include it here as an example in case it is useful. This version is oriented towards a pre-nested world, mostly ocata, but sometimes queens.

-=-=-
#!/bin/bash

rp_count=0

rp_count=$(mysql -N -D nova_api -e "select count(id) from resource_providers;")

i=0
while [ $i -lt $rp_count ]
do

#Resource Provider ID
rp_id=$(mysql -N -D nova_api -e "select id from resource_providers limit $i, 1;")

#Resource Provider Name
rp_name=$(mysql -N -D nova_api -e "select name from resource_providers where id = $rp_id")

#Used Resources
cpu_used=$(mysql -N -D nova_api -e "select sum(used) from allocations where resource_class_id=0 and resource_provider_id=$rp_id;")
mem_used=$(mysql -N -D nova_api -e "select sum(used) from allocations where resource_class_id=1 and resource_provider_id=$rp_id;")
disk_used=$(mysql -N -D nova_api -e "select sum(used) from allocations where resource_class_id=2 and resource_provider_id=$rp_id;")

#Total Resources
cpu_total=$(mysql -N -D nova_api -e "select total from inventories where resource_class_id=0 and resource_provider_id=$rp_id;")
mem_total=$(mysql -N -D nova_api -e "select total from inventories where resource_class_id=1 and resource_provider_id=$rp_id;")
disk_total=$(mysql -N -D nova_api -e "select total from inventories where resource_class_id=2 and resource_provider_id=$rp_id;")

#Minimum Resource Value
cpu_min=$(mysql -N -D nova_api -e "select min_unit from inventories where resource_class_id=0 and resource_provider_id=$rp_id;")
mem_min=$(mysql -N -D nova_api -e "select min_unit from inventories where resource_class_id=1 and resource_provider_id=$rp_id;")
disk_min=$(mysql -N -D nova_api -e "select min_unit from inventories where resource_class_id=2 and resource_provider_id=$rp_id;")

#Maximum Resource Value
cpu_max=$(mysql -N -D nova_api -e "select max_unit from inventories where resource_class_id=0 and resource_provider_id=$rp_id;")
mem_max=$(mysql -N -D nova_api -e "select max_unit from inventories where resource_class_id=1 and resource_provider_id=$rp_id;")
disk_max=$(mysql -N -D nova_api -e "select max_unit from inventories where resource_class_id=2 and resource_provider_id=$rp_id;")

#Resource Step Size
cpu_step=$(mysql -N -D nova_api -e "select step_size from inventories where resource_class_id=0 and resource_provider_id=$rp_id;")
mem_step=$(mysql -N -D nova_api -e "select step_size from inventories where resource_class_id=1 and resource_provider_id=$rp_id;")
disk_step=$(mysql -N -D nova_api -e "select step_size from inventories where resource_class_id=2 and resource_provider_id=$rp_id;")

#Allocation Ratio
cpu_ratio=$(mysql -N -D nova_api -e "select allocation_ratio from inventories where resource_class_id=0 and resource_provider_id=$rp_id;")
mem_ratio=$(mysql -N -D nova_api -e "select allocation_ratio from inventories where resource_class_id=1 and resource_provider_id=$rp_id;")
disk_ratio=$(mysql -N -D nova_api -e "select allocation_ratio from inventories where resource_class_id=2 and resource_provider_id=$rp_id;")

echo -e "Resource Provider: $rp_name\n CPU_Used: $cpu_used\n Memory_Used: $mem_used\n Disk_Used: $disk_used\n CPU_Total: $cpu_total\n Memory_Total: $mem_total\n Disk_Total: $disk_total\n CPU_Min: $cpu_min\n Memory_Min: $mem_min\n Disk_Min: $disk_min\n CPU_Max: $cpu_max\n Mem_Max: $mem_max\n Disk_Max: $disk_max\n CPU_Step_Size: $cpu_step\n Memory_Step_Size: $mem_step\n Disk_Step_Size: $disk_step\n CPU_Alloc_Ratio: $cpu_ratio\n Memory_Alloc_Ratio: $mem_ratio\n Disk_Alloc_Ratio: $disk_ratio\n"

i=$[$i+1]
done
-=-=-