diff --git a/deployment_scripts/remove_default_networks.sh b/deployment_scripts/remove_default_networks.sh new file mode 100755 index 0000000..15c633e --- /dev/null +++ b/deployment_scripts/remove_default_networks.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# This script removes default network config created in OpenStack as part of a +# Fuel deployment. These networks do not work for instance creation with +# Calico, so need to be removed. + +# OpenStack authentication and authorization requires environment variables +# contained in the openrc file, this will allow us to issue commands via the +# neutron API. +source /root/openrc + +# Details of the default networks/routers created on Fuel deployment of a +# Mirantis OpenStack environment. +DEFAULT_NET=net04 +DEFAULT_NET_EXT=net04_ext +DEFAULT_ROUTER=router04 + +# DEFAULT_NET_EXT is set as the gateway for DEFAULT_ROUTER, we must clear that +# before we can delete the network. +neutron router-gateway-clear $DEFAULT_ROUTER +neutron net-delete $DEFAULT_NET_EXT + +# DEFAULT_NET cannot be deleted until all ports configured on the network have +# been removed. We get details of the configured ports from the "neutron port-list" +# command, whose output is of the form: +# +-----+------+-------------------+-----------------------------------------------+ +# | id | name | mac_address | fixed_ips | +# +-----+------+-------------------+-----------------------------------------------+ +# | foo | | fa:16:3e:ae:70:4e | {"subnet_id": "bar", "ip_address": "a.b.c.d"} | +# +-----+------+-------------------+-----------------------------------------------+ +port_ids=$(neutron port-list | grep "|" | grep -v "fixed_ips" | cut -d " " -f 2) +for port_id in "${port_ids[@]}" +do + neutron port-delete $port_id + if [[ $? != 0 ]]; then + # One of the ports is associated with the interface for the default router. + # This causes port deletion to fail. So we delete the interface on the + # router (this also removes the port). + neutron router-interface-delete $DEFAULT_ROUTER port=$port_id + fi +done + +# We can now delete the default router and the default network. +neutron router-delete $DEFAULT_ROUTER +neutron net-delete $DEFAULT_NET + diff --git a/tasks.yaml b/tasks.yaml index fe62e41..8fc69d0 100644 --- a/tasks.yaml +++ b/tasks.yaml @@ -16,6 +16,14 @@ cmd: ./calico_route_reflector.sh timeout: 60 +# Remove default OpenStack network configuration which doesn't work with Calico. +- role: ['primary-controller'] + stage: post_deployment/150 + type: shell + parameters: + cmd: ./remove_default_networks.sh + timeout: 60 + # Install/configure calico on the compute nodes after cluster deployment. - role: ['compute'] stage: post_deployment