Skip to content

Instantly share code, notes, and snippets.

@dosaboy
Last active March 29, 2019 10:22
Show Gist options
  • Save dosaboy/beb721fe56bf8e0ed796910f5ef134bd to your computer and use it in GitHub Desktop.
Save dosaboy/beb721fe56bf8e0ed796910f5ef134bd to your computer and use it in GitHub Desktop.
#!/bin/bash -eu
# To get a list of all your compute hosts do:
#
# openstack compute service list --service nova-compute -c Host -f value
#
# To get a list of UUIDs of all vms running on a host do:
#
# openstack server list --host <hostname> -c ID -f value
#
# Add your vm block devices to this list with format [<vm uuid>]=<block name>
declare -A VM_DEVS=(
# Add your info here e.g. each line must look like [<vm uuid>]=<device name>
)
((${#VM_DEVS[@]})) || { echo "You must add your vm block dev info to the script array before running it"; exit 1; }
(($#==1)) || \
{ echo "Usage: `basename $0` <compute host>"; exit 1; }
COMPUTE_HOSTNAME=$1
NUM_SEC_SAMPLES=600 # i.e. 10 mins
d_results="`mktemp -d`"
echo "Putting results in $d_results"
echo -n "Fetching list of vms on host $COMPUTE_HOSTNAME..."
readarray -t vms<<<"`openstack server list --host $COMPUTE_HOSTNAME --all-projects -c ID -f value`"
if ((${#vms[@]}==1)) && [ -z "${vms[0]}" ]; then
echo -e "\nThere are no vms on host '$COMPUTE_HOSTNAME' - exiting"
else
echo "Found ${#vms[@]} vms"
read -p "Proceed to execute script on each vm in parallel? [ENTER]"
for vm in "${vms[@]}"; do
device=${VM_DEVS[$vm]:-''}
[ -n "$device" ] || { echo "Skipping vm $vm since it doesn't appear to have a block device entry in VM_DEVS"; continue; }
[ -r "./get_server_iops.sh" ] || { echo "script ./get_server_iops.sh not found"; exit 1; }
(./get_server_iops.sh $vm $device $NUM_SEC_SAMPLES &> $d_results/$vm.$device) &
done
echo "Waiting for actions to complete (check files in $d_results to see progress.)"
wait
echo "Done - results can be found in $d_results"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment