Revision 4a8667dc

b/snf-cyclades-app/synnefo/admin/urls.py
1
# Copyright 2013 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

  
34
from django.conf.urls.defaults import url, patterns
35
from synnefo.admin import views
36
from django.http import Http404
37

  
38

  
39
def index(request):
40
    raise Http404
41

  
42
urlpatterns = patterns('',
43
    url(r'^$', index),
44
    url(r'^stats$', views.get_stats),
45
)
b/snf-cyclades-app/synnefo/admin/views.py
1
# Copyright 2013 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

  
34
import logging
35
from django import http
36
from django.utils import simplejson as json
37
from synnefo.db.models import VirtualMachine, Network
38
from django.db.models import Count, Sum
39
from snf_django.lib import api
40
from copy import copy
41

  
42

  
43
log = logging.getLogger(__name__)
44

  
45

  
46
@api.api_method(http_method='GET', user_required=False, token_required=False,
47
                logger=log)
48
def get_stats(request):
49
    stats = get_statistics()
50
    data = json.dumps(stats)
51
    return http.HttpResponse(data, status=200)
52

  
53

  
54
def get_statistics():
55
    # VirtualMachines
56
    vm_objects = VirtualMachine.objects
57
    servers = vm_objects.values("deleted", "operstate")\
58
                        .annotate(count=Count("id"),
59
                                  cpu=Sum("flavor__cpu"),
60
                                  ram=Sum("flavor__ram"),
61
                                  disk=Sum("flavor__disk"))
62
    zero_stats = {"count": 0, "cpu": 0, "ram": 0, "disk": 0}
63
    server_stats = {}
64
    for state in VirtualMachine.RSAPI_STATE_FROM_OPER_STATE.values():
65
        server_stats[state] = copy(zero_stats)
66

  
67
    for stats in servers:
68
        deleted = stats.pop("deleted")
69
        operstate = stats.pop("operstate")
70
        state = VirtualMachine.RSAPI_STATE_FROM_OPER_STATE.get(operstate)
71
        if deleted:
72
            for key in zero_stats.keys():
73
                server_stats["DELETED"][key] += stats.get(key, 0)
74
        elif state:
75
            for key in zero_stats.keys():
76
                server_stats[state][key] += stats.get(key, 0)
77

  
78
    #Networks
79
    net_objects = Network.objects
80
    networks = net_objects.values("deleted", "state")\
81
                          .annotate(count=Count("id"))
82
    zero_stats = {"count": 0}
83
    network_stats = {}
84
    for state in Network.RSAPI_STATE_FROM_OPER_STATE.values():
85
        network_stats[state] = copy(zero_stats)
86

  
87
    for stats in networks:
88
        deleted = stats.pop("deleted")
89
        state = stats.pop("state")
90
        state = Network.RSAPI_STATE_FROM_OPER_STATE.get(state)
91
        if deleted:
92
            for key in zero_stats.keys():
93
                network_stats["DELETED"][key] += stats.get(key, 0)
94
        elif state:
95
            for key in zero_stats.keys():
96
                network_stats[state][key] += stats.get(key, 0)
97

  
98
    statistics = {"servers": server_stats,
99
                  "networks": network_stats}
100
    return statistics
b/snf-cyclades-app/synnefo/api/services.py
138 138
        ],
139 139
        'resources': {},
140 140
    },
141

  
142
    'cyclades_admin': {
143
        'type': 'admin',
144
        'component': 'cyclades',
145
        'prefix': 'admin',
146
        'public': True,
147
        'endpoints': [
148
            {'versionId': '',
149
             'publicURL': None},
150
        ],
151
        'resources': {},
152
    },
141 153
}
b/snf-cyclades-app/synnefo/app_settings/urls.py
40 40
from synnefo.cyclades_settings import (
41 41
    BASE_URL, BASE_HOST, BASE_PATH, COMPUTE_PREFIX, VMAPI_PREFIX,
42 42
    PLANKTON_PREFIX, HELPDESK_PREFIX, UI_PREFIX, ASTAKOS_BASE_URL,
43
    USERDATA_PREFIX, ASTAKOS_BASE_PATH, BASE_ASTAKOS_PROXY_PATH,
43
    USERDATA_PREFIX, ADMIN_PREFIX, ASTAKOS_BASE_PATH, BASE_ASTAKOS_PROXY_PATH,
44 44
    ASTAKOS_ACCOUNTS_PREFIX, ASTAKOS_VIEWS_PREFIX, PROXY_USER_SERVICES,
45 45
    cyclades_services)
46 46

  
47
from urlparse import urlparse
48 47
from functools import partial
49 48

  
50 49

  
......
56 55
    (prefix_pattern(PLANKTON_PREFIX), include('synnefo.plankton.urls')),
57 56
    (prefix_pattern(COMPUTE_PREFIX), include('synnefo.api.urls')),
58 57
    (prefix_pattern(USERDATA_PREFIX), include('synnefo.userdata.urls')),
58
    (prefix_pattern(ADMIN_PREFIX), include('synnefo.admin.urls')),
59 59
)
60 60

  
61 61
cyclades_patterns += patterns('',
b/snf-cyclades-app/synnefo/cyclades_settings.py
59 59
HELPDESK_PREFIX = get_path(cyclades_services, 'cyclades_helpdesk.prefix')
60 60
UI_PREFIX = get_path(cyclades_services, 'cyclades_ui.prefix')
61 61
USERDATA_PREFIX = get_path(cyclades_services, 'cyclades_userdata.prefix')
62
ADMIN_PREFIX = get_path(cyclades_services, 'cyclades_admin.prefix')
62 63

  
63 64
COMPUTE_ROOT_URL = join_urls(BASE_URL, COMPUTE_PREFIX)
64 65

  

Also available in: Unified diff