Revision e77a29ab snf-cyclades-app/synnefo/logic/backend.py
b/snf-cyclades-app/synnefo/logic/backend.py | ||
---|---|---|
30 | 30 |
# documentation are those of the authors and should not be |
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 |
|
|
34 |
import multiprocessing |
|
35 |
|
|
36 | 33 |
from django.conf import settings |
37 | 34 |
from django.db import transaction |
38 | 35 |
from datetime import datetime |
... | ... | |
641 | 638 |
os_name=os_name) |
642 | 639 |
|
643 | 640 |
|
644 |
def get_instances(backend, bulk, queue): |
|
645 |
with pooled_rapi_client(backend) as client: |
|
646 |
instances = client.GetInstances(bulk=bulk) |
|
647 |
queue.put(instances) |
|
648 |
|
|
649 |
|
|
650 |
def get_nodes(backend, bulk, queue): |
|
651 |
with pooled_rapi_client(backend) as client: |
|
652 |
nodes = client.GetNodes(bulk=bulk) |
|
653 |
queue.put(nodes) |
|
654 |
|
|
655 |
|
|
656 |
def get_jobs(backend, bulk, queue): |
|
657 |
with pooled_rapi_client(backend) as client: |
|
658 |
nodes = client.GetJobs() |
|
659 |
queue.put(nodes) |
|
660 |
|
|
661 |
|
|
662 |
def get_ganeti_instances(backend=None, bulk=False): |
|
663 |
backends = get_backends(backend) |
|
664 |
return get_from_ganeti(backends, get_instances, bulk) |
|
665 |
|
|
666 |
|
|
667 |
def get_ganeti_jobs(backend=None, bulk=False): |
|
668 |
backends = get_backends(backend) |
|
669 |
return get_from_ganeti(backends, get_jobs, bulk) |
|
670 |
|
|
671 |
|
|
672 |
def get_ganeti_nodes(backend=None, bulk=False): |
|
673 |
backends = get_backends(backend) |
|
674 |
return get_from_ganeti(backends, get_nodes, bulk) |
|
641 |
def get_instances(backend, bulk=True): |
|
642 |
with pooled_rapi_client(backend) as c: |
|
643 |
return c.GetInstances(bulk=bulk) |
|
675 | 644 |
|
676 | 645 |
|
677 |
def get_from_ganeti(backends, callback, bulk): |
|
678 |
queue = multiprocessing.Queue() |
|
679 |
processes = [] |
|
680 |
for backend in backends: |
|
681 |
p = multiprocessing.Process(target=callback, |
|
682 |
args=(backend, bulk, queue)) |
|
683 |
processes.append((p, backend)) |
|
684 |
p.start() |
|
685 |
for (p, b) in processes: |
|
686 |
p.join() |
|
687 |
if p.exitcode != 0: |
|
688 |
raise Exception("Error getting instances from backend %s" % b) |
|
689 |
items = [] |
|
690 |
for p in processes: |
|
691 |
items.extend(queue.get()) |
|
692 |
return items |
|
693 |
|
|
694 |
|
|
695 |
## |
|
696 |
## |
|
697 |
## |
|
646 |
def get_nodes(backend, bulk=True): |
|
647 |
with pooled_rapi_client(backend) as c: |
|
648 |
return c.GetNodes(bulk=bulk) |
|
698 | 649 |
|
699 | 650 |
|
700 |
def get_backends(backend=None): |
|
701 |
if backend: |
|
702 |
if backend.offline: |
|
703 |
return [] |
|
704 |
return [backend] |
|
705 |
return Backend.objects.filter(offline=False) |
|
651 |
def get_jobs(backend): |
|
652 |
with pooled_rapi_client(backend) as c: |
|
653 |
return c.GetJobs() |
|
706 | 654 |
|
707 | 655 |
|
708 | 656 |
def get_physical_resources(backend): |
... | ... | |
711 | 659 |
Get the resources of a backend as reported by the backend (not the db). |
712 | 660 |
|
713 | 661 |
""" |
714 |
nodes = get_ganeti_nodes(backend, bulk=True)
|
|
662 |
nodes = get_nodes(backend, bulk=True) |
|
715 | 663 |
attr = ['mfree', 'mtotal', 'dfree', 'dtotal', 'pinst_cnt', 'ctotal'] |
716 | 664 |
res = {} |
717 | 665 |
for a in attr: |
Also available in: Unified diff