root / kamaki / cli / commands / astakos.py @ 00b1248e
History | View | Annotate | Download (28.4 kB)
1 | e3f01d64 | Stavros Sachtouris | # Copyright 2011-2013 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 7493ccb6 | Stavros Sachtouris | #
|
3 | 7493ccb6 | Stavros Sachtouris | # Redistribution and use in source and binary forms, with or
|
4 | 7493ccb6 | Stavros Sachtouris | # without modification, are permitted provided that the following
|
5 | 7493ccb6 | Stavros Sachtouris | # conditions are met:
|
6 | 7493ccb6 | Stavros Sachtouris | #
|
7 | 7493ccb6 | Stavros Sachtouris | # 1. Redistributions of source code must retain the above
|
8 | 7493ccb6 | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
9 | 7493ccb6 | Stavros Sachtouris | # disclaimer.
|
10 | 7493ccb6 | Stavros Sachtouris | #
|
11 | 7493ccb6 | Stavros Sachtouris | # 2. Redistributions in binary form must reproduce the above
|
12 | 7493ccb6 | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
13 | 7493ccb6 | Stavros Sachtouris | # disclaimer in the documentation and/or other materials
|
14 | 7493ccb6 | Stavros Sachtouris | # provided with the distribution.
|
15 | 7493ccb6 | Stavros Sachtouris | #
|
16 | 7493ccb6 | Stavros Sachtouris | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 7493ccb6 | Stavros Sachtouris | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 7493ccb6 | Stavros Sachtouris | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 7493ccb6 | Stavros Sachtouris | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 7493ccb6 | Stavros Sachtouris | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 7493ccb6 | Stavros Sachtouris | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 7493ccb6 | Stavros Sachtouris | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 7493ccb6 | Stavros Sachtouris | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 7493ccb6 | Stavros Sachtouris | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 7493ccb6 | Stavros Sachtouris | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 7493ccb6 | Stavros Sachtouris | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 7493ccb6 | Stavros Sachtouris | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 7493ccb6 | Stavros Sachtouris | #
|
29 | 7493ccb6 | Stavros Sachtouris | # The views and conclusions contained in the software and
|
30 | 7493ccb6 | Stavros Sachtouris | # documentation are those of the authors and should not be
|
31 | 7493ccb6 | Stavros Sachtouris | # interpreted as representing official policies, either expressed
|
32 | 7493ccb6 | Stavros Sachtouris | # or implied, of GRNET S.A.command
|
33 | 7493ccb6 | Stavros Sachtouris | |
34 | ab863157 | Stavros Sachtouris | from json import load, loads |
35 | c308d73f | Stavros Sachtouris | from os.path import abspath |
36 | c308d73f | Stavros Sachtouris | |
37 | c2be5c96 | Stavros Sachtouris | from kamaki.cli import command |
38 | 5033585e | Stavros Sachtouris | from kamaki.clients.astakos import SynnefoAstakosClient |
39 | b4f69041 | Stavros Sachtouris | from kamaki.cli.commands import ( |
40 | 98c02f22 | Stavros Sachtouris | _command_init, errors, _optional_json, addLogSettings) |
41 | be99b6ad | Stavros Sachtouris | from kamaki.cli.command_tree import CommandTree |
42 | fa7d08b6 | Stavros Sachtouris | from kamaki.cli.errors import CLIBaseUrlError, CLISyntaxError, CLIError |
43 | ab863157 | Stavros Sachtouris | from kamaki.cli.argument import ( |
44 | ab863157 | Stavros Sachtouris | FlagArgument, ValueArgument, IntArgument, CommaSeparatedListArgument) |
45 | e8d3b957 | Stavros Sachtouris | from kamaki.cli.utils import format_size |
46 | 7493ccb6 | Stavros Sachtouris | |
47 | 25f9a991 | Stavros Sachtouris | # Mandatory
|
48 | 25f9a991 | Stavros Sachtouris | |
49 | e8d3b957 | Stavros Sachtouris | user_commands = CommandTree('user', 'Astakos/Identity API commands') |
50 | 25f9a991 | Stavros Sachtouris | quota_commands = CommandTree( |
51 | 25f9a991 | Stavros Sachtouris | 'quota', 'Astakos/Account API commands for quotas') |
52 | 25f9a991 | Stavros Sachtouris | resource_commands = CommandTree( |
53 | 25f9a991 | Stavros Sachtouris | 'resource', 'Astakos/Account API commands for resources') |
54 | e8d3b957 | Stavros Sachtouris | project_commands = CommandTree('project', 'Astakos project API commands') |
55 | 25f9a991 | Stavros Sachtouris | |
56 | 25f9a991 | Stavros Sachtouris | |
57 | 25f9a991 | Stavros Sachtouris | # Optional
|
58 | 25f9a991 | Stavros Sachtouris | |
59 | 25f9a991 | Stavros Sachtouris | endpoint_commands = CommandTree( |
60 | 25f9a991 | Stavros Sachtouris | 'endpoint', 'Astakos/Account API commands for endpoints') |
61 | 25f9a991 | Stavros Sachtouris | service_commands = CommandTree('service', 'Astakos API commands for services') |
62 | 25f9a991 | Stavros Sachtouris | commission_commands = CommandTree( |
63 | 25f9a991 | Stavros Sachtouris | 'commission', 'Astakos API commands for commissions') |
64 | 25f9a991 | Stavros Sachtouris | |
65 | 25f9a991 | Stavros Sachtouris | _commands = [ |
66 | 25f9a991 | Stavros Sachtouris | user_commands, quota_commands, resource_commands, project_commands, |
67 | 25f9a991 | Stavros Sachtouris | service_commands, commission_commands, endpoint_commands] |
68 | 234954d1 | Stavros Sachtouris | |
69 | 234954d1 | Stavros Sachtouris | |
70 | ab863157 | Stavros Sachtouris | def with_temp_token(foo): |
71 | ab863157 | Stavros Sachtouris | """ Set token to self.client.token, run foo, recover old token """
|
72 | ab863157 | Stavros Sachtouris | def wrap(self, *args, **kwargs): |
73 | ab863157 | Stavros Sachtouris | try:
|
74 | ab863157 | Stavros Sachtouris | token = kwargs.pop('token')
|
75 | ab863157 | Stavros Sachtouris | except KeyError: |
76 | ab863157 | Stavros Sachtouris | raise CLISyntaxError('A token is needed for %s' % foo) |
77 | ab863157 | Stavros Sachtouris | token_bu = self.client.token
|
78 | ab863157 | Stavros Sachtouris | try:
|
79 | fa7d08b6 | Stavros Sachtouris | self.client.token = token or token_bu |
80 | ab863157 | Stavros Sachtouris | return foo(self, *args, **kwargs) |
81 | ab863157 | Stavros Sachtouris | finally:
|
82 | ab863157 | Stavros Sachtouris | self.client.token = token_bu
|
83 | ab863157 | Stavros Sachtouris | return wrap
|
84 | ab863157 | Stavros Sachtouris | |
85 | ab863157 | Stavros Sachtouris | |
86 | e8d3b957 | Stavros Sachtouris | class _init_synnefo_astakosclient(_command_init): |
87 | 85115c12 | Stavros Sachtouris | |
88 | a03ade9e | Stavros Sachtouris | @errors.generic.all
|
89 | 4018326d | Stavros Sachtouris | @errors.user.load
|
90 | e8d3b957 | Stavros Sachtouris | @errors.user.astakosclient
|
91 | b4f69041 | Stavros Sachtouris | @addLogSettings
|
92 | 436bd910 | Stavros Sachtouris | def _run(self): |
93 | e8d3b957 | Stavros Sachtouris | if getattr(self, 'cloud', None): |
94 | b4f69041 | Stavros Sachtouris | base_url = self._custom_url('astakos') |
95 | b4f69041 | Stavros Sachtouris | if base_url:
|
96 | f5ff79d9 | Stavros Sachtouris | token = self._custom_token(
|
97 | ab863157 | Stavros Sachtouris | 'astakos') or self.config.get_cloud( |
98 | ab863157 | Stavros Sachtouris | self.cloud, 'token') |
99 | dc897a7e | Stavros Sachtouris | token = token.split()[0] if ' ' in token else token |
100 | e8d3b957 | Stavros Sachtouris | self.client = SynnefoAstakosClient(
|
101 | e8d3b957 | Stavros Sachtouris | auth_url=base_url, token=token) |
102 | b4f69041 | Stavros Sachtouris | return
|
103 | b4f69041 | Stavros Sachtouris | else:
|
104 | b4f69041 | Stavros Sachtouris | self.cloud = 'default' |
105 | e8d3b957 | Stavros Sachtouris | if getattr(self, 'auth_base', None): |
106 | 5033585e | Stavros Sachtouris | self.client = self.auth_base.get_client() |
107 | b4f69041 | Stavros Sachtouris | return
|
108 | b4f69041 | Stavros Sachtouris | raise CLIBaseUrlError(service='astakos') |
109 | 7493ccb6 | Stavros Sachtouris | |
110 | 436bd910 | Stavros Sachtouris | def main(self): |
111 | 5fdccdec | Stavros Sachtouris | self._run()
|
112 | 436bd910 | Stavros Sachtouris | |
113 | 234954d1 | Stavros Sachtouris | |
114 | e8d3b957 | Stavros Sachtouris | @command(user_commands)
|
115 | fa7d08b6 | Stavros Sachtouris | class user_authenticate(_init_synnefo_astakosclient, _optional_json): |
116 | fa7d08b6 | Stavros Sachtouris | """Authenticate a user and get all authentication information"""
|
117 | 7493ccb6 | Stavros Sachtouris | |
118 | a03ade9e | Stavros Sachtouris | @errors.generic.all
|
119 | 4018326d | Stavros Sachtouris | @errors.user.authenticate
|
120 | e8d3b957 | Stavros Sachtouris | @errors.user.astakosclient
|
121 | 5033585e | Stavros Sachtouris | @with_temp_token
|
122 | 5033585e | Stavros Sachtouris | def _run(self): |
123 | fa7d08b6 | Stavros Sachtouris | self._print(self.client.authenticate(), self.print_dict) |
124 | 3185cd6d | Stavros Sachtouris | |
125 | e8d3b957 | Stavros Sachtouris | def main(self, token=None): |
126 | 9a8861d1 | Stavros Sachtouris | super(self.__class__, self)._run() |
127 | 5033585e | Stavros Sachtouris | self._run(token=token)
|
128 | 9a8861d1 | Stavros Sachtouris | |
129 | 9a8861d1 | Stavros Sachtouris | |
130 | e8d3b957 | Stavros Sachtouris | @command(user_commands)
|
131 | 5033585e | Stavros Sachtouris | class user_uuid2name(_init_synnefo_astakosclient, _optional_json): |
132 | 5033585e | Stavros Sachtouris | """Get user name(s) from uuid(s)"""
|
133 | 9a8861d1 | Stavros Sachtouris | |
134 | 9a8861d1 | Stavros Sachtouris | @errors.generic.all
|
135 | e8d3b957 | Stavros Sachtouris | @errors.user.astakosclient
|
136 | e8d3b957 | Stavros Sachtouris | def _run(self, uuids): |
137 | e8d3b957 | Stavros Sachtouris | r = self.client.get_usernames(uuids)
|
138 | e8d3b957 | Stavros Sachtouris | self._print(r, self.print_dict) |
139 | e8d3b957 | Stavros Sachtouris | unresolved = set(uuids).difference(r)
|
140 | e8d3b957 | Stavros Sachtouris | if unresolved:
|
141 | e8d3b957 | Stavros Sachtouris | self.error('Unresolved uuids: %s' % ', '.join(unresolved)) |
142 | e8d3b957 | Stavros Sachtouris | |
143 | e8d3b957 | Stavros Sachtouris | def main(self, uuid, *more_uuids): |
144 | 9a8861d1 | Stavros Sachtouris | super(self.__class__, self)._run() |
145 | e8d3b957 | Stavros Sachtouris | self._run(uuids=((uuid, ) + more_uuids))
|
146 | b91111b9 | Stavros Sachtouris | |
147 | b91111b9 | Stavros Sachtouris | |
148 | e8d3b957 | Stavros Sachtouris | @command(user_commands)
|
149 | 5033585e | Stavros Sachtouris | class user_name2uuid(_init_synnefo_astakosclient, _optional_json): |
150 | 5033585e | Stavros Sachtouris | """Get user uuid(s) from name(s)"""
|
151 | b91111b9 | Stavros Sachtouris | |
152 | b91111b9 | Stavros Sachtouris | @errors.generic.all
|
153 | e8d3b957 | Stavros Sachtouris | @errors.user.astakosclient
|
154 | e8d3b957 | Stavros Sachtouris | def _run(self, usernames): |
155 | e8d3b957 | Stavros Sachtouris | r = self.client.get_uuids(usernames)
|
156 | e8d3b957 | Stavros Sachtouris | self._print(r, self.print_dict) |
157 | e8d3b957 | Stavros Sachtouris | unresolved = set(usernames).difference(r)
|
158 | e8d3b957 | Stavros Sachtouris | if unresolved:
|
159 | e8d3b957 | Stavros Sachtouris | self.error('Unresolved usernames: %s' % ', '.join(unresolved)) |
160 | e8d3b957 | Stavros Sachtouris | |
161 | e8d3b957 | Stavros Sachtouris | def main(self, username, *more_usernames): |
162 | b91111b9 | Stavros Sachtouris | super(self.__class__, self)._run() |
163 | e8d3b957 | Stavros Sachtouris | self._run(usernames=((username, ) + more_usernames))
|
164 | e8d3b957 | Stavros Sachtouris | |
165 | e8d3b957 | Stavros Sachtouris | |
166 | 25f9a991 | Stavros Sachtouris | @command(quota_commands)
|
167 | 25f9a991 | Stavros Sachtouris | class quota_list(_init_synnefo_astakosclient, _optional_json): |
168 | e8d3b957 | Stavros Sachtouris | """Get user quotas"""
|
169 | e8d3b957 | Stavros Sachtouris | |
170 | e8d3b957 | Stavros Sachtouris | _to_format = set(['cyclades.disk', 'pithos.diskspace', 'cyclades.ram']) |
171 | fe4940bc | Stavros Sachtouris | |
172 | e8d3b957 | Stavros Sachtouris | arguments = dict(
|
173 | e8d3b957 | Stavros Sachtouris | bytes=FlagArgument('Show data size in bytes', '--bytes') |
174 | e8d3b957 | Stavros Sachtouris | ) |
175 | fe4940bc | Stavros Sachtouris | |
176 | e8d3b957 | Stavros Sachtouris | def _print_quotas(self, quotas, *args, **kwargs): |
177 | e8d3b957 | Stavros Sachtouris | if not self['bytes']: |
178 | e8d3b957 | Stavros Sachtouris | for category in quotas.values(): |
179 | e8d3b957 | Stavros Sachtouris | for service in self._to_format.intersection(category): |
180 | e8d3b957 | Stavros Sachtouris | for attr, v in category[service].items(): |
181 | e8d3b957 | Stavros Sachtouris | category[service][attr] = format_size(v) |
182 | e8d3b957 | Stavros Sachtouris | self.print_dict(quotas, *args, **kwargs)
|
183 | fe4940bc | Stavros Sachtouris | |
184 | fe4940bc | Stavros Sachtouris | @errors.generic.all
|
185 | e8d3b957 | Stavros Sachtouris | @errors.user.astakosclient
|
186 | e8d3b957 | Stavros Sachtouris | def _run(self): |
187 | e8d3b957 | Stavros Sachtouris | self._print(self.client.get_quotas(), self._print_quotas) |
188 | fe4940bc | Stavros Sachtouris | |
189 | e8d3b957 | Stavros Sachtouris | def main(self): |
190 | fe4940bc | Stavros Sachtouris | super(self.__class__, self)._run() |
191 | e8d3b957 | Stavros Sachtouris | self._run()
|
192 | c308d73f | Stavros Sachtouris | |
193 | c308d73f | Stavros Sachtouris | |
194 | fa7d08b6 | Stavros Sachtouris | # command user session
|
195 | fa7d08b6 | Stavros Sachtouris | |
196 | fa7d08b6 | Stavros Sachtouris | |
197 | fa7d08b6 | Stavros Sachtouris | @command(user_commands)
|
198 | 25f9a991 | Stavros Sachtouris | class user_info(_init_synnefo_astakosclient, _optional_json): |
199 | fa7d08b6 | Stavros Sachtouris | """Get info for (current) session user"""
|
200 | fa7d08b6 | Stavros Sachtouris | |
201 | fa7d08b6 | Stavros Sachtouris | arguments = dict(
|
202 | fa7d08b6 | Stavros Sachtouris | uuid=ValueArgument('Query user with uuid', '--uuid'), |
203 | fa7d08b6 | Stavros Sachtouris | name=ValueArgument('Query user with username/email', '--username') |
204 | fa7d08b6 | Stavros Sachtouris | ) |
205 | fa7d08b6 | Stavros Sachtouris | |
206 | fa7d08b6 | Stavros Sachtouris | @errors.generic.all
|
207 | fa7d08b6 | Stavros Sachtouris | @errors.user.astakosclient
|
208 | fa7d08b6 | Stavros Sachtouris | def _run(self): |
209 | fa7d08b6 | Stavros Sachtouris | if self['uuid'] and self['name']: |
210 | fa7d08b6 | Stavros Sachtouris | raise CLISyntaxError(
|
211 | fa7d08b6 | Stavros Sachtouris | 'Arguments uuid and username are mutually exclusive',
|
212 | fa7d08b6 | Stavros Sachtouris | details=['Use either uuid OR username OR none, not both'])
|
213 | fa7d08b6 | Stavros Sachtouris | uuid = self['uuid'] or (self._username2uuid(self['name']) if ( |
214 | fa7d08b6 | Stavros Sachtouris | self['name']) else None) |
215 | fa7d08b6 | Stavros Sachtouris | try:
|
216 | fa7d08b6 | Stavros Sachtouris | token = self.auth_base.get_token(uuid) if uuid else None |
217 | fa7d08b6 | Stavros Sachtouris | except KeyError: |
218 | fa7d08b6 | Stavros Sachtouris | msg = ('id %s' % self['uuid']) if ( |
219 | fa7d08b6 | Stavros Sachtouris | self['uuid']) else 'username %s' % self['name'] |
220 | fa7d08b6 | Stavros Sachtouris | raise CLIError(
|
221 | fa7d08b6 | Stavros Sachtouris | 'No user with %s in the cached session list' % msg, details=[
|
222 | fa7d08b6 | Stavros Sachtouris | 'To see all cached session users',
|
223 | 25f9a991 | Stavros Sachtouris | ' /user list',
|
224 | fa7d08b6 | Stavros Sachtouris | 'To authenticate and add a new user in the session list',
|
225 | 25f9a991 | Stavros Sachtouris | ' /user add <new token>'])
|
226 | fa7d08b6 | Stavros Sachtouris | self._print(self.auth_base.user_info(token), self.print_dict) |
227 | fa7d08b6 | Stavros Sachtouris | |
228 | fa7d08b6 | Stavros Sachtouris | |
229 | fa7d08b6 | Stavros Sachtouris | @command(user_commands)
|
230 | 25f9a991 | Stavros Sachtouris | class user_add(_init_synnefo_astakosclient, _optional_json): |
231 | 25f9a991 | Stavros Sachtouris | """Authenticate a user by token and add to kamaki session (cache)"""
|
232 | fa7d08b6 | Stavros Sachtouris | |
233 | fa7d08b6 | Stavros Sachtouris | @errors.generic.all
|
234 | fa7d08b6 | Stavros Sachtouris | @errors.user.astakosclient
|
235 | fa7d08b6 | Stavros Sachtouris | def _run(self, token=None): |
236 | fa7d08b6 | Stavros Sachtouris | ask = token and token not in self.auth_base._uuids |
237 | fa7d08b6 | Stavros Sachtouris | self._print(self.auth_base.authenticate(token), self.print_dict) |
238 | fa7d08b6 | Stavros Sachtouris | if ask and self.ask_user( |
239 | fa7d08b6 | Stavros Sachtouris | 'Token is temporarily stored in memory. If it is stored in'
|
240 | fa7d08b6 | Stavros Sachtouris | ' kamaki configuration file, it will be available in later'
|
241 | fa7d08b6 | Stavros Sachtouris | ' sessions. Do you want to permanently store this token?'):
|
242 | fa7d08b6 | Stavros Sachtouris | tokens = self.auth_base._uuids.keys()
|
243 | fa7d08b6 | Stavros Sachtouris | tokens.remove(self.auth_base.token)
|
244 | fa7d08b6 | Stavros Sachtouris | self['config'].set_cloud( |
245 | fa7d08b6 | Stavros Sachtouris | self.cloud, 'token', ' '.join([self.auth_base.token] + tokens)) |
246 | fa7d08b6 | Stavros Sachtouris | self['config'].write() |
247 | fa7d08b6 | Stavros Sachtouris | |
248 | fa7d08b6 | Stavros Sachtouris | def main(self, new_token=None): |
249 | fa7d08b6 | Stavros Sachtouris | super(self.__class__, self)._run() |
250 | fa7d08b6 | Stavros Sachtouris | self._run(token=new_token)
|
251 | fa7d08b6 | Stavros Sachtouris | |
252 | fa7d08b6 | Stavros Sachtouris | |
253 | fa7d08b6 | Stavros Sachtouris | @command(user_commands)
|
254 | 25f9a991 | Stavros Sachtouris | class user_list(_init_synnefo_astakosclient, _optional_json): |
255 | 25f9a991 | Stavros Sachtouris | """List (cached) session users"""
|
256 | fa7d08b6 | Stavros Sachtouris | |
257 | fa7d08b6 | Stavros Sachtouris | arguments = dict(
|
258 | fa7d08b6 | Stavros Sachtouris | detail=FlagArgument('Detailed listing', ('-l', '--detail')) |
259 | fa7d08b6 | Stavros Sachtouris | ) |
260 | fa7d08b6 | Stavros Sachtouris | |
261 | fa7d08b6 | Stavros Sachtouris | @errors.generic.all
|
262 | fa7d08b6 | Stavros Sachtouris | @errors.user.astakosclient
|
263 | fa7d08b6 | Stavros Sachtouris | def _run(self): |
264 | fa7d08b6 | Stavros Sachtouris | self._print([u if self['detail'] else (dict( |
265 | fa7d08b6 | Stavros Sachtouris | id=u['id'], name=u['name'])) for u in self.auth_base.list_users()]) |
266 | fa7d08b6 | Stavros Sachtouris | |
267 | fa7d08b6 | Stavros Sachtouris | def main(self): |
268 | fa7d08b6 | Stavros Sachtouris | super(self.__class__, self)._run() |
269 | fa7d08b6 | Stavros Sachtouris | self._run()
|
270 | fa7d08b6 | Stavros Sachtouris | |
271 | fa7d08b6 | Stavros Sachtouris | |
272 | fa7d08b6 | Stavros Sachtouris | @command(user_commands)
|
273 | 25f9a991 | Stavros Sachtouris | class user_select(_init_synnefo_astakosclient): |
274 | 25f9a991 | Stavros Sachtouris | """Select a user from the (cached) list as the current session user"""
|
275 | fa7d08b6 | Stavros Sachtouris | |
276 | fa7d08b6 | Stavros Sachtouris | @errors.generic.all
|
277 | fa7d08b6 | Stavros Sachtouris | @errors.user.astakosclient
|
278 | fa7d08b6 | Stavros Sachtouris | def _run(self, uuid): |
279 | fa7d08b6 | Stavros Sachtouris | try:
|
280 | fa7d08b6 | Stavros Sachtouris | first_token = self.auth_base.get_token(uuid)
|
281 | fa7d08b6 | Stavros Sachtouris | except KeyError: |
282 | fa7d08b6 | Stavros Sachtouris | raise CLIError(
|
283 | fa7d08b6 | Stavros Sachtouris | 'No user with uuid %s in the cached session list' % uuid,
|
284 | fa7d08b6 | Stavros Sachtouris | details=[ |
285 | fa7d08b6 | Stavros Sachtouris | 'To see all cached session users',
|
286 | 25f9a991 | Stavros Sachtouris | ' /user list',
|
287 | fa7d08b6 | Stavros Sachtouris | 'To authenticate and add a new user in the session list',
|
288 | 25f9a991 | Stavros Sachtouris | ' /user add <new token>'])
|
289 | fa7d08b6 | Stavros Sachtouris | if self.auth_base.token != first_token: |
290 | fa7d08b6 | Stavros Sachtouris | self.auth_base.token = first_token
|
291 | fa7d08b6 | Stavros Sachtouris | msg = 'User with id %s is now the current session user.\n' % uuid
|
292 | fa7d08b6 | Stavros Sachtouris | msg += 'Do you want future sessions to also start with this user?'
|
293 | fa7d08b6 | Stavros Sachtouris | if self.ask_user(msg): |
294 | fa7d08b6 | Stavros Sachtouris | tokens = self.auth_base._uuids.keys()
|
295 | fa7d08b6 | Stavros Sachtouris | tokens.remove(self.auth_base.token)
|
296 | fa7d08b6 | Stavros Sachtouris | tokens.insert(0, self.auth_base.token) |
297 | fa7d08b6 | Stavros Sachtouris | self['config'].set_cloud( |
298 | fa7d08b6 | Stavros Sachtouris | self.cloud, 'token', ' '.join(tokens)) |
299 | fa7d08b6 | Stavros Sachtouris | self['config'].write() |
300 | fa7d08b6 | Stavros Sachtouris | self.error('User is selected for next sessions') |
301 | fa7d08b6 | Stavros Sachtouris | else:
|
302 | fa7d08b6 | Stavros Sachtouris | self.error('User is not permanently selected') |
303 | fa7d08b6 | Stavros Sachtouris | else:
|
304 | fa7d08b6 | Stavros Sachtouris | self.error('User was already the selected session user') |
305 | fa7d08b6 | Stavros Sachtouris | |
306 | fa7d08b6 | Stavros Sachtouris | def main(self, user_uuid): |
307 | fa7d08b6 | Stavros Sachtouris | super(self.__class__, self)._run() |
308 | fa7d08b6 | Stavros Sachtouris | self._run(uuid=user_uuid)
|
309 | fa7d08b6 | Stavros Sachtouris | |
310 | fa7d08b6 | Stavros Sachtouris | |
311 | fa7d08b6 | Stavros Sachtouris | @command(user_commands)
|
312 | 25f9a991 | Stavros Sachtouris | class user_delete(_init_synnefo_astakosclient): |
313 | 25f9a991 | Stavros Sachtouris | """Delete a user (token) from the (cached) list of session users"""
|
314 | fa7d08b6 | Stavros Sachtouris | |
315 | fa7d08b6 | Stavros Sachtouris | @errors.generic.all
|
316 | fa7d08b6 | Stavros Sachtouris | @errors.user.astakosclient
|
317 | fa7d08b6 | Stavros Sachtouris | def _run(self, uuid): |
318 | fa7d08b6 | Stavros Sachtouris | if uuid == self.auth_base.user_term('id'): |
319 | fa7d08b6 | Stavros Sachtouris | raise CLIError('Cannot remove current session user', details=[ |
320 | fa7d08b6 | Stavros Sachtouris | 'To see all cached session users',
|
321 | 25f9a991 | Stavros Sachtouris | ' /user list',
|
322 | fa7d08b6 | Stavros Sachtouris | 'To see current session user',
|
323 | 25f9a991 | Stavros Sachtouris | ' /user info',
|
324 | fa7d08b6 | Stavros Sachtouris | 'To select a different session user',
|
325 | 25f9a991 | Stavros Sachtouris | ' /user select <user uuid>'])
|
326 | fa7d08b6 | Stavros Sachtouris | try:
|
327 | fa7d08b6 | Stavros Sachtouris | self.auth_base.remove_user(uuid)
|
328 | fa7d08b6 | Stavros Sachtouris | except KeyError: |
329 | fa7d08b6 | Stavros Sachtouris | raise CLIError('No user with uuid %s in session list' % uuid, |
330 | fa7d08b6 | Stavros Sachtouris | details=[ |
331 | fa7d08b6 | Stavros Sachtouris | 'To see all cached session users',
|
332 | 25f9a991 | Stavros Sachtouris | ' /user list',
|
333 | fa7d08b6 | Stavros Sachtouris | 'To authenticate and add a new user in the session list',
|
334 | 25f9a991 | Stavros Sachtouris | ' /user add <new token>'])
|
335 | fa7d08b6 | Stavros Sachtouris | if self.ask_user( |
336 | fa7d08b6 | Stavros Sachtouris | 'User is removed from current session, but will be restored in'
|
337 | fa7d08b6 | Stavros Sachtouris | ' the next session. Remove the user from future sessions?'):
|
338 | fa7d08b6 | Stavros Sachtouris | self['config'].set_cloud( |
339 | fa7d08b6 | Stavros Sachtouris | self.cloud, 'token', ' '.join(self.auth_base._uuids.keys())) |
340 | fa7d08b6 | Stavros Sachtouris | self['config'].write() |
341 | fa7d08b6 | Stavros Sachtouris | |
342 | fa7d08b6 | Stavros Sachtouris | def main(self, user_uuid): |
343 | fa7d08b6 | Stavros Sachtouris | super(self.__class__, self)._run() |
344 | fa7d08b6 | Stavros Sachtouris | self._run(uuid=user_uuid)
|
345 | fa7d08b6 | Stavros Sachtouris | |
346 | fa7d08b6 | Stavros Sachtouris | |
347 | ab863157 | Stavros Sachtouris | # command admin
|
348 | ab863157 | Stavros Sachtouris | |
349 | 25f9a991 | Stavros Sachtouris | @command(service_commands)
|
350 | 25f9a991 | Stavros Sachtouris | class service_list(_init_synnefo_astakosclient, _optional_json): |
351 | ab863157 | Stavros Sachtouris | """List available services"""
|
352 | ab863157 | Stavros Sachtouris | |
353 | ab863157 | Stavros Sachtouris | @errors.generic.all
|
354 | ab863157 | Stavros Sachtouris | @errors.user.astakosclient
|
355 | ab863157 | Stavros Sachtouris | def _run(self): |
356 | ab863157 | Stavros Sachtouris | self._print(self.client.get_services()) |
357 | ab863157 | Stavros Sachtouris | |
358 | ab863157 | Stavros Sachtouris | def main(self): |
359 | ab863157 | Stavros Sachtouris | super(self.__class__, self)._run() |
360 | ab863157 | Stavros Sachtouris | self._run()
|
361 | ab863157 | Stavros Sachtouris | |
362 | ab863157 | Stavros Sachtouris | |
363 | 25f9a991 | Stavros Sachtouris | @command(service_commands)
|
364 | 25f9a991 | Stavros Sachtouris | class service_uuid2username(_init_synnefo_astakosclient, _optional_json): |
365 | ab863157 | Stavros Sachtouris | """Get service username(s) from uuid(s)"""
|
366 | ab863157 | Stavros Sachtouris | |
367 | ab863157 | Stavros Sachtouris | @errors.generic.all
|
368 | ab863157 | Stavros Sachtouris | @errors.user.astakosclient
|
369 | ab863157 | Stavros Sachtouris | @with_temp_token
|
370 | ab863157 | Stavros Sachtouris | def _run(self, uuids): |
371 | ab863157 | Stavros Sachtouris | if 1 == len(uuids): |
372 | ab863157 | Stavros Sachtouris | self._print(self.client.service_get_username(uuids[0])) |
373 | ab863157 | Stavros Sachtouris | else:
|
374 | ab863157 | Stavros Sachtouris | self._print(
|
375 | ab863157 | Stavros Sachtouris | self.client.service_get_usernames(uuids),
|
376 | ab863157 | Stavros Sachtouris | self.print_dict)
|
377 | ab863157 | Stavros Sachtouris | |
378 | ab863157 | Stavros Sachtouris | def main(self, service_token, uuid, *more_uuids): |
379 | ab863157 | Stavros Sachtouris | super(self.__class__, self)._run() |
380 | ab863157 | Stavros Sachtouris | self._run([uuid] + list(more_uuids), token=service_token) |
381 | ab863157 | Stavros Sachtouris | |
382 | ab863157 | Stavros Sachtouris | |
383 | 25f9a991 | Stavros Sachtouris | @command(service_commands)
|
384 | 25f9a991 | Stavros Sachtouris | class service_username2uuid(_init_synnefo_astakosclient, _optional_json): |
385 | ab863157 | Stavros Sachtouris | """Get service uuid(s) from username(s)"""
|
386 | ab863157 | Stavros Sachtouris | |
387 | ab863157 | Stavros Sachtouris | @errors.generic.all
|
388 | ab863157 | Stavros Sachtouris | @errors.user.astakosclient
|
389 | ab863157 | Stavros Sachtouris | @with_temp_token
|
390 | ab863157 | Stavros Sachtouris | def _run(self, usernames): |
391 | ab863157 | Stavros Sachtouris | if 1 == len(usernames): |
392 | ab863157 | Stavros Sachtouris | self._print(self.client.service_get_uuid(usernames[0])) |
393 | ab863157 | Stavros Sachtouris | else:
|
394 | ab863157 | Stavros Sachtouris | self._print(
|
395 | ab863157 | Stavros Sachtouris | self.client.service_get_uuids(usernames),
|
396 | ab863157 | Stavros Sachtouris | self.print_dict)
|
397 | ab863157 | Stavros Sachtouris | |
398 | ab863157 | Stavros Sachtouris | def main(self, service_token, usernames, *more_usernames): |
399 | ab863157 | Stavros Sachtouris | super(self.__class__, self)._run() |
400 | ab863157 | Stavros Sachtouris | self._run([usernames] + list(more_usernames), token=service_token) |
401 | ab863157 | Stavros Sachtouris | |
402 | ab863157 | Stavros Sachtouris | |
403 | 25f9a991 | Stavros Sachtouris | @command(service_commands)
|
404 | 25f9a991 | Stavros Sachtouris | class service_quotas(_init_synnefo_astakosclient, _optional_json): |
405 | ab863157 | Stavros Sachtouris | """Get service quotas"""
|
406 | ab863157 | Stavros Sachtouris | |
407 | ab863157 | Stavros Sachtouris | arguments = dict(
|
408 | ab863157 | Stavros Sachtouris | uuid=ValueArgument('A user uuid to get quotas for', '--uuid') |
409 | ab863157 | Stavros Sachtouris | ) |
410 | ab863157 | Stavros Sachtouris | |
411 | ab863157 | Stavros Sachtouris | @errors.generic.all
|
412 | ab863157 | Stavros Sachtouris | @errors.user.astakosclient
|
413 | ab863157 | Stavros Sachtouris | @with_temp_token
|
414 | ab863157 | Stavros Sachtouris | def _run(self): |
415 | ab863157 | Stavros Sachtouris | self._print(self.client.service_get_quotas(self['uuid'])) |
416 | ab863157 | Stavros Sachtouris | |
417 | ab863157 | Stavros Sachtouris | def main(self, service_token): |
418 | ab863157 | Stavros Sachtouris | super(self.__class__, self)._run() |
419 | ab863157 | Stavros Sachtouris | self._run(token=service_token)
|
420 | ab863157 | Stavros Sachtouris | |
421 | ab863157 | Stavros Sachtouris | |
422 | 25f9a991 | Stavros Sachtouris | @command(commission_commands)
|
423 | 25f9a991 | Stavros Sachtouris | class commission_pending(_init_synnefo_astakosclient, _optional_json): |
424 | ab863157 | Stavros Sachtouris | """List pending commissions (special privileges required)"""
|
425 | ab863157 | Stavros Sachtouris | |
426 | ab863157 | Stavros Sachtouris | @errors.generic.all
|
427 | ab863157 | Stavros Sachtouris | @errors.user.astakosclient
|
428 | ab863157 | Stavros Sachtouris | def _run(self): |
429 | ab863157 | Stavros Sachtouris | self._print(self.client.get_pending_commissions()) |
430 | ab863157 | Stavros Sachtouris | |
431 | ab863157 | Stavros Sachtouris | def main(self): |
432 | ab863157 | Stavros Sachtouris | super(self.__class__, self)._run() |
433 | ab863157 | Stavros Sachtouris | self._run()
|
434 | ab863157 | Stavros Sachtouris | |
435 | ab863157 | Stavros Sachtouris | |
436 | 25f9a991 | Stavros Sachtouris | @command(commission_commands)
|
437 | 25f9a991 | Stavros Sachtouris | class commission_info(_init_synnefo_astakosclient, _optional_json): |
438 | ab863157 | Stavros Sachtouris | """Get commission info (special privileges required)"""
|
439 | ab863157 | Stavros Sachtouris | |
440 | ab863157 | Stavros Sachtouris | @errors.generic.all
|
441 | ab863157 | Stavros Sachtouris | @errors.user.astakosclient
|
442 | ab863157 | Stavros Sachtouris | def _run(self, commission_id): |
443 | ab863157 | Stavros Sachtouris | commission_id = int(commission_id)
|
444 | ab863157 | Stavros Sachtouris | self._print(
|
445 | ab863157 | Stavros Sachtouris | self.client.get_commission_info(commission_id), self.print_dict) |
446 | ab863157 | Stavros Sachtouris | |
447 | ab863157 | Stavros Sachtouris | def main(self, commission_id): |
448 | ab863157 | Stavros Sachtouris | super(self.__class__, self)._run() |
449 | ab863157 | Stavros Sachtouris | self._run(commission_id)
|
450 | ab863157 | Stavros Sachtouris | |
451 | ab863157 | Stavros Sachtouris | |
452 | 25f9a991 | Stavros Sachtouris | @command(commission_commands)
|
453 | 25f9a991 | Stavros Sachtouris | class commission_accept(_init_synnefo_astakosclient): |
454 | ab863157 | Stavros Sachtouris | """Accept a pending commission (special privileges required)"""
|
455 | ab863157 | Stavros Sachtouris | |
456 | ab863157 | Stavros Sachtouris | @errors.generic.all
|
457 | ab863157 | Stavros Sachtouris | @errors.user.astakosclient
|
458 | ab863157 | Stavros Sachtouris | def _run(self, commission_id): |
459 | ab863157 | Stavros Sachtouris | commission_id = int(commission_id)
|
460 | ab863157 | Stavros Sachtouris | self.client.accept_commission(commission_id)
|
461 | ab863157 | Stavros Sachtouris | |
462 | ab863157 | Stavros Sachtouris | def main(self, commission_id): |
463 | ab863157 | Stavros Sachtouris | super(self.__class__, self)._run() |
464 | ab863157 | Stavros Sachtouris | self._run(commission_id)
|
465 | ab863157 | Stavros Sachtouris | |
466 | ab863157 | Stavros Sachtouris | |
467 | 25f9a991 | Stavros Sachtouris | @command(commission_commands)
|
468 | 25f9a991 | Stavros Sachtouris | class commission_reject(_init_synnefo_astakosclient): |
469 | ab863157 | Stavros Sachtouris | """Reject a pending commission (special privileges required)"""
|
470 | ab863157 | Stavros Sachtouris | |
471 | ab863157 | Stavros Sachtouris | @errors.generic.all
|
472 | ab863157 | Stavros Sachtouris | @errors.user.astakosclient
|
473 | ab863157 | Stavros Sachtouris | def _run(self, commission_id): |
474 | ab863157 | Stavros Sachtouris | commission_id = int(commission_id)
|
475 | ab863157 | Stavros Sachtouris | self.client.reject_commission(commission_id)
|
476 | ab863157 | Stavros Sachtouris | |
477 | ab863157 | Stavros Sachtouris | def main(self, commission_id): |
478 | ab863157 | Stavros Sachtouris | super(self.__class__, self)._run() |
479 | ab863157 | Stavros Sachtouris | self._run(commission_id)
|
480 | ab863157 | Stavros Sachtouris | |
481 | ab863157 | Stavros Sachtouris | |
482 | 25f9a991 | Stavros Sachtouris | @command(commission_commands)
|
483 | 25f9a991 | Stavros Sachtouris | class commission_resolve(_init_synnefo_astakosclient, _optional_json): |
484 | ab863157 | Stavros Sachtouris | """Resolve multiple commissions (special privileges required)"""
|
485 | ab863157 | Stavros Sachtouris | |
486 | ab863157 | Stavros Sachtouris | arguments = dict(
|
487 | ab863157 | Stavros Sachtouris | accept=CommaSeparatedListArgument( |
488 | ab863157 | Stavros Sachtouris | 'commission ids to accept (e.g., --accept=11,12,13,...',
|
489 | ab863157 | Stavros Sachtouris | '--accept'),
|
490 | ab863157 | Stavros Sachtouris | reject=CommaSeparatedListArgument( |
491 | ab863157 | Stavros Sachtouris | 'commission ids to reject (e.g., --reject=11,12,13,...',
|
492 | ab863157 | Stavros Sachtouris | '--reject')
|
493 | ab863157 | Stavros Sachtouris | ) |
494 | ab863157 | Stavros Sachtouris | |
495 | ab863157 | Stavros Sachtouris | @errors.generic.all
|
496 | ab863157 | Stavros Sachtouris | @errors.user.astakosclient
|
497 | ab863157 | Stavros Sachtouris | def _run(self): |
498 | ab863157 | Stavros Sachtouris | self.writeln('accepted ', self['accept']) |
499 | ab863157 | Stavros Sachtouris | self.writeln('rejected ', self['reject']) |
500 | ab863157 | Stavros Sachtouris | self._print(
|
501 | ab863157 | Stavros Sachtouris | self.client.resolve_commissions(self['accept'], self['reject']), |
502 | ab863157 | Stavros Sachtouris | self.print_dict)
|
503 | ab863157 | Stavros Sachtouris | |
504 | ab863157 | Stavros Sachtouris | def main(self): |
505 | ab863157 | Stavros Sachtouris | super(self.__class__, self)._run() |
506 | ab863157 | Stavros Sachtouris | self._run()
|
507 | ab863157 | Stavros Sachtouris | |
508 | ab863157 | Stavros Sachtouris | |
509 | 25f9a991 | Stavros Sachtouris | @command(commission_commands)
|
510 | 25f9a991 | Stavros Sachtouris | class commission_issue(_init_synnefo_astakosclient, _optional_json): |
511 | ab863157 | Stavros Sachtouris | """Issue commissions as a json string (special privileges required)
|
512 | ab863157 | Stavros Sachtouris | Parameters:
|
513 | ab863157 | Stavros Sachtouris | holder -- user's id (string)
|
514 | ab863157 | Stavros Sachtouris | source -- commission's source (ex system) (string)
|
515 | ab863157 | Stavros Sachtouris | provisions -- resources with their quantity (json-dict from string to int)
|
516 | ab863157 | Stavros Sachtouris | name -- description of the commission (string)
|
517 | ab863157 | Stavros Sachtouris | """
|
518 | ab863157 | Stavros Sachtouris | |
519 | ab863157 | Stavros Sachtouris | arguments = dict(
|
520 | ab863157 | Stavros Sachtouris | force=FlagArgument('Force commission', '--force'), |
521 | ab863157 | Stavros Sachtouris | accept=FlagArgument('Do not wait for verification', '--accept') |
522 | ab863157 | Stavros Sachtouris | ) |
523 | ab863157 | Stavros Sachtouris | |
524 | ab863157 | Stavros Sachtouris | @errors.generic.all
|
525 | ab863157 | Stavros Sachtouris | @errors.user.astakosclient
|
526 | ab863157 | Stavros Sachtouris | def _run(self, holder, source, provisions, name=''): |
527 | ab863157 | Stavros Sachtouris | provisions = loads(provisions) |
528 | ab863157 | Stavros Sachtouris | self._print(self.client.issue_one_commission( |
529 | ab863157 | Stavros Sachtouris | holder, source, provisions, name, |
530 | ab863157 | Stavros Sachtouris | self['force'], self['accept'])) |
531 | ab863157 | Stavros Sachtouris | |
532 | ab863157 | Stavros Sachtouris | def main(self, user_uuid, source, provisions_file, name=''): |
533 | ab863157 | Stavros Sachtouris | super(self.__class__, self)._run() |
534 | ab863157 | Stavros Sachtouris | self._run(user_uuid, source, provisions_file, name)
|
535 | ab863157 | Stavros Sachtouris | |
536 | ab863157 | Stavros Sachtouris | |
537 | 25f9a991 | Stavros Sachtouris | @command(resource_commands)
|
538 | 25f9a991 | Stavros Sachtouris | class resource_list(_init_synnefo_astakosclient, _optional_json): |
539 | ab863157 | Stavros Sachtouris | """List user resources"""
|
540 | ab863157 | Stavros Sachtouris | |
541 | ab863157 | Stavros Sachtouris | @errors.generic.all
|
542 | ab863157 | Stavros Sachtouris | @errors.user.astakosclient
|
543 | ab863157 | Stavros Sachtouris | def _run(self): |
544 | ab863157 | Stavros Sachtouris | self._print(self.client.get_resources(), self.print_dict) |
545 | ab863157 | Stavros Sachtouris | |
546 | ab863157 | Stavros Sachtouris | def main(self): |
547 | ab863157 | Stavros Sachtouris | super(self.__class__, self)._run() |
548 | ab863157 | Stavros Sachtouris | self._run()
|
549 | ab863157 | Stavros Sachtouris | |
550 | ab863157 | Stavros Sachtouris | |
551 | 25f9a991 | Stavros Sachtouris | @command(endpoint_commands)
|
552 | 25f9a991 | Stavros Sachtouris | class endpoint_list(_init_synnefo_astakosclient, _optional_json): |
553 | ab863157 | Stavros Sachtouris | """Get endpoints service endpoints"""
|
554 | ab863157 | Stavros Sachtouris | |
555 | ab863157 | Stavros Sachtouris | @errors.generic.all
|
556 | ab863157 | Stavros Sachtouris | @errors.user.astakosclient
|
557 | ab863157 | Stavros Sachtouris | def _run(self): |
558 | fa7d08b6 | Stavros Sachtouris | self._print(self.client.get_endpoints(), self.print_dict) |
559 | ab863157 | Stavros Sachtouris | |
560 | ab863157 | Stavros Sachtouris | def main(self): |
561 | ab863157 | Stavros Sachtouris | super(self.__class__, self)._run() |
562 | ab863157 | Stavros Sachtouris | self._run()
|
563 | ab863157 | Stavros Sachtouris | |
564 | ab863157 | Stavros Sachtouris | |
565 | c308d73f | Stavros Sachtouris | # command project
|
566 | c308d73f | Stavros Sachtouris | |
567 | c308d73f | Stavros Sachtouris | |
568 | c308d73f | Stavros Sachtouris | _project_specs = """
|
569 | c308d73f | Stavros Sachtouris | {
|
570 | c308d73f | Stavros Sachtouris | "name": name,
|
571 | c308d73f | Stavros Sachtouris | "owner": uuid,
|
572 | c308d73f | Stavros Sachtouris | "homepage": homepage, # optional
|
573 | c308d73f | Stavros Sachtouris | "description": description, # optional
|
574 | c308d73f | Stavros Sachtouris | "comments": comments, # optional
|
575 | c308d73f | Stavros Sachtouris | "start_date": date, # optional
|
576 | c308d73f | Stavros Sachtouris | "end_date": date,
|
577 | c308d73f | Stavros Sachtouris | "join_policy": "auto" | "moderated" | "closed", # default: "moderated"
|
578 | c308d73f | Stavros Sachtouris | "leave_policy": "auto" | "moderated" | "closed", # default: "auto"
|
579 | c308d73f | Stavros Sachtouris | "resources": {
|
580 | c308d73f | Stavros Sachtouris | "cyclades.vm": {
|
581 | c308d73f | Stavros Sachtouris | "project_capacity": int or null,
|
582 | c308d73f | Stavros Sachtouris | "member_capacity": int
|
583 | c308d73f | Stavros Sachtouris | }
|
584 | c308d73f | Stavros Sachtouris | }
|
585 | c308d73f | Stavros Sachtouris | }
|
586 | c308d73f | Stavros Sachtouris | """
|
587 | c308d73f | Stavros Sachtouris | |
588 | c308d73f | Stavros Sachtouris | |
589 | c308d73f | Stavros Sachtouris | def apply_notification(foo): |
590 | c308d73f | Stavros Sachtouris | def wrap(self, *args, **kwargs): |
591 | c308d73f | Stavros Sachtouris | r = foo(self, *args, **kwargs)
|
592 | c308d73f | Stavros Sachtouris | self.writeln('Application is submitted successfully') |
593 | c308d73f | Stavros Sachtouris | return r
|
594 | c308d73f | Stavros Sachtouris | return wrap
|
595 | c308d73f | Stavros Sachtouris | |
596 | c308d73f | Stavros Sachtouris | |
597 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
598 | c308d73f | Stavros Sachtouris | class project_list(_init_synnefo_astakosclient, _optional_json): |
599 | c308d73f | Stavros Sachtouris | """List all projects"""
|
600 | c308d73f | Stavros Sachtouris | |
601 | c308d73f | Stavros Sachtouris | arguments = dict(
|
602 | c308d73f | Stavros Sachtouris | name=ValueArgument('Filter by name', ('--with-name', )), |
603 | c308d73f | Stavros Sachtouris | state=ValueArgument('Filter by state', ('--with-state', )), |
604 | c308d73f | Stavros Sachtouris | owner=ValueArgument('Filter by owner', ('--with-owner', )) |
605 | c308d73f | Stavros Sachtouris | ) |
606 | c308d73f | Stavros Sachtouris | |
607 | c308d73f | Stavros Sachtouris | @errors.generic.all
|
608 | c308d73f | Stavros Sachtouris | @errors.user.astakosclient
|
609 | c308d73f | Stavros Sachtouris | def _run(self): |
610 | c308d73f | Stavros Sachtouris | self._print(self.client.get_projects( |
611 | c308d73f | Stavros Sachtouris | self['name'], self['state'], self['owner'])) |
612 | c308d73f | Stavros Sachtouris | |
613 | c308d73f | Stavros Sachtouris | def main(self): |
614 | c308d73f | Stavros Sachtouris | super(self.__class__, self)._run() |
615 | c308d73f | Stavros Sachtouris | self._run()
|
616 | c308d73f | Stavros Sachtouris | |
617 | c308d73f | Stavros Sachtouris | |
618 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
619 | c308d73f | Stavros Sachtouris | class project_info(_init_synnefo_astakosclient, _optional_json): |
620 | c308d73f | Stavros Sachtouris | """Get details for a project"""
|
621 | c308d73f | Stavros Sachtouris | |
622 | c308d73f | Stavros Sachtouris | @errors.generic.all
|
623 | c308d73f | Stavros Sachtouris | @errors.user.astakosclient
|
624 | c308d73f | Stavros Sachtouris | def _run(self, project_id): |
625 | c308d73f | Stavros Sachtouris | self._print(
|
626 | c308d73f | Stavros Sachtouris | self.client.get_project(project_id), self.print_dict) |
627 | c308d73f | Stavros Sachtouris | |
628 | c308d73f | Stavros Sachtouris | def main(self, project_id): |
629 | c308d73f | Stavros Sachtouris | super(self.__class__, self)._run() |
630 | c308d73f | Stavros Sachtouris | self._run(project_id)
|
631 | c308d73f | Stavros Sachtouris | |
632 | c308d73f | Stavros Sachtouris | |
633 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
634 | c308d73f | Stavros Sachtouris | class project_create(_init_synnefo_astakosclient, _optional_json): |
635 | c308d73f | Stavros Sachtouris | """Apply for a new project (input a json-dict)
|
636 | c308d73f | Stavros Sachtouris | Project details must be provided as a json-formated dict from the standard
|
637 | c308d73f | Stavros Sachtouris | input, or through a file
|
638 | c308d73f | Stavros Sachtouris | """
|
639 | c308d73f | Stavros Sachtouris | |
640 | c308d73f | Stavros Sachtouris | __doc__ += _project_specs |
641 | c308d73f | Stavros Sachtouris | |
642 | c308d73f | Stavros Sachtouris | arguments = dict(
|
643 | c308d73f | Stavros Sachtouris | specs_path=ValueArgument( |
644 | c308d73f | Stavros Sachtouris | 'Specification file path (content must be in json)', '--spec-file') |
645 | c308d73f | Stavros Sachtouris | ) |
646 | c308d73f | Stavros Sachtouris | |
647 | c308d73f | Stavros Sachtouris | @errors.generic.all
|
648 | c308d73f | Stavros Sachtouris | @errors.user.astakosclient
|
649 | c308d73f | Stavros Sachtouris | @apply_notification
|
650 | c308d73f | Stavros Sachtouris | def _run(self): |
651 | c308d73f | Stavros Sachtouris | input_stream = open(abspath(self['specs_path'])) if ( |
652 | c308d73f | Stavros Sachtouris | self['specs_path']) else self._in |
653 | c308d73f | Stavros Sachtouris | specs = load(input_stream) |
654 | c308d73f | Stavros Sachtouris | self._print(
|
655 | c308d73f | Stavros Sachtouris | self.client.create_project(specs), self.print_dict) |
656 | c308d73f | Stavros Sachtouris | |
657 | c308d73f | Stavros Sachtouris | def main(self): |
658 | c308d73f | Stavros Sachtouris | super(self.__class__, self)._run() |
659 | c308d73f | Stavros Sachtouris | self._run()
|
660 | c308d73f | Stavros Sachtouris | |
661 | c308d73f | Stavros Sachtouris | |
662 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
663 | c308d73f | Stavros Sachtouris | class project_modify(_init_synnefo_astakosclient, _optional_json): |
664 | c308d73f | Stavros Sachtouris | """Modify a project (input a json-dict)
|
665 | c308d73f | Stavros Sachtouris | Project details must be provided as a json-formated dict from the standard
|
666 | c308d73f | Stavros Sachtouris | input, or through a file
|
667 | c308d73f | Stavros Sachtouris | """
|
668 | c308d73f | Stavros Sachtouris | |
669 | c308d73f | Stavros Sachtouris | __doc__ += _project_specs |
670 | c308d73f | Stavros Sachtouris | |
671 | c308d73f | Stavros Sachtouris | arguments = dict(
|
672 | c308d73f | Stavros Sachtouris | specs_path=ValueArgument( |
673 | c308d73f | Stavros Sachtouris | 'Specification file path (content must be in json)', '--spec-file') |
674 | c308d73f | Stavros Sachtouris | ) |
675 | c308d73f | Stavros Sachtouris | |
676 | c308d73f | Stavros Sachtouris | @errors.generic.all
|
677 | c308d73f | Stavros Sachtouris | @errors.user.astakosclient
|
678 | c308d73f | Stavros Sachtouris | @apply_notification
|
679 | c308d73f | Stavros Sachtouris | def _run(self, project_id): |
680 | c308d73f | Stavros Sachtouris | input_stream = open(abspath(self['specs_path'])) if ( |
681 | c308d73f | Stavros Sachtouris | self['specs_path']) else self._in |
682 | c308d73f | Stavros Sachtouris | specs = load(input_stream) |
683 | c308d73f | Stavros Sachtouris | self._print(
|
684 | c308d73f | Stavros Sachtouris | self.client.modify_project(project_id, specs),
|
685 | c308d73f | Stavros Sachtouris | self.print_dict)
|
686 | c308d73f | Stavros Sachtouris | |
687 | c308d73f | Stavros Sachtouris | def main(self, project_id): |
688 | c308d73f | Stavros Sachtouris | super(self.__class__, self)._run() |
689 | c308d73f | Stavros Sachtouris | self._run(project_id)
|
690 | c308d73f | Stavros Sachtouris | |
691 | c308d73f | Stavros Sachtouris | |
692 | c308d73f | Stavros Sachtouris | class _project_action(_init_synnefo_astakosclient): |
693 | c308d73f | Stavros Sachtouris | |
694 | c308d73f | Stavros Sachtouris | action = ''
|
695 | c308d73f | Stavros Sachtouris | |
696 | c308d73f | Stavros Sachtouris | @errors.generic.all
|
697 | c308d73f | Stavros Sachtouris | @errors.user.astakosclient
|
698 | c308d73f | Stavros Sachtouris | def _run(self, project_id, quote_a_reason): |
699 | c308d73f | Stavros Sachtouris | self.client.project_action(project_id, self.action, quote_a_reason) |
700 | c308d73f | Stavros Sachtouris | |
701 | c308d73f | Stavros Sachtouris | def main(self, project_id, quote_a_reason=''): |
702 | c308d73f | Stavros Sachtouris | super(_project_action, self)._run() |
703 | c308d73f | Stavros Sachtouris | self._run(project_id, quote_a_reason)
|
704 | c308d73f | Stavros Sachtouris | |
705 | c308d73f | Stavros Sachtouris | |
706 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
707 | c308d73f | Stavros Sachtouris | class project_suspend(_project_action): |
708 | c308d73f | Stavros Sachtouris | """Suspend a project (special privileges needed)"""
|
709 | c308d73f | Stavros Sachtouris | action = 'suspend'
|
710 | c308d73f | Stavros Sachtouris | |
711 | c308d73f | Stavros Sachtouris | |
712 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
713 | c308d73f | Stavros Sachtouris | class project_unsuspend(_project_action): |
714 | c308d73f | Stavros Sachtouris | """Resume a suspended project (special privileges needed)"""
|
715 | c308d73f | Stavros Sachtouris | action = 'unsuspend'
|
716 | c308d73f | Stavros Sachtouris | |
717 | c308d73f | Stavros Sachtouris | |
718 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
719 | c308d73f | Stavros Sachtouris | class project_terminate(_project_action): |
720 | c308d73f | Stavros Sachtouris | """Terminate a project (special privileges needed)"""
|
721 | c308d73f | Stavros Sachtouris | action = 'terminate'
|
722 | c308d73f | Stavros Sachtouris | |
723 | c308d73f | Stavros Sachtouris | |
724 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
725 | c308d73f | Stavros Sachtouris | class project_reinstate(_project_action): |
726 | c308d73f | Stavros Sachtouris | """Reinstate a terminated project (special privileges needed)"""
|
727 | c308d73f | Stavros Sachtouris | action = 'reinstate'
|
728 | c308d73f | Stavros Sachtouris | |
729 | c308d73f | Stavros Sachtouris | |
730 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
731 | c308d73f | Stavros Sachtouris | class project_application(_init_synnefo_astakosclient): |
732 | c308d73f | Stavros Sachtouris | """Application management commands"""
|
733 | c308d73f | Stavros Sachtouris | |
734 | c308d73f | Stavros Sachtouris | |
735 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
736 | c308d73f | Stavros Sachtouris | class project_application_list(_init_synnefo_astakosclient, _optional_json): |
737 | c308d73f | Stavros Sachtouris | """List all applications (old and new)"""
|
738 | c308d73f | Stavros Sachtouris | |
739 | c308d73f | Stavros Sachtouris | arguments = dict(
|
740 | c308d73f | Stavros Sachtouris | project=IntArgument('Filter by project id', '--with-project-id') |
741 | c308d73f | Stavros Sachtouris | ) |
742 | c308d73f | Stavros Sachtouris | |
743 | c308d73f | Stavros Sachtouris | @errors.generic.all
|
744 | c308d73f | Stavros Sachtouris | @errors.user.astakosclient
|
745 | c308d73f | Stavros Sachtouris | def _run(self): |
746 | c308d73f | Stavros Sachtouris | self._print(self.client.get_applications(self['project'])) |
747 | c308d73f | Stavros Sachtouris | |
748 | c308d73f | Stavros Sachtouris | def main(self): |
749 | c308d73f | Stavros Sachtouris | super(self.__class__, self)._run() |
750 | c308d73f | Stavros Sachtouris | self._run()
|
751 | c308d73f | Stavros Sachtouris | |
752 | c308d73f | Stavros Sachtouris | |
753 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
754 | c308d73f | Stavros Sachtouris | class project_application_info(_init_synnefo_astakosclient, _optional_json): |
755 | c308d73f | Stavros Sachtouris | """Get details on an application"""
|
756 | c308d73f | Stavros Sachtouris | |
757 | c308d73f | Stavros Sachtouris | @errors.generic.all
|
758 | c308d73f | Stavros Sachtouris | @errors.user.astakosclient
|
759 | c308d73f | Stavros Sachtouris | def _run(self, app_id): |
760 | c308d73f | Stavros Sachtouris | self._print(
|
761 | c308d73f | Stavros Sachtouris | self.client.get_application(app_id), self.print_dict) |
762 | c308d73f | Stavros Sachtouris | |
763 | c308d73f | Stavros Sachtouris | def main(self, application_id): |
764 | c308d73f | Stavros Sachtouris | super(self.__class__, self)._run() |
765 | c308d73f | Stavros Sachtouris | self._run(application_id)
|
766 | c308d73f | Stavros Sachtouris | |
767 | c308d73f | Stavros Sachtouris | |
768 | c308d73f | Stavros Sachtouris | class _application_action(_init_synnefo_astakosclient): |
769 | c308d73f | Stavros Sachtouris | |
770 | c308d73f | Stavros Sachtouris | action = ''
|
771 | c308d73f | Stavros Sachtouris | |
772 | c308d73f | Stavros Sachtouris | @errors.generic.all
|
773 | c308d73f | Stavros Sachtouris | @errors.user.astakosclient
|
774 | c308d73f | Stavros Sachtouris | def _run(self, app_id, quote_a_reason): |
775 | c308d73f | Stavros Sachtouris | self.client.application_action(app_id, self.action, quote_a_reason) |
776 | c308d73f | Stavros Sachtouris | |
777 | c308d73f | Stavros Sachtouris | def main(self, application_id, quote_a_reason=''): |
778 | c308d73f | Stavros Sachtouris | super(_application_action, self)._run() |
779 | c308d73f | Stavros Sachtouris | self._run(application_id, quote_a_reason)
|
780 | c308d73f | Stavros Sachtouris | |
781 | c308d73f | Stavros Sachtouris | |
782 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
783 | c308d73f | Stavros Sachtouris | class project_application_approve(_application_action): |
784 | c308d73f | Stavros Sachtouris | """Approve an application (special privileges needed)"""
|
785 | c308d73f | Stavros Sachtouris | action = 'approve'
|
786 | c308d73f | Stavros Sachtouris | |
787 | c308d73f | Stavros Sachtouris | |
788 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
789 | c308d73f | Stavros Sachtouris | class project_application_deny(_application_action): |
790 | c308d73f | Stavros Sachtouris | """Deny an application (special privileges needed)"""
|
791 | c308d73f | Stavros Sachtouris | action = 'deny'
|
792 | c308d73f | Stavros Sachtouris | |
793 | c308d73f | Stavros Sachtouris | |
794 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
795 | c308d73f | Stavros Sachtouris | class project_application_dismiss(_application_action): |
796 | c308d73f | Stavros Sachtouris | """Dismiss your denied application"""
|
797 | c308d73f | Stavros Sachtouris | action = 'dismiss'
|
798 | c308d73f | Stavros Sachtouris | |
799 | c308d73f | Stavros Sachtouris | |
800 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
801 | c308d73f | Stavros Sachtouris | class project_application_cancel(_application_action): |
802 | c308d73f | Stavros Sachtouris | """Cancel your application"""
|
803 | c308d73f | Stavros Sachtouris | action = 'cancel'
|
804 | c308d73f | Stavros Sachtouris | |
805 | c308d73f | Stavros Sachtouris | |
806 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
807 | c308d73f | Stavros Sachtouris | class project_membership(_init_synnefo_astakosclient): |
808 | c308d73f | Stavros Sachtouris | """Project membership management commands"""
|
809 | c308d73f | Stavros Sachtouris | |
810 | c308d73f | Stavros Sachtouris | |
811 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
812 | c308d73f | Stavros Sachtouris | class project_membership_list(_init_synnefo_astakosclient, _optional_json): |
813 | c308d73f | Stavros Sachtouris | """List all memberships"""
|
814 | c308d73f | Stavros Sachtouris | |
815 | c308d73f | Stavros Sachtouris | arguments = dict(
|
816 | c308d73f | Stavros Sachtouris | project=IntArgument('Filter by project id', '--with-project-id') |
817 | c308d73f | Stavros Sachtouris | ) |
818 | c308d73f | Stavros Sachtouris | |
819 | c308d73f | Stavros Sachtouris | @errors.generic.all
|
820 | c308d73f | Stavros Sachtouris | @errors.user.astakosclient
|
821 | c308d73f | Stavros Sachtouris | def _run(self): |
822 | c308d73f | Stavros Sachtouris | self._print(self.client.get_memberships(self['project'])) |
823 | c308d73f | Stavros Sachtouris | |
824 | c308d73f | Stavros Sachtouris | def main(self): |
825 | c308d73f | Stavros Sachtouris | super(self.__class__, self)._run() |
826 | c308d73f | Stavros Sachtouris | self._run()
|
827 | c308d73f | Stavros Sachtouris | |
828 | c308d73f | Stavros Sachtouris | |
829 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
830 | c308d73f | Stavros Sachtouris | class project_membership_info(_init_synnefo_astakosclient, _optional_json): |
831 | c308d73f | Stavros Sachtouris | """Details on a membership"""
|
832 | c308d73f | Stavros Sachtouris | |
833 | c308d73f | Stavros Sachtouris | @errors.generic.all
|
834 | c308d73f | Stavros Sachtouris | @errors.user.astakosclient
|
835 | c308d73f | Stavros Sachtouris | def _run(self, memb_id): |
836 | c308d73f | Stavros Sachtouris | self._print(
|
837 | c308d73f | Stavros Sachtouris | self.client.get_membership(memb_id), self.print_dict) |
838 | c308d73f | Stavros Sachtouris | |
839 | c308d73f | Stavros Sachtouris | def main(self, membership_id): |
840 | c308d73f | Stavros Sachtouris | super(self.__class__, self)._run() |
841 | c308d73f | Stavros Sachtouris | self._run(membership_id)
|
842 | c308d73f | Stavros Sachtouris | |
843 | c308d73f | Stavros Sachtouris | |
844 | c308d73f | Stavros Sachtouris | class _membership_action(_init_synnefo_astakosclient, _optional_json): |
845 | c308d73f | Stavros Sachtouris | |
846 | c308d73f | Stavros Sachtouris | action = ''
|
847 | c308d73f | Stavros Sachtouris | |
848 | c308d73f | Stavros Sachtouris | @errors.generic.all
|
849 | c308d73f | Stavros Sachtouris | @errors.user.astakosclient
|
850 | c308d73f | Stavros Sachtouris | def _run(self, memb_id, quote_a_reason): |
851 | c308d73f | Stavros Sachtouris | self._print(self.client.membership_action( |
852 | c308d73f | Stavros Sachtouris | memb_id, self.action, quote_a_reason))
|
853 | c308d73f | Stavros Sachtouris | |
854 | c308d73f | Stavros Sachtouris | def main(self, membership_id, quote_a_reason=''): |
855 | c308d73f | Stavros Sachtouris | super(_membership_action, self)._run() |
856 | c308d73f | Stavros Sachtouris | self._run(membership_id, quote_a_reason)
|
857 | c308d73f | Stavros Sachtouris | |
858 | c308d73f | Stavros Sachtouris | |
859 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
860 | c308d73f | Stavros Sachtouris | class project_membership_leave(_membership_action): |
861 | c308d73f | Stavros Sachtouris | """Leave a project you have membership to"""
|
862 | c308d73f | Stavros Sachtouris | action = 'leave'
|
863 | c308d73f | Stavros Sachtouris | |
864 | c308d73f | Stavros Sachtouris | |
865 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
866 | c308d73f | Stavros Sachtouris | class project_membership_cancel(_membership_action): |
867 | c308d73f | Stavros Sachtouris | """Cancel your (probably pending) membership to a project"""
|
868 | c308d73f | Stavros Sachtouris | action = 'cancel'
|
869 | c308d73f | Stavros Sachtouris | |
870 | c308d73f | Stavros Sachtouris | |
871 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
872 | c308d73f | Stavros Sachtouris | class project_membership_accept(_membership_action): |
873 | c308d73f | Stavros Sachtouris | """Accept a membership for a project you manage"""
|
874 | c308d73f | Stavros Sachtouris | action = 'accept'
|
875 | c308d73f | Stavros Sachtouris | |
876 | c308d73f | Stavros Sachtouris | |
877 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
878 | c308d73f | Stavros Sachtouris | class project_membership_reject(_membership_action): |
879 | c308d73f | Stavros Sachtouris | """Reject a membership for a project you manage"""
|
880 | c308d73f | Stavros Sachtouris | action = 'reject'
|
881 | c308d73f | Stavros Sachtouris | |
882 | c308d73f | Stavros Sachtouris | |
883 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
884 | c308d73f | Stavros Sachtouris | class project_membership_remove(_membership_action): |
885 | c308d73f | Stavros Sachtouris | """Remove a membership for a project you manage"""
|
886 | c308d73f | Stavros Sachtouris | action = 'remove'
|
887 | c308d73f | Stavros Sachtouris | |
888 | c308d73f | Stavros Sachtouris | |
889 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
890 | c308d73f | Stavros Sachtouris | class project_membership_join(_init_synnefo_astakosclient): |
891 | c308d73f | Stavros Sachtouris | """Join a project"""
|
892 | c308d73f | Stavros Sachtouris | |
893 | c308d73f | Stavros Sachtouris | @errors.generic.all
|
894 | c308d73f | Stavros Sachtouris | @errors.user.astakosclient
|
895 | c308d73f | Stavros Sachtouris | def _run(self, project_id): |
896 | c308d73f | Stavros Sachtouris | self.writeln(self.client.join_project(project_id)) |
897 | c308d73f | Stavros Sachtouris | |
898 | c308d73f | Stavros Sachtouris | def main(self, project_id): |
899 | c308d73f | Stavros Sachtouris | super(project_membership_join, self)._run() |
900 | c308d73f | Stavros Sachtouris | self._run(project_id)
|
901 | c308d73f | Stavros Sachtouris | |
902 | c308d73f | Stavros Sachtouris | |
903 | c308d73f | Stavros Sachtouris | @command(project_commands)
|
904 | c308d73f | Stavros Sachtouris | class project_membership_enroll(_init_synnefo_astakosclient): |
905 | c308d73f | Stavros Sachtouris | """Enroll somebody to a project you manage"""
|
906 | c308d73f | Stavros Sachtouris | |
907 | c308d73f | Stavros Sachtouris | @errors.generic.all
|
908 | c308d73f | Stavros Sachtouris | @errors.user.astakosclient
|
909 | c308d73f | Stavros Sachtouris | def _run(self, project_id, email): |
910 | c308d73f | Stavros Sachtouris | self.writeln(self.client.enroll_member(project_id, email)) |
911 | c308d73f | Stavros Sachtouris | |
912 | c308d73f | Stavros Sachtouris | def main(self, project_id, email): |
913 | c308d73f | Stavros Sachtouris | super(project_membership_join, self)._run() |
914 | c308d73f | Stavros Sachtouris | self._run(project_id, email) |