cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
user.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.clm.views.user.user
22 # @alldecoratedby{src.clm.utils.decorators.user_log}
23 #
24 
25 from django.conf import settings
26 
27 from clm.models.cluster import Cluster
28 from clm.models.user import User
29 from clm.utils import mail
30 from clm.utils.decorators import user_log, cm_request
31 from clm.utils.exception import CLMException
32 from common.states import cluster_states
33 
34 
35 @user_log(log=True)
36 ##
37 #
38 # Returns user's data.
39 #
40 # @clmview_user
41 #
42 def get_my_data(cm_id, caller_id):
43  user = User.get(caller_id)
44  user = user.dict
45  endpoints = []
46  for cm_name in [c.short_dict['name'] for c in Cluster.objects.filter(state=cluster_states['ok'])]:
47  endpoints.append(cm_name + "." + settings.EC2_URL)
48  user["ec2_endpoints"] = endpoints
49  return user
50 
51 
52 @user_log(log=True)
53 ##
54 #
55 # Sets user's password.
56 #
57 # @clmview_user
58 # @param_post{new_password,string}
59 #
60 def set_password(cm_id, caller_id, new_password):
61  user = User.get(caller_id)
62  user.password = new_password
63  try:
64  user.save()
65  except:
66  raise CLMException('user_set_password')
67 
68  return user.dict
69 
70 
71 @user_log(log=True)
72 ##
73 #
74 # Function for editing user's data.
75 #
76 # @clmview_user
77 # @param_post{email,string}
78 # @param_post{default_cluster_id}
79 #
80 # @response{dict} new user's info
81 #
82 def edit(cm_id, caller_id, email, default_cluster_id):
83 
84  user = User.get(caller_id)
85  user.email = email
86  user.default_cluster_id = default_cluster_id
87  try:
88  user.save()
89  except:
90  raise CLMException('user_edit')
91 
92  return user.dict
93 
94 
95 @user_log(log=True, pack=False)
96 @cm_request
97 ##
98 #
99 # @clmview_user
100 # @cm_request_transparent{user.user.get_quota()}
101 #
102 def get_quota(cm_response, **data):
103  return cm_response
104 
105 
106 @user_log(log=True, pack=False)
107 @cm_request
108 ##
109 #
110 # @clmview_user
111 # @cm_request_transparent{user.user.point_history()}
112 #
113 def points_history(cm_response, **data):
114  return cm_response
115 
116 
117 @user_log(log=True)
118 ##
119 #
120 # Send issue email
121 #
122 # @clmview_user
123 # @param_post{topic,string} topic of the issue email
124 # @param_post{issue,string} content of the issue email
125 #
126 def send_issue(cm_id, caller_id, topic, issue):
127  try:
128  mail.send(settings.ISSUE_EMAIL, issue, topic)
129  except Exception:
130  raise CLMException('send_issue_error')
131 
132 
133 # @todo: monia not defined in CM
134 # @user_log(log=True, pack=False)
135 # def stat_test(cm_id, caller_id, vm_name, stats, start_time, stop_time, resolution):
136 # """
137 # @param_post{vm_name,string}
138 # @param_post{stats}
139 # @param_post{start_time}
140 # @param_post{stop_time}
141 # @param_post{resolution}
142 # @returns @asreturned{src.cm.views.user.user.stat_test()}
143 # """
144