1 min read

How to delete a neutron load balancer

Catchy title I'm sure however recently I had a chance to deploy a few neutron load balancers and while I found setup to be easy and very intuitive, and quite powerful overall, I found their destruction to be anything but friendly. It would seem that in order to delete a load balancer one must delete a health monitor, all pools and all listeners before the API will accept your delete request. To make matters worse the Horizon dashboard is incapable of deleting any of the required sub components. So to clean up my load balancer mess I came up with a simple script to do all of the needed things.

# Set the lb id
LB_ID="CHANGE THIS TO BE THE ID OF THE LOAD BALANCER YOU WANT TO DELETE"

# delete the lb and all sub components.
LB_DATA=$(neutron --os-user-domain-name Default lbaas-loadbalancer-show ${LB_ID} --format yaml)
LB_LISTENERS_ID=$(echo -e "$LB_DATA" | awk -F'"' '/listeners/ {print $4}')
LB_POOL_ID=$(echo -e "$LB_DATA" | awk -F'"' '/pools/ {print $4}')
LB_HEALTH_ID=$(neutron --os-user-domain-name Default lbaas-pool-show ${LB_POOL_ID} | awk '/healthmonitor_id/ {print $4}')
neutron --os-user-domain-name Default lbaas-listener-delete "${LB_LISTENERS_ID}"
neutron --os-user-domain-name Default lbaas-healthmonitor-delete "${LB_HEALTH_ID}"
neutron --os-user-domain-name Default lbaas-pool-delete "${LB_POOL_ID}"
neutron --os-user-domain-name Default lbaas-loadbalancer-delete "${LB_ID}"

Once this script is done the LB all cleaned up.

Mastodon