cc1  v2.1
CC1 source code docs
All Classes Namespaces Files Functions Variables Pages
actions.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 users import *
21 from macros import *
22 import hashlib
23 
24 # List clusters. Should be called as standard admin account (called before any CM exists)
25 list_clusters = {'u': u_admin_clm,
26  'fname': 'cluster.admin_clm.list',
27  'args': [],
28  'store_as': 'clusters',
29  'predefined_action': True}
30 
31 # Lust user accounts
32 list_users = {'u': u_admin,
33  'fname': 'user.admin_clm.list',
34  'args': [],
35  'store_as': 'clm_user_list',
36  'predefined_action': True}
37 
38 # Template list
39 list_templates = {'u': u_new,
40  'fname': 'template.user.list',
41  'args': [],
42  'store_as': 'templates',
43  'predefined_action': True}
44 
45 # Public IP list
46 list_admin_public_ip = {'u': u_admin_cm,
47  'fname': 'elasticip.admin_cm.list',
48  'as_cmadmin': True,
49  'args': [],
50  'store_as': 'admin_public_ip'}
51 # User's public IP list
52 list_user_public_ip = {'u': u_new,
53  'fname': 'elasticip.user.list',
54  'args': [],
55  'store_as': 'user_public_ip',
56  'predefined_action': True}
57 
58 # List available networks
59 list_available_networks = {'u': u_new,
60  'fname': 'network.user.list_available_networks',
61  'args': [],
62  'store_as': 'available_networks',
63  'predefined_action': True}
64 
65 # List user networks
66 list_user_networks = {'u': u_new,
67  'fname': 'network.user.list_user_networks',
68  'args': [],
69  'store_as': 'user_networks',
70  'predefined_action': True}
71 
72 # List available storages
73 list_storages = {'u': u_admin_cm,
74  'as_cmadmin': True,
75  'fname': 'storage.admin_cm.list',
76  'args': [],
77  'store_as': 'storages',
78  'predefined_action': True}
79 
80 # List nodes
81 list_nodes = {'u': u_admin_cm,
82  'fname': 'node.admin_cm.list',
83  'as_cmadmin': True,
84  'args': [],
85  'store_as': 'nodes',
86  'predefined_action': True}
87 
88 # List images
89 list_private_vm_images = {'u': u_new,
90  'fname': 'image.user.list',
91  'args': [{'access': 0, 'type': 2}],
92  'store_as': 'private_vm_images',
93  'predefined_action': True
94  }
95 list_public_vm_images = {'u': u_new,
96  'fname': 'image.user.list',
97  'args': [{'access': 1, 'type': 2}],
98  'store_as': 'public_vm_images',
99  'predefined_action': True
100  }
101 list_group_vm_images = {'u': u_new,
102  'fname': 'image.user.list',
103  'args': [{'access': 2, 'type': 2}],
104  'store_as': 'group_vm_images',
105  'predefined_action': True
106  }
107 list_all_storage_images = {'u': u_admin,
108  'fname': 'image.admin_cm.list',
109  'as_cmadmin': True,
110  'args': [{'access': 0, 'type': 1}],
111  'store_as': 'storage_images',
112  'predefined_action': True
113  }
114 list_private_storage_images = {'u': u_new,
115  'fname': 'image.user.list',
116  'args': [{'access': 0, 'type': 1}],
117  'store_as': 'private_storage_images',
118  'predefined_action': True
119  }
120 list_private_cd_images = {'u': u_new,
121  'fname': 'image.user.list',
122  'args': [{'access': 0, 'type': 0}],
123  'store_as': 'private_cd_images',
124  'predefined_action': True
125  }
126 
127 # Hardware lists
128 list_filesystems = {'u': u_new,
129  'fname': 'image.user.get_supported_filesystems',
130  'args': [],
131  'store_as': 'filesystems',
132  'predefined_action': True}
133 list_video_devices = {'u': u_new,
134  'fname': 'image.user.get_video_devices',
135  'args': [],
136  'store_as': 'video_devices',
137  'predefined_action': True}
138 list_network_devices = {'u': u_new,
139  'fname': 'image.user.get_network_devices',
140  'args': [],
141  'store_as': 'network_devices',
142  'predefined_action': True}
143 list_disk_controllers = {'u': u_new,
144  'fname': 'image.user.get_disk_controllers',
145  'args': [],
146  'store_as': 'disk_controllers',
147  'predefined_action': True}
148 
149 # List virtual machines
150 list_user_vms = {'u': u_new,
151  'fname': 'vm.user.list',
152  'args': [],
153  'store_as': 'user_vms',
154  'predefined_action': True}
155 list_admin_vms = {'u': u_admin_cm,
156  'as_cmadmin': True,
157  'fname': 'vm.admin_cm.list',
158  'args': [{'all': True, 'user_id': 0}],
159  'store_as': 'admin_vms',
160  'predefined_action': True}
161 
162 def get_admin_vm_details(name): return {'u': u_admin_cm,
163  'as_cmadmin': True,
164  'fname': 'vm.admin_cm.get_by_id',
165  'args': [MACRO_GET_ADMIN_VM_ID(name)],
166  'store_as': 'vm_%s_details' % name,
167  'predefined_action': True}
168 
169 #########################
170 # Wait conditions #
171 #########################
172 def wait_vm_is_running(name, state=1): return {'u': u_new,
173  'fname': 'vm.user.list',
174  'args': [],
175  'wait_response': 'len(filter(lambda x: x["state"] == %d and x["name"] == "%s", r)) > 0' % (state, name),
176  'wait_max': 60}
177 
178 def wait_vm_in_state_by_id(id, state=1): return {'u': u_new,
179  'fname': 'vm.user.get_by_id',
180  'args': [id],
181  'wait_response': 'r["state"] == %d' % state,
182  'wait_max': 60}
183 
184 def wait_image_is_downloaded(name, access, type): return {'u': u_new,
185  'fname': 'image.user.list',
186  'args': [{'access': access, 'type': type}],
187  'wait_response': 'len(filter(lambda x: x["state"] == 0 and x["name"] == "%s", r)) > 0' % name,
188  'wait_max': 160}
189