Revision 491d2a31 snf-cyclades-app/synnefo/admin/views.py
b/snf-cyclades-app/synnefo/admin/views.py | ||
---|---|---|
36 | 36 |
from django.utils import simplejson as json |
37 | 37 |
from django.conf import settings |
38 | 38 |
from snf_django.lib import api |
39 |
from snf_django.lib.api import utils, faults |
|
40 |
from synnefo.db.models import Backend |
|
39 | 41 |
|
40 | 42 |
from synnefo.admin import stats |
41 | 43 |
|
... | ... | |
56 | 58 |
@api.user_in_groups(permitted_groups=settings.ADMIN_STATS_PERMITTED_GROUPS, |
57 | 59 |
logger=logger) |
58 | 60 |
def get_cyclades_stats(request): |
59 |
_stats = stats.get_cyclades_stats(backend=None, clusters=True, |
|
61 |
images = True |
|
62 |
backend = None |
|
63 |
if request.body: |
|
64 |
req = utils.get_request_dict(request) |
|
65 |
req_stats = utils.get_attribute(req, "stats", required=True, |
|
66 |
attr_type=dict) |
|
67 |
# Check backend |
|
68 |
backend_id = utils.get_attribute(req_stats, "backend", required=False, |
|
69 |
attr_type=(basestring, int)) |
|
70 |
if backend_id is not None: |
|
71 |
try: |
|
72 |
try: |
|
73 |
backend_id = int(backend_id) |
|
74 |
backend = Backend.objects.get(id=backend_id) |
|
75 |
except (ValueError, TypeError): |
|
76 |
backend = Backend.objects.get(clustername=backend_id) |
|
77 |
except Backend.DoesNotExist: |
|
78 |
raise faults.BadRequest("Invalid backend '%s'" % backend_id) |
|
79 |
include_images = utils.get_attribute(req_stats, "images", |
|
80 |
required=False, |
|
81 |
attr_type=bool) |
|
82 |
if include_images is not None: |
|
83 |
images = include_images |
|
84 |
|
|
85 |
_stats = stats.get_cyclades_stats(backend=backend, clusters=True, |
|
60 | 86 |
servers=True, resources=True, |
61 |
networks=True, images=True)
|
|
87 |
networks=True, images=images)
|
|
62 | 88 |
data = json.dumps(_stats) |
63 | 89 |
return http.HttpResponse(data, status=200, content_type='application/json') |
Also available in: Unified diff