Last active
July 19, 2016 12:13
-
-
Save chrigl/d7eed7c9b878766d187f77d6c52fda79 to your computer and use it in GitHub Desktop.
Detect duplicate floating ips in midonet zookeeper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
from kazoo.client import KazooClient | |
from collections import Counter | |
# id of ext-net | |
DEFAULT_BRIDGE='caf8de33-1059-4473-a2c1-2a62d12294fa' | |
def make_con(hosts='127.0.0.1:2181'): | |
zk = KazooClient(hosts=hosts) | |
zk.start() | |
return zk | |
def get_fips(zk): | |
return Counter(c.split(',')[0] for c in zk.get_children('/midonet/bridges/%s/ip4_mac_map' % DEFAULT_BRIDGE)) | |
con = make_con() | |
res = get_fips(con) | |
warn = False | |
for ip in res: | |
if res[ip] > 1: | |
warn = True | |
print(ip, ":", res[ip]) | |
if warn: | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment