cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
admin.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.cm.views.user.admin
22 #
23 # @alldecoratedby{src.cm.utils.decorators.user_log}
24 #
25 
26 from cm.utils.exception import CMException
27 from cm.utils.decorators import user_log, admin_cm_log
28 from cm.models.admin import Admin
29 from cm.models.user import User
30 from cm.utils import log
31 
32 
33 @user_log(log=True)
34 ##
35 #
36 # Creates first admin of the cluster. It should be called right after
37 # submiting the form for adding new CM. System will not operate properly
38 # with no CM admin existing.
39 #
40 # @note It can be run only if no CM admin exists in the CM database.
41 #
42 # @cmview_user
43 # @param_post{new_password,string} first *CM admin password* to set
44 # @param_post{clm_address,string}
45 #
46 def first_admin_add(caller_id, new_password, clm_address):
47  # verify if the id caller exists and gets the instance
48  # try:
49  # user = User.objects.get(pk=caller_id)
50  # except User.DoesNotExist:
51  # raise CMException('admin_add')
52  user = User.create(caller_id)
53  user.save()
54 
55  # creates a new admin, which is the caller
56  admin = Admin()
57  admin.user = user
58  admin.password = new_password
59 
60  try:
61  admin.save()
62  except:
63  raise CMException('admin_add')
64 
65  # Update config and setup CLM address
66  try:
67  lines = []
68  config = open('/usr/lib/cc1/cm/config.py', 'r')
69  for line in config.readlines():
70  if line.startswith('CLM_ADDRESS') and 'NOT_CONFIGURED' in line:
71  lines.append('CLM_ADDRESS = "https://%s:8000/"\n' % clm_address)
72  else:
73  lines.append(line)
74  config.close()
75 
76  config = open('/usr/lib/cc1/cm/config.py', 'w')
77  config.write(''.join(lines))
78  config.close()
79  except:
80  log.exception(caller_id, 'config_update')
81  raise CMException('config_update')
82 
83 
84 @admin_cm_log(log=True)
85 ##
86 #
87 # Checks caller's password. Authentication is performed inside \@admin_cm_log
88 # decorator, therefore check_password() doesn't need to perform any further
89 # action.
90 #
91 # @cmview_admin_cm
92 #
93 def check_password(caller_id):
94  pass
95