cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
cm.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @COPYRIGHT_begin
3 #
4 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # @COPYRIGHT_end
19 
20 ##
21 # @package src.wi.views.admin_cm.cm
22 # @author Krzysztof Danielowski
23 # @author Piotr W√≥jcik
24 # @date 17.10.2011
25 #
26 
27 from wi.commontags.templatetags.templatetags import filesizeformatmb
28 from wi.utils import messages_ajax
29 from wi.utils.decorators import admin_cm_permission, django_view
30 from wi.utils.messages_ajax import ajax_request
31 from wi.utils.states import cm_active_reversed as cm_states, node_states_reversed as node_states
32 from wi.utils.views import prep_data
33 
34 
35 @django_view
36 @ajax_request
37 @admin_cm_permission
38 ##
39 #
40 # Ajax view for fetching CM data (quotas etc.).
41 #
42 def cma_ajax_get_cm_data(request):
43  if request.method == 'GET':
44  rest_data = prep_data({'cm_data': 'admin_cm/cluster/get_data/',
45  'nodes': 'admin_cm/node/get_list/'
46  }, request.session)
47 
48  data = rest_data['cm_data']
49 
50  total_cpu = 0
51  total_mem = 0
52  free_cpu = 0
53  free_mem = 0
54  for node in rest_data['nodes']:
55  node['stateName'] = unicode(node_states[node['state']])
56  if node['state'] == 1:
57  free_cpu += node['cpu_free']
58  free_mem += node['memory_free']
59  total_cpu += node['cpu_total']
60  total_mem += node['memory_total']
61 
62  data['free_cpu'] = free_cpu
63  data['free_mem'] = filesizeformatmb(free_mem)
64  data['total_cpu'] = total_cpu
65  data['total_mem'] = filesizeformatmb(total_mem)
66 
67  data['stateName'] = unicode(cm_states[data['state']])
68 
69  return messages_ajax.success(data)
70