cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
ctx.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.ctx
22 #
23 # @alldecoratedby{src.cm.utils.decorators.user_log}
24 #
25 from cm.models.command import Command
26 from cm.utils.decorators import user_log
27 
28 
29 @user_log(log=True)
30 ##
31 #
32 # Executes \c shutdown on virtual machines listed in \c vm_list at a given
33 # \c timeout (@val{now} by default) provided they belong to caller.
34 #
35 # @cmview_user
36 # @param_post{vm_id,int}
37 # @param_post{timeout,string} optional, "now" by default
38 #
39 def shutdown(caller_id, vm_id, timeout='now'):
40  return Command.execute('shutdown', caller_id, vm_id, timeout=timeout)
41 
42 
43 @user_log(log=True)
44 ##
45 #
46 # Executes \c reboot on given VM at given \c timeout (@val{now} by default).
47 #
48 # @warning Deprecated since execution's success/failure depends on inner
49 # VM's state.
50 #
51 # @cmview_user
52 # @param_post{vm_id,int} id of the VM to reboot
53 # @param_post{timeout,string} @optional{"now"}
54 #
55 def reboot(caller_id, vm_id, timeout='now'):
56  return Command.execute('reboot', caller_id, vm_id, timeout=timeout)
57 
58 
59 @user_log(log=True)
60 ##
61 #
62 # Resets password of the existing OS user \c user_name on given VM. User
63 # obtains new randomly created password. Such a password is sent in CM
64 # response. It is recommended to change password manually afterwards.
65 #
66 # @cmview_user
67 # @param_post{vm_id,int}
68 # @param_post{vm_username,string} username of the user whose password should
69 # be reseted
70 #
71 def reset_password(caller_id, vm_id, vm_username):
72  return {'password': Command.execute('reset_password', caller_id, vm_id, user=vm_username)}
73 
74 
75 @user_log(log=True)
76 ##
77 #
78 # Injects given SSH public key to authorized keys on specified VMs.
79 #
80 # @cmview_user
81 # @param_post{vm_ids,list(int)} id's of the VMs where SSH public key should be injected
82 # @param_post{vm_username,string}
83 # @param_post{vm_key,string}
84 #
85 def add_ssh_key(caller_id, vm_ids, vm_username, vm_key):
86  results = ''
87  for vm_id in vm_ids:
88  results += Command.execute('add_ssh_key', caller_id, vm_id, user=vm_username, ssh_key=vm_key)
89  return results
90