cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
farm.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 from clm.utils.decorators import user_log, cm_request
21 from clm.utils.cm import CM
22 from clm.models.user import User
23 from common.states import group_states
24 from clm.utils.exception import CLMException
25 
26 
27 @user_log(log=True, pack=False)
28 ##
29 #
30 # @clmview_user
31 #
32 def create(cm_id, caller_id, **data):
33  user = User.get(caller_id)
34  groups = list(user.group_set.filter(usergroup__status__exact=group_states['ok']).values_list('id', flat=True))
35  return CM(cm_id).send_request("user/farm/create/", caller_id=caller_id, groups=groups, **data)
36 
37 
38 @user_log(log=True, pack=False)
39 @cm_request
40 ##
41 #
42 # @clmview_user
43 # @cm_request_transparent{user.farm.destroy()}
44 #
45 def destroy(cm_response, **data):
46  return cm_response
47 
48 
49 @user_log(log=True)
50 @cm_request
51 ##
52 #
53 # @clmview_user
54 # @cm_request_transparent{user.farm.get_list()}
55 #
56 def get_list(cm_response, **data):
57  d = {}
58  r = cm_response['data']
59  for farm in r:
60  if farm['user_id'] not in d:
61  try:
62  u = User.objects.get(pk=farm['user_id'])
63  d[farm['user_id']] = u.first + " " + u.last
64  except User.DoesNotExist:
65  raise CLMException('user_get')
66  farm['owner'] = d[farm['user_id']]
67  return r
68 
69 
70 @user_log(log=True, pack=False)
71 @cm_request
72 ##
73 #
74 # @clmview_user
75 # @cm_request_transparent{user.farm.get_by_id()}
76 #
77 def get_by_id(cm_response, **data):
78  return cm_response
79 
80 
81 @user_log(log=True, pack=False)
82 @cm_request
83 ##
84 #
85 # @clmview_user
86 # @cm_request_transparent{user.farm.save_and_shutdown()}
87 #
88 def save_and_shutdown(cm_response, **data):
89  return cm_response
90 
91 
92 @user_log(log=True, pack=False)
93 @cm_request
94 ##
95 #
96 # @clmview_user
97 # @cm_request_transparent{user.farm.check_resources()}
98 #
99 def check_resources(cm_response, **data):
100  return cm_response
101