Revision b12ab2d0 snf-cyclades-app/synnefo/logic/backend.py
b/snf-cyclades-app/synnefo/logic/backend.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
import json |
35 |
import multiprocessing |
|
36 |
import itertools |
|
37 | 35 |
|
38 | 36 |
from django.conf import settings |
39 | 37 |
from django.db import transaction |
... | ... | |
643 | 641 |
os_name=os_name) |
644 | 642 |
|
645 | 643 |
|
646 |
def get_instances(backend, bulk, queue): |
|
647 |
with pooled_rapi_client(backend) as client: |
|
648 |
instances = client.GetInstances(bulk=bulk) |
|
649 |
queue.put(instances) |
|
650 |
|
|
651 |
|
|
652 | 644 |
def get_ganeti_instances(backend=None, bulk=False): |
653 | 645 |
instances = [] |
654 |
backends = get_backends(backend) |
|
655 |
queue = multiprocessing.Queue() |
|
656 |
processes = [] |
|
657 |
for backend in backends: |
|
658 |
p = multiprocessing.Process(target=get_instances, |
|
659 |
args=(backend, bulk, queue)) |
|
660 |
processes.append(p) |
|
661 |
p.start() |
|
662 |
[p.join() for p in processes] |
|
663 |
[instances.extend(queue.get()) for p in processes] |
|
664 |
return instances |
|
646 |
for backend in get_backends(backend): |
|
647 |
with pooled_rapi_client(backend) as client: |
|
648 |
instances.append(client.GetInstances(bulk=bulk)) |
|
649 |
|
|
650 |
return reduce(list.__add__, instances, []) |
|
665 | 651 |
|
666 | 652 |
|
667 | 653 |
def get_ganeti_nodes(backend=None, bulk=False): |
Also available in: Unified diff