Created
May 22, 2020 19:27
-
-
Save tykeal/fc26be40c60fe9777bbcea0759b930c6 to your computer and use it in GitHub Desktop.
OpenStack cloud "switcher"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# requires python yq (pip install --user yq) | |
# requires openstack installed into a virtual env, adjust path accordingling | |
# requires that you use ~/.config/openstack/secure.yaml for all the clouds that you | |
# have passwords for. Adjust appropriately | |
# openstack | |
cloud() { | |
# export our cloud | |
export OS_CLOUD="$1" | |
# activate openstack client | |
alias openstack=~/venv/current-openstack/bin/openstack | |
# shellcheck disable=SC1090 | |
source <(openstack complete) | |
# Set the NETID | |
# shellcheck disable=SC2155 | |
export NETID=$(openstack network list | awk "/${OS_CLOUD}/ {print \$2}") | |
} | |
_cloud_completions() { | |
if [ "${#COMP_WORDS[@]}" != "2" ]; then | |
return | |
fi | |
# shellcheck disable=SC2207 | |
COMPREPLY=($(compgen -W "$(yq -y '.clouds | keys' ~/.config/openstack/secure.yaml | cut -c 3- | tr '\n' ' ' | sed 's/ $//')" -- "${COMP_WORDS[1]}")) | |
} | |
complete -F _cloud_completions cloud |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment