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.

Wednesday, December 16, 2015

Converting hg repository to git

(offtopic for openstack, but important task for devops around CI).

Our CI wants git to build proper debian packages. We do not use mercurial in any way and all our internals are in gits. But external software we using is published in mercurial and do not provide pre-build packages.

We have decided to convert external hg to local git, and then proceed as usual.

Here the simple way to convert hg repository to git:
1) Install mercurial and hg-fast-export:
    sudo apt-get install -y mercurial hg-fast-export
2)  Clone hg repository to some temporal place: (e.g. /tmp):
    hg clone https://bitbucket.org/some/repo
3) Create new git repository in your gitlab/github
4) Create local empty git repository:
    mkdir ~/git/some_repo
    cd ~/git/some_repo
    git init
5) Run hg-fast-export:
    cd ~/git/some_repo
    hg-fast-export -r /tmp/some/repo
6) Add remote origin to git:
    git remote add origin git@internal_git:some_repo.git
7) Push changes:
    git push --all
8) Push tags:
    git push --tags

Thats all. No more strange thoughts about 'How to force intercourse between debian-jenkins-glue & mercurial'.