Last active
November 10, 2021 15:42
-
-
Save Richard-Barrett/dc2641e94c59f1655245d04e100efc96 to your computer and use it in GitHub Desktop.
Migrate OpenStack L3 and DHCP Agents on OpenStack Kolla-Ansible
This file contains 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 | |
# ============================================= | |
# Created by: Richard Barrett | |
# Date Created: 11/09/2021 | |
# Purpose: Migrate OpenStack L3 Agents | |
# Company: Charter Spectrum | |
# ============================================= | |
# Documentation: | |
# ======================================================================================== | |
# https://docs.openstack.org/kolla-ansible/latest/user/adding-and-removing-hosts.html | |
# ======================================================================================== | |
#set -e | |
# keep track of the last executed command | |
#trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG | |
# echo an error message before exiting | |
#trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT | |
# System Variables | |
# ================ | |
# System Functions | |
# ================ | |
# List Networking Agents Function | |
function list_networking_agents { | |
while true; do | |
read -p "Would you like to list all OpenStack Networking Agents (yes/no)?" yn | |
case $yn in | |
[Yy]* ) echo "======================================="; \ | |
echo " Listing Networking Agents..."; \ | |
echo "======================================="; \ | |
openstack network agent list --fit-width; \ | |
echo "======================================="; \ | |
break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
} | |
# Migrate OpenStack L3 Agents Prompt | |
function migrate_openstack_l3_agents { | |
while true; do | |
echo "What is the source host L3 agent migration from?" | |
read source_host | |
echo "What is the target host L3 agent migration to?" | |
read target_host | |
read -p "Would you like to migrate all OpenStack L3 Agents (yes/no)?" yn | |
case $yn in | |
[Yy]* ) echo "======================================="; \ | |
echo " Migrating L3 Agents..."; \ | |
echo "======================================="; \ | |
l3_id=$(openstack network agent list --host $source_host --agent-type l3 -f value -c ID); \ | |
target_l3_id=$(openstack network agent list --host target_host --agent-type l3 -f value -c ID); \ | |
openstack router list --agent $l3_id -f value -c ID | while read router; do \ | |
openstack network agent remove router $l3_id $router --l3; \ | |
openstack network agent add router $target_l3_id $router --l3; \ | |
done; \ | |
openstack network agent set $l3_id --disable; \ | |
echo "======================================="; \ | |
break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
} | |
# Migrate OpenStack DHCP Agents Prompt | |
function migrate_openstack_dhcp_agents { | |
while true; do | |
echo "What is the source host DHCP agent migration from?" | |
read source_host | |
echo "What is the target host DHCP agent migration to?" | |
read target_host | |
read -p "Would you like to migrate all OpenStack DHCP Agents (yes/no)?" yn | |
case $yn in | |
[Yy]* ) echo "======================================="; \ | |
echo " Migrating DHCP Agents..."; \ | |
echo "======================================="; \ | |
dhcp_id=$(openstack network agent list --host $source_host --agent-type dhcp -f value -c ID); \ | |
target_dhcp_id=$(openstack network agent list --host $target_host --agent-type dhcp -f value -c ID); \ | |
openstack network list --agent $dhcp_id -f value -c ID | while read network; do \ | |
openstack network agent remove network $dhcp_id $network --dhcp \ | |
openstack network agent add network $target_dhcp_id $network --dhcp \ | |
done; \ | |
echo "======================================="; \ | |
break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
} | |
list_networking_agents | |
migrate_openstack_l3_agents | |
migrate_openstack_dhcp_agents |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment