OpenStack Migrate Routers and DHCP
Neutron routers and DHCP agents run on network nodes. When you need to take a network node offline for maintenance, you must migrate these services to another network node first. This guide covers migrating L3 routers and DHCP agents in OpenStack 2024.2 Dalmatian.
When to Migrate
- Network node hardware maintenance
- OS patching that requires reboot
- Rebalancing load across network nodes
- Recovering from a failed network node
Prerequisites
| Requirement | Details |
|---|---|
| OpenStack | 2024.2 Dalmatian with Neutron |
| Network nodes | At least 2 network nodes running L3 and DHCP agents |
| Admin access | source openrc admin admin |
Migrating L3 Routers
Step 1: List Routers and Their Agents
# List all L3 agents
openstack network agent list --agent-type l3
# List routers on a specific agent
neutron l3-agent-list-hosting-router <router-id>
# Or with newer CLI:
openstack network agent list --router <router-id>
Step 2: Identify the Source and Target Agent
# Source agent (the one being drained)
SOURCE_AGENT=$(openstack network agent list --agent-type l3 \
--host network-node-01 -f value -c ID)
# Target agent
TARGET_AGENT=$(openstack network agent list --agent-type l3 \
--host network-node-02 -f value -c ID)
Step 3: Move Each Router
# List all routers on the source agent
ROUTERS=$(openstack router list --agent $SOURCE_AGENT -f value -c ID)
# Remove from source and add to target
for ROUTER in $ROUTERS; do
openstack network agent remove router $SOURCE_AGENT $ROUTER
openstack network agent add router $TARGET_AGENT $ROUTER
echo "Moved router $ROUTER"
done
Step 4: Verify
openstack network agent list --router <router-id>
The router should now show on network-node-02.
Migrating DHCP Agents
Step 1: List DHCP Agents and Networks
# List all DHCP agents
openstack network agent list --agent-type dhcp
# List networks on a specific DHCP agent
openstack network list --agent $SOURCE_DHCP_AGENT
Step 2: Identify Agents
SOURCE_DHCP=$(openstack network agent list --agent-type dhcp \
--host network-node-01 -f value -c ID)
TARGET_DHCP=$(openstack network agent list --agent-type dhcp \
--host network-node-02 -f value -c ID)
Step 3: Move Each Network
NETWORKS=$(openstack network list --agent $SOURCE_DHCP -f value -c ID)
for NET in $NETWORKS; do
openstack network agent remove network $SOURCE_DHCP $NET
openstack network agent add network $TARGET_DHCP $NET
echo "Moved network $NET"
done
Step 4: Verify DHCP Migration
openstack network agent list --network <network-id>
Automating with a Script
Create a drain script for maintenance windows:
#!/bin/bash
SOURCE_HOST=$1
TARGET_HOST=$2
# Drain L3 routers
SRC_L3=$(openstack network agent list --agent-type l3 --host $SOURCE_HOST -f value -c ID)
TGT_L3=$(openstack network agent list --agent-type l3 --host $TARGET_HOST -f value -c ID)
for R in $(openstack router list --agent $SRC_L3 -f value -c ID); do
openstack network agent remove router $SRC_L3 $R
openstack network agent add router $TGT_L3 $R
done
# Drain DHCP
SRC_DHCP=$(openstack network agent list --agent-type dhcp --host $SOURCE_HOST -f value -c ID)
TGT_DHCP=$(openstack network agent list --agent-type dhcp --host $TARGET_HOST -f value -c ID)
for N in $(openstack network list --agent $SRC_DHCP -f value -c ID); do
openstack network agent remove network $SRC_DHCP $N
openstack network agent add network $TGT_DHCP $N
done
# Disable agents on source
openstack network agent set --disable $SRC_L3
openstack network agent set --disable $SRC_DHCP
echo "Drained $SOURCE_HOST. Safe to reboot."
Usage:
bash drain-network-node.sh network-node-01 network-node-02
Using HA Routers (Recommended)
For production, use HA routers to avoid manual migration. HA routers automatically failover:
# Enable HA routers globally in neutron.conf
[DEFAULT]
l3_ha = true
max_l3_agents_per_router = 2
# Create an HA router
openstack router create --ha ha-router
With HA routers, Neutron maintains a standby copy on another network node. If the primary fails, VRRP triggers automatic failover in seconds.
DHCP Agent Redundancy
Configure multiple DHCP agents per network:
# /etc/neutron/neutron.conf
[DEFAULT]
dhcp_agents_per_network = 2
This ensures DHCP continues working if one agent goes down.
Troubleshooting
| Issue | Fix |
|---|---|
| Router migration fails | Ensure target agent is alive and has capacity |
| DHCP lease lost after move | VMs renew leases automatically; wait for lease cycle |
| HA router not failing over | Check VRRP and keepalived status on network nodes |
Agent shows xxx (dead) |
Restart the agent: systemctl restart neutron-l3-agent |
Summary
Migrating Neutron routers and DHCP agents is essential for network node maintenance. For production environments, HA routers and multi-agent DHCP eliminate the need for manual migration during planned or unplanned outages.