Skip to content

Instantly share code, notes, and snippets.

@jjo
Created October 1, 2014 19:03
Show Gist options
  • Save jjo/9d2033a6a999ed8db24d to your computer and use it in GitHub Desktop.
Save jjo/9d2033a6a999ed8db24d to your computer and use it in GitHub Desktop.
vip-units.sh: show juju unit holding the vip for each passed service, or --all // keywords: juju, openstack, ha, vip
#!/bin/bash
# vip-units.sh: show juju unit holding the vip for each passed service, or --all
# it forks for each service, to lower result times
#
# Author: JuanJo Ciarlante <[email protected]>
# License: GPLv3
#
# Show unit holding the vip, unfortunately can't use "crm foo"
# as it shows hostnames, which are useless for LXC over MaaS
services=${*:?missing service(s), eg: keystone cinder}
vip_unit() {
# get vip from services config
local vip=$(juju get $1 | python -c 'import yaml, sys;print yaml.load(sys.stdin)["settings"].get("vip", {}).get("value", "")')
test -n "$vip" || continue
# sweep on each unit, grepping ip addresses for $vip
juju run --timeout 5s --service=$1 "ip -o -4 a|fgrep $vip && echo unit:$vip \$JUJU_UNIT_NAME"|sed -n 's/.*unit://p'
}
# main()
if [ "$1" == '--all' ];then
# All services from juju status, skipped if they don't have a 'vip' setting
services=$(juju status |python -c 'import yaml,sys;print " ".join(yaml.load(sys.stdin)["services"].keys())')
fi
for i in $services; do
vip_unit $i &
done | sort
@jjo
Copy link
Author

jjo commented Oct 1, 2014

Related to deploying Openstack HA with Juju: https://wiki.ubuntu.com/ServerTeam/OpenStackHA

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