Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / admin / views.py @ 19b2c29d

History | View | Annotate | Download (2.6 kB)

1 4a8667dc Christos Stavrakakis
# Copyright 2013 GRNET S.A. All rights reserved.
2 4a8667dc Christos Stavrakakis
#
3 4a8667dc Christos Stavrakakis
# Redistribution and use in source and binary forms, with or
4 4a8667dc Christos Stavrakakis
# without modification, are permitted provided that the following
5 4a8667dc Christos Stavrakakis
# conditions are met:
6 4a8667dc Christos Stavrakakis
#
7 4a8667dc Christos Stavrakakis
#   1. Redistributions of source code must retain the above
8 4a8667dc Christos Stavrakakis
#      copyright notice, this list of conditions and the following
9 4a8667dc Christos Stavrakakis
#      disclaimer.
10 4a8667dc Christos Stavrakakis
#
11 4a8667dc Christos Stavrakakis
#   2. Redistributions in binary form must reproduce the above
12 4a8667dc Christos Stavrakakis
#      copyright notice, this list of conditions and the following
13 4a8667dc Christos Stavrakakis
#      disclaimer in the documentation and/or other materials
14 4a8667dc Christos Stavrakakis
#      provided with the distribution.
15 4a8667dc Christos Stavrakakis
#
16 4a8667dc Christos Stavrakakis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 4a8667dc Christos Stavrakakis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 4a8667dc Christos Stavrakakis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 4a8667dc Christos Stavrakakis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 4a8667dc Christos Stavrakakis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 4a8667dc Christos Stavrakakis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 4a8667dc Christos Stavrakakis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 4a8667dc Christos Stavrakakis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 4a8667dc Christos Stavrakakis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 4a8667dc Christos Stavrakakis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 4a8667dc Christos Stavrakakis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 4a8667dc Christos Stavrakakis
# POSSIBILITY OF SUCH DAMAGE.
28 4a8667dc Christos Stavrakakis
#
29 4a8667dc Christos Stavrakakis
# The views and conclusions contained in the software and
30 4a8667dc Christos Stavrakakis
# documentation are those of the authors and should not be
31 4a8667dc Christos Stavrakakis
# interpreted as representing official policies, either expressed
32 4a8667dc Christos Stavrakakis
# or implied, of GRNET S.A.
33 4a8667dc Christos Stavrakakis
34 4a8667dc Christos Stavrakakis
import logging
35 4a8667dc Christos Stavrakakis
from django import http
36 4a8667dc Christos Stavrakakis
from django.utils import simplejson as json
37 bda47e03 Christos Stavrakakis
from django.conf import settings
38 4a8667dc Christos Stavrakakis
from snf_django.lib import api
39 4a8667dc Christos Stavrakakis
40 bda47e03 Christos Stavrakakis
from synnefo.admin import stats
41 4a8667dc Christos Stavrakakis
42 bda47e03 Christos Stavrakakis
logger = logging.getLogger(__name__)
43 4a8667dc Christos Stavrakakis
44 4a8667dc Christos Stavrakakis
45 4a8667dc Christos Stavrakakis
@api.api_method(http_method='GET', user_required=False, token_required=False,
46 bda47e03 Christos Stavrakakis
                logger=logger, serializations=['json'])
47 1295f78a Kostas Papadimitriou
@api.allow_jsonp()
48 bda47e03 Christos Stavrakakis
def get_public_stats(request):
49 bda47e03 Christos Stavrakakis
    _stats = stats.get_public_stats()
50 bda47e03 Christos Stavrakakis
    data = json.dumps(_stats)
51 1295f78a Kostas Papadimitriou
    return http.HttpResponse(data, status=200, content_type='application/json')
52 4a8667dc Christos Stavrakakis
53 4a8667dc Christos Stavrakakis
54 bda47e03 Christos Stavrakakis
@api.api_method(http_method='GET', user_required=True, token_required=True,
55 bda47e03 Christos Stavrakakis
                logger=logger, serializations=['json'])
56 bda47e03 Christos Stavrakakis
@api.user_in_groups(permitted_groups=settings.ADMIN_STATS_PERMITTED_GROUPS,
57 bda47e03 Christos Stavrakakis
                    logger=logger)
58 bda47e03 Christos Stavrakakis
def get_cyclades_stats(request):
59 bda47e03 Christos Stavrakakis
    _stats = stats.get_cyclades_stats(backend=None, clusters=True,
60 bda47e03 Christos Stavrakakis
                                      servers=True, resources=True,
61 bda47e03 Christos Stavrakakis
                                      networks=True, images=True)
62 bda47e03 Christos Stavrakakis
    data = json.dumps(_stats)
63 bda47e03 Christos Stavrakakis
    return http.HttpResponse(data, status=200, content_type='application/json')