Commit e4752c1b authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Stats per backend from API

Extend Cyclades stats API endpoint with the ability to return stats
only for a backend. Also, add option to include image stats or not.
parent 4565543b
......@@ -36,6 +36,8 @@ from django import http
from django.utils import simplejson as json
from django.conf import settings
from snf_django.lib import api
from snf_django.lib.api import utils, faults
from synnefo.db.models import Backend
from synnefo.admin import stats
......@@ -56,8 +58,32 @@ def get_public_stats(request):
def get_cyclades_stats(request):
_stats = stats.get_cyclades_stats(backend=None, clusters=True,
images = True
backend = None
if request.body:
req = utils.get_request_dict(request)
req_stats = utils.get_attribute(req, "stats", required=True,
# Check backend
backend_id = utils.get_attribute(req_stats, "backend", required=False,
attr_type=(basestring, int))
if backend_id is not None:
backend_id = int(backend_id)
backend = Backend.objects.get(id=backend_id)
except (ValueError, TypeError):
backend = Backend.objects.get(clustername=backend_id)
except Backend.DoesNotExist:
raise faults.BadRequest("Invalid backend '%s'" % backend_id)
include_images = utils.get_attribute(req_stats, "images",
if include_images is not None:
images = include_images
_stats = stats.get_cyclades_stats(backend=backend, clusters=True,
servers=True, resources=True,
networks=True, images=True)
networks=True, images=images)
data = json.dumps(_stats)
return http.HttpResponse(data, status=200, content_type='application/json')
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