-
-
Save epcim/2e54d00b27de199d257c087fea15ba99 to your computer and use it in GitHub Desktop.
Openstack: Use python-novaclient commands to disassociate/reassociate a floating IP with an instance to correct connectivity issues.
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
!/bin/bash | |
togglefloaterByUUID() { | |
floater=$(nova show $1 | grep network | awk -F "|" '{printf $3}' | awk -F ", " '{printf $NF}' | sed -e 's/ //g' | sed ':a;N;$!ba;s/\n/ /g'); | |
if [ -z $floater ]; then | |
echo $1": No floating IP association found."; | |
else | |
name=$(nova show $1 | grep ' name ' | awk -F "|" '{printf $3}' | sed -e 's/ //g' | sed ':a;N;$!ba;s/\n/ /g'); | |
echo "Dis-associating floating IP" $floater "from instance" $name "("$1")..."; | |
nova floating-ip-disassociate $1 $floater; | |
echo "Done." | |
echo "Associating floating IP" $floater "to instance" $name "("$1")..."; | |
nova floating-ip-associate $1 $floater; | |
echo "Done."; | |
unset name; | |
unset floater; | |
fi | |
} | |
export -f togglefloaterByUUID | |
togglefloaterByIP() { | |
instance=$(nova list | grep $1 | awk -F "|" '{printf $2}'| sed -e 's/ //g' | sed ':a;N;$!ba;s/\n/ /g'); | |
if [ -z $instance ]; then | |
echo $1": No instance association found."; | |
else | |
name=$(nova show $instance | grep ' name ' | awk -F "|" '{printf $3}' | sed -e 's/ //g' | sed ':a;N;$!ba;s/\n/ /g'); | |
echo "Dis-associating floating IP" $1 "from instance" $name "("$instance")..."; | |
nova floating-ip-disassociate $instance $1; | |
echo "Done." | |
echo "Associating floating IP" $1 "to instance" $name "("$instance")..."; | |
nova floating-ip-associate $instance $1; | |
echo "Done."; | |
unset name; | |
unset instance; | |
fi | |
} | |
export -f togglefloaterByIP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment