Commit b7724861 authored by Christos Stavrakakis's avatar Christos Stavrakakis

reconciliation:avoid double asking Ganeti

Modify reconcile-servers to not communicate 2 times with Ganeti
to get the operstate and the NICs of the VMs. Merge this two one
call.
parent 6834797e
......@@ -113,10 +113,10 @@ class Command(BaseCommand):
self._process_args(options)
D = reconciliation.get_servers_from_db()
G = reconciliation.get_instances_from_ganeti()
G, GNics = reconciliation.get_instances_from_ganeti()
DBNics = reconciliation.get_nics_from_db()
GNics = reconciliation.get_nics_from_ganeti()
#
# Detect problems
#
......
......@@ -168,6 +168,7 @@ def get_servers_from_db():
def get_instances_from_ganeti():
ganeti_instances = get_ganeti_instances(bulk=True)
snf_instances = {}
snf_nics = {}
prefix = settings.BACKEND_PREFIX_ID
for i in ganeti_instances:
......@@ -185,8 +186,9 @@ def get_instances_from_ganeti():
continue
snf_instances[id] = i['oper_state']
snf_nics[id] = get_nics_from_instance(i)
return snf_instances
return snf_instances, snf_nics
#
# Nics
......@@ -212,20 +214,24 @@ def get_nics_from_ganeti():
i['name'])
continue
ips = zip(itertools.repeat('ipv4'), i['nic.ips'])
macs = zip(itertools.repeat('mac'), i['nic.macs'])
networks = zip(itertools.repeat('network'), i['nic.networks'])
# modes = zip(itertools.repeat('mode'), i['nic.modes'])
# links = zip(itertools.repeat('link'), i['nic.links'])
# nics = zip(ips,macs,modes,networks,links)
nics = zip(ips, macs, networks)
nics = map(lambda x:dict(x), nics)
nics = dict(enumerate(nics))
snf_instances_nics[id] = nics
snf_instances_nics[id] = get_nics_from_instance(i)
return snf_instances_nics
def get_nics_from_instance(i):
ips = zip(itertools.repeat('ipv4'), i['nic.ips'])
macs = zip(itertools.repeat('mac'), i['nic.macs'])
networks = zip(itertools.repeat('network'), i['nic.networks'])
# modes = zip(itertools.repeat('mode'), i['nic.modes'])
# links = zip(itertools.repeat('link'), i['nic.links'])
# nics = zip(ips,macs,modes,networks,links)
nics = zip(ips, macs, networks)
nics = map(lambda x: dict(x), nics)
nics = dict(enumerate(nics))
return nics
def get_nics_from_db():
"""Get network interfaces for each vm in DB.
......
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