Commit 97090cd9 authored by Sigmund Augdal's avatar Sigmund Augdal

Added script to remove entries for deleted VMs from mac/address binding table in etcd

parent 8fb38e5d
import etcd
from nova_router import neighbors
from scvmm_client import odata
import logging
def main():
key = "/home/sigmunda/Devel/nova/etcd_client.key"
cert = "/home/sigmunda/Devel/nova/etcd_client.crt"
cacert = "/home/sigmunda/Devel/nova/etcd_ca.crt"
vmm_baseurl = 'https://srv-spf-99.bs.unsi.no:8090/SC2012R2/VMM/Microsoft.Management.Odata.svc'
username = 'bs-unsi\spfsvc'
password = 'Laste8il'
logging.basicConfig(level=logging.INFO)
etcd_client = etcd.Etcd("158.38.213.2", ssl_key=key, ssl_cert=cert, verify=cacert)
vmm_client = odata.VMMClient(vmm_baseurl, username, password)
nics = set()
for nic in vmm_client.query_collection("VirtualNetworkAdapters"):
mac = nic.properties["MACAddress"]
if mac is not None:
nics.add(mac.lower())
for entry in etcd_client.list("/nova/iaas/instances"):
if not entry.dir:
next
mac = entry.key.split("/")[-1].lower()
if not mac in nics:
for addrtype in (neighbors.V4, neighbors.V6_LL, neighbors.V6_PUB):
ipaddr = neighbors.get_ipaddress_from_mac(etcd_client, mac, addrtype)
if ipaddr is not None:
logging.info("Removing address {} from mac {}".format(ipaddr, mac))
neighbors.remove_pair(etcd_client, mac, ipaddr, addrtype)
else:
logging.debug("found owner for mac {}".format(mac))
if __name__ == '__main__':
main()
......@@ -10,6 +10,7 @@ requires = [
'daemonize',
'pytest',
'mock',
'scvmm-client-py',
'pyroute2',
]
......@@ -26,5 +27,6 @@ setup(name='router-services',
tests_require=requires,
dependency_links=[
'git+https://github.com/sigmunau/etcd-py.git#egg=etcd-py-0.0.6',
'git+https://scm.uninett.no/nova/scvmm_client_py.git#egg=scvmm-client-py-0.1',
],
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment