Thursday, December 24, 2015

How to randomly distribute networks to all dhcp-agents

If you are have an issue with DHCP agents, one of the solutions is to recreate DHCP ports.  Here the small howto:

Step 1: remove all networks from all DHCP agents:

 for a in `neutron agent-list|grep dhcp|awk '{print $2}'`;do neutron net-list|awk '{print $2}'|xargs -I I neutron dhcp-agent-network-remove $a I ;done

Step 2: Throw networks randomly on DHCP agents:


neutron agent-list|grep DHCP|grep True|grep ':-)'|awk '{print $2}' > /tmp/dhcp_agents
for net in `neutron net-list|awk '{print $2}'`;do neutron dhcp-agent-network-add `sort -R /tmp/dhcp_agents|tail -1` $net ;done

Note: This will works only in homogenous network settings (all dhcp-agents are equal).

You could made it one-liner if you wants, but looped calls for neutron agent-list is not a good idea.

No comments:

Post a Comment