Revision 3524241a snf-cyclades-app/synnefo/logic/reconciliation.py
b/snf-cyclades-app/synnefo/logic/reconciliation.py | ||
---|---|---|
71 | 71 |
|
72 | 72 |
from datetime import datetime, timedelta |
73 | 73 |
|
74 |
from synnefo.db.models import VirtualMachine, Network, BackendNetwork |
|
75 |
from synnefo.util.dictconfig import dictConfig |
|
76 |
from synnefo.util.rapi import GanetiApiError |
|
74 |
from synnefo.db.models import (VirtualMachine, pooled_rapi_client) |
|
75 |
from synnefo.logic.rapi import GanetiApiError |
|
77 | 76 |
from synnefo.logic.backend import get_ganeti_instances |
78 | 77 |
from synnefo.logic import utils |
79 | 78 |
|
... | ... | |
92 | 91 |
# Check time to avoid many rapi calls |
93 | 92 |
if datetime.now() > vm.backendtime + timedelta(seconds=5): |
94 | 93 |
try: |
95 |
job_status = vm.client.GetJobStatus(vm.backendjobid)['status'] |
|
96 |
if job_status in ('queued', 'waiting', 'running'): |
|
97 |
# Server is still building in Ganeti |
|
98 |
continue |
|
99 |
else: |
|
100 |
new_vm = vm.client.GetInstance(utils.id_to_instance_name(i)) |
|
101 |
# Server has just been created in Ganeti |
|
102 |
continue |
|
94 |
with pooled_rapi_client(vm) as c: |
|
95 |
job_status = c.GetJobStatus(vm.backendjobid)['status'] |
|
96 |
if job_status in ('queued', 'waiting', 'running'): |
|
97 |
# Server is still building in Ganeti |
|
98 |
continue |
|
99 |
else: |
|
100 |
c.GetInstance(utils.id_to_instance_name(i)) |
|
101 |
# Server has just been created in Ganeti |
|
102 |
continue |
|
103 | 103 |
except GanetiApiError: |
104 | 104 |
stale.add(i) |
105 | 105 |
else: |
... | ... | |
129 | 129 |
# Check time to avoid many rapi calls |
130 | 130 |
if datetime.now() > vm.backendtime + timedelta(seconds=5): |
131 | 131 |
try: |
132 |
job_info = vm.client.GetJobStatus(job_id = vm.backendjobid) |
|
133 |
if job_info['status'] == 'success': |
|
134 |
unsynced.add((i, D[i], G[i])) |
|
132 |
with pooled_rapi_client(vm) as c: |
|
133 |
job_info = c.GetJobStatus(job_id=vm.backendjobid) |
|
134 |
if job_info['status'] == 'success': |
|
135 |
unsynced.add((i, D[i], G[i])) |
|
135 | 136 |
except GanetiApiError: |
136 | 137 |
pass |
137 | 138 |
|
... | ... | |
149 | 150 |
# Check time to avoid many rapi calls |
150 | 151 |
if datetime.now() > vm.backendtime + timedelta(seconds=5): |
151 | 152 |
try: |
152 |
job_info = vm.client.GetJobStatus(job_id = vm.backendjobid) |
|
153 |
if job_info['status'] == 'error': |
|
154 |
failed.add(i) |
|
153 |
with pooled_rapi_client(vm) as c: |
|
154 |
job_info = c.GetJobStatus(job_id=vm.backendjobid) |
|
155 |
if job_info['status'] == 'error': |
|
156 |
failed.add(i) |
|
155 | 157 |
except GanetiApiError: |
156 | 158 |
failed.add(i) |
157 | 159 |
|
158 | 160 |
return failed |
159 | 161 |
|
160 | 162 |
|
161 |
|
|
162 | 163 |
def get_servers_from_db(): |
163 | 164 |
vms = VirtualMachine.objects.filter(deleted=False, backend__offline=False) |
164 | 165 |
return dict(map(lambda x: (x.id, x.operstate), vms)) |
... | ... | |
268 | 269 |
if nicD['ipv4'] != nicG['ipv4'] or \ |
269 | 270 |
nicD['mac'] != nicG['mac'] or \ |
270 | 271 |
nicD['network'] != nicG['network']: |
271 |
unsynced[i] = (nicsD, nicsG)
|
|
272 |
break
|
|
272 |
unsynced[i] = (nicsD, nicsG) |
|
273 |
break |
|
273 | 274 |
|
274 | 275 |
return unsynced |
275 | 276 |
|
276 | 277 |
# |
277 | 278 |
# Networks |
278 | 279 |
# |
280 |
|
|
281 |
|
|
279 | 282 |
def get_networks_from_ganeti(backend): |
280 | 283 |
prefix = settings.BACKEND_PREFIX_ID + 'net-' |
281 | 284 |
|
282 | 285 |
networks = {} |
283 |
for net in backend.client.GetNetworks(bulk=True): |
|
284 |
if net['name'].startswith(prefix): |
|
285 |
id = utils.id_from_network_name(net['name']) |
|
286 |
networks[id] = net |
|
286 |
with pooled_rapi_client(backend) as c: |
|
287 |
for net in c.GetNetworks(bulk=True): |
|
288 |
if net['name'].startswith(prefix): |
|
289 |
id = utils.id_from_network_name(net['name']) |
|
290 |
networks[id] = net |
|
287 | 291 |
|
288 | 292 |
return networks |
289 | 293 |
|
... | ... | |
299 | 303 |
groups.add(g_name) |
300 | 304 |
return groups |
301 | 305 |
|
302 |
groups = set(backend.client.GetGroups()) |
|
306 |
with pooled_rapi_client(backend) as c: |
|
307 |
groups = set(c.GetGroups()) |
|
303 | 308 |
|
304 | 309 |
hanging = {} |
305 | 310 |
for id, info in GNets.items(): |
Also available in: Unified diff