Skip to content

Instantly share code, notes, and snippets.

@BlackDex
Last active February 14, 2019 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BlackDex/222cafa7f1a616cc54f18d0fb877616b to your computer and use it in GitHub Desktop.
Save BlackDex/222cafa7f1a616cc54f18d0fb877616b to your computer and use it in GitHub Desktop.
Useful OpenStack CLI

Filter volumes per availability zone

# Using openstack-cli with jq (Since openstack-cli isn't able to filter or show the az)
AZ="zone" ; for volume_id in $(openstack volume list -fvalue --quote=none --all-projects --sort-column=ID -cID); do openstack volume show -fjson "${volume_id}" | jq -r '. | select(.availability_zone == "'"${AZ}"'") | "\(.id)"'; done

# Using cinder-cli which has the option to show the az, but can't filter if using volumev2
AZ="zone" ; cinder --os-volume-api-version=2 list --all-tenants --sort id:asc --fields id,availability_zone | grep "${AZ}" | awk '{print $2}'

# Get all instance ID's which are using an ephemeral image
openstack server list --all-projects --limit -1 --no-name-lookup --sort-column ID -fjson | jq -r '.[] | select(.Image != "") | "\(.ID)"'

Some useful links for scripting
https://github.com/stedolan/jq/wiki/Cookbook
https://lzone.de/cheat-sheet/jq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment