root / kamaki / cli / commands / snf-astakos.py @ f17d6cb5
History | View | Annotate | Download (15.2 kB)
1 | 97fc1e06 | Stavros Sachtouris | # Copyright 2013 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 97fc1e06 | Stavros Sachtouris | #
|
3 | 97fc1e06 | Stavros Sachtouris | # Redistribution and use in source and binary forms, with or
|
4 | 97fc1e06 | Stavros Sachtouris | # without modification, are permitted provided that the following
|
5 | 97fc1e06 | Stavros Sachtouris | # conditions are met:
|
6 | 97fc1e06 | Stavros Sachtouris | #
|
7 | 97fc1e06 | Stavros Sachtouris | # 1. Redistributions of source code must retain the above
|
8 | 97fc1e06 | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
9 | 97fc1e06 | Stavros Sachtouris | # disclaimer.
|
10 | 97fc1e06 | Stavros Sachtouris | #
|
11 | 97fc1e06 | Stavros Sachtouris | # 2. Redistributions in binary form must reproduce the above
|
12 | 97fc1e06 | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
13 | 97fc1e06 | Stavros Sachtouris | # disclaimer in the documentation and/or other materials
|
14 | 97fc1e06 | Stavros Sachtouris | # provided with the distribution.
|
15 | 97fc1e06 | Stavros Sachtouris | #
|
16 | 97fc1e06 | Stavros Sachtouris | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 97fc1e06 | Stavros Sachtouris | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 97fc1e06 | Stavros Sachtouris | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 97fc1e06 | Stavros Sachtouris | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 97fc1e06 | Stavros Sachtouris | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 97fc1e06 | Stavros Sachtouris | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 97fc1e06 | Stavros Sachtouris | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 97fc1e06 | Stavros Sachtouris | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 97fc1e06 | Stavros Sachtouris | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 97fc1e06 | Stavros Sachtouris | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 97fc1e06 | Stavros Sachtouris | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 97fc1e06 | Stavros Sachtouris | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 97fc1e06 | Stavros Sachtouris | #
|
29 | 97fc1e06 | Stavros Sachtouris | # The views and conclusions contained in the software and
|
30 | 97fc1e06 | Stavros Sachtouris | # documentation are those of the authors and should not be
|
31 | 97fc1e06 | Stavros Sachtouris | # interpreted as representing official policies, either expressed
|
32 | 97fc1e06 | Stavros Sachtouris | # or implied, of GRNET S.A.command
|
33 | 97fc1e06 | Stavros Sachtouris | |
34 | 84b0517f | Stavros Sachtouris | from json import loads |
35 | 84b0517f | Stavros Sachtouris | |
36 | d1d0cec9 | Stavros Sachtouris | from astakosclient import AstakosClient, AstakosClientException |
37 | 97fc1e06 | Stavros Sachtouris | |
38 | 97fc1e06 | Stavros Sachtouris | from kamaki.cli import command |
39 | 82e32e50 | Stavros Sachtouris | from kamaki.cli.errors import CLIBaseUrlError |
40 | b4f69041 | Stavros Sachtouris | from kamaki.cli.commands import ( |
41 | b4f69041 | Stavros Sachtouris | _command_init, errors, _optional_json, addLogSettings) |
42 | 97fc1e06 | Stavros Sachtouris | from kamaki.cli.command_tree import CommandTree |
43 | 31618e2a | Stavros Sachtouris | from kamaki.cli.utils import print_dict, format_size |
44 | 683335b1 | Stavros Sachtouris | from kamaki.cli.argument import FlagArgument, ValueArgument |
45 | 0155548b | Stavros Sachtouris | from kamaki.cli.argument import CommaSeparatedListArgument |
46 | 9b47150e | Stavros Sachtouris | from kamaki.cli.logger import get_logger |
47 | 97fc1e06 | Stavros Sachtouris | |
48 | 97fc1e06 | Stavros Sachtouris | snfastakos_cmds = CommandTree('astakos', 'astakosclient CLI') |
49 | 97fc1e06 | Stavros Sachtouris | _commands = [snfastakos_cmds] |
50 | 97fc1e06 | Stavros Sachtouris | |
51 | 97fc1e06 | Stavros Sachtouris | |
52 | d1d0cec9 | Stavros Sachtouris | def astakoserror(foo): |
53 | d1d0cec9 | Stavros Sachtouris | def _raise(self, *args, **kwargs): |
54 | d1d0cec9 | Stavros Sachtouris | try:
|
55 | d1d0cec9 | Stavros Sachtouris | return foo(self, *args, **kwargs) |
56 | d1d0cec9 | Stavros Sachtouris | except AstakosClientException as ace: |
57 | d1d0cec9 | Stavros Sachtouris | try:
|
58 | d1d0cec9 | Stavros Sachtouris | ace.details = ['%s' % ace.details]
|
59 | d1d0cec9 | Stavros Sachtouris | except Exception: |
60 | d1d0cec9 | Stavros Sachtouris | pass
|
61 | d1d0cec9 | Stavros Sachtouris | finally:
|
62 | d1d0cec9 | Stavros Sachtouris | raise ace
|
63 | d1d0cec9 | Stavros Sachtouris | return _raise
|
64 | d1d0cec9 | Stavros Sachtouris | |
65 | d1d0cec9 | Stavros Sachtouris | |
66 | 97fc1e06 | Stavros Sachtouris | class _astakos_init(_command_init): |
67 | 97fc1e06 | Stavros Sachtouris | |
68 | b4f69041 | Stavros Sachtouris | def __init__(self, arguments=dict(), auth_base=None, cloud=None): |
69 | b4f69041 | Stavros Sachtouris | super(_astakos_init, self).__init__(arguments, auth_base, cloud) |
70 | 683335b1 | Stavros Sachtouris | self['token'] = ValueArgument('Custom token', '--token') |
71 | 683335b1 | Stavros Sachtouris | |
72 | 97fc1e06 | Stavros Sachtouris | @errors.generic.all
|
73 | d1d0cec9 | Stavros Sachtouris | @astakoserror
|
74 | b4f69041 | Stavros Sachtouris | @addLogSettings
|
75 | 97fc1e06 | Stavros Sachtouris | def _run(self): |
76 | b4f69041 | Stavros Sachtouris | self.cloud = self.cloud if self.cloud else 'default' |
77 | b4f69041 | Stavros Sachtouris | self.token = self['token'] or self._custom_token('astakos')\ |
78 | 144b3551 | Stavros Sachtouris | or self.config.get_cloud(self.cloud, 'token') |
79 | 82e32e50 | Stavros Sachtouris | if getattr(self, 'auth_base', False): |
80 | 82e32e50 | Stavros Sachtouris | astakos_endpoints = self.auth_base.get_service_endpoints(
|
81 | b4f69041 | Stavros Sachtouris | self._custom_type('astakos') or 'identity', |
82 | b4f69041 | Stavros Sachtouris | self._custom_version('astakos') or '') |
83 | 31618e2a | Stavros Sachtouris | base_url = astakos_endpoints['SNF:uiURL']
|
84 | 0155548b | Stavros Sachtouris | base_url = base_url[:-3]
|
85 | 0155548b | Stavros Sachtouris | #base_url = ''.join(base_url.split('/ui'))
|
86 | 82e32e50 | Stavros Sachtouris | else:
|
87 | b4f69041 | Stavros Sachtouris | base_url = self._custom_url('astakos') |
88 | 82e32e50 | Stavros Sachtouris | if not base_url: |
89 | 82e32e50 | Stavros Sachtouris | raise CLIBaseUrlError(service='astakos') |
90 | 556e6916 | Stavros Sachtouris | self.client = AstakosClient(
|
91 | 556e6916 | Stavros Sachtouris | base_url, logger=get_logger('kamaki.clients'))
|
92 | 97fc1e06 | Stavros Sachtouris | |
93 | 97fc1e06 | Stavros Sachtouris | def main(self): |
94 | 97fc1e06 | Stavros Sachtouris | self._run()
|
95 | 97fc1e06 | Stavros Sachtouris | |
96 | 97fc1e06 | Stavros Sachtouris | |
97 | 97fc1e06 | Stavros Sachtouris | @command(snfastakos_cmds)
|
98 | d1d0cec9 | Stavros Sachtouris | class astakos_user_info(_astakos_init, _optional_json): |
99 | 97fc1e06 | Stavros Sachtouris | """Authenticate a user
|
100 | 97fc1e06 | Stavros Sachtouris | Get user information (e.g. unique account name) from token
|
101 | 97fc1e06 | Stavros Sachtouris | Token should be set in settings:
|
102 | 144b3551 | Stavros Sachtouris | * check if a token is set /config get cloud.default.token
|
103 | 144b3551 | Stavros Sachtouris | * permanently set a token /config set cloud.default.token <token>
|
104 | 97fc1e06 | Stavros Sachtouris | Token can also be provided as a parameter
|
105 | 144b3551 | Stavros Sachtouris | (To use a named cloud, use its name instead of "default")
|
106 | 97fc1e06 | Stavros Sachtouris | """
|
107 | 97fc1e06 | Stavros Sachtouris | |
108 | 97fc1e06 | Stavros Sachtouris | arguments = dict(
|
109 | 97fc1e06 | Stavros Sachtouris | usage=FlagArgument('also return usage information', ('--with-usage')) |
110 | 97fc1e06 | Stavros Sachtouris | ) |
111 | 97fc1e06 | Stavros Sachtouris | |
112 | d1d0cec9 | Stavros Sachtouris | @errors.generic.all
|
113 | d1d0cec9 | Stavros Sachtouris | @astakoserror
|
114 | 683335b1 | Stavros Sachtouris | def _run(self): |
115 | 97fc1e06 | Stavros Sachtouris | self._print(
|
116 | e1c18867 | Stavros Sachtouris | self.client.get_user_info(self.token, self['usage']), print_dict) |
117 | 97fc1e06 | Stavros Sachtouris | |
118 | 683335b1 | Stavros Sachtouris | def main(self): |
119 | 683335b1 | Stavros Sachtouris | super(self.__class__, self)._run() |
120 | 683335b1 | Stavros Sachtouris | self._run()
|
121 | 683335b1 | Stavros Sachtouris | |
122 | 683335b1 | Stavros Sachtouris | |
123 | 683335b1 | Stavros Sachtouris | @command(snfastakos_cmds)
|
124 | d1d0cec9 | Stavros Sachtouris | class astakos_user_name(_astakos_init, _optional_json): |
125 | 683335b1 | Stavros Sachtouris | """Get username(s) from uuid(s)"""
|
126 | 683335b1 | Stavros Sachtouris | |
127 | 683335b1 | Stavros Sachtouris | arguments = dict(
|
128 | 683335b1 | Stavros Sachtouris | service_token=ValueArgument( |
129 | 683335b1 | Stavros Sachtouris | 'Use service token instead', '--service-token') |
130 | 683335b1 | Stavros Sachtouris | ) |
131 | 683335b1 | Stavros Sachtouris | |
132 | d1d0cec9 | Stavros Sachtouris | @errors.generic.all
|
133 | d1d0cec9 | Stavros Sachtouris | @astakoserror
|
134 | 683335b1 | Stavros Sachtouris | def _run(self, uuids): |
135 | 683335b1 | Stavros Sachtouris | assert uuids and isinstance(uuids, list), 'No valid uuids' |
136 | 683335b1 | Stavros Sachtouris | if 1 == len(uuids): |
137 | 683335b1 | Stavros Sachtouris | self._print(self.client.get_username(self.token, uuids[0])) |
138 | 683335b1 | Stavros Sachtouris | else:
|
139 | 683335b1 | Stavros Sachtouris | self._print(
|
140 | 683335b1 | Stavros Sachtouris | self.client.get_username(self.token, uuids), print_dict) |
141 | 683335b1 | Stavros Sachtouris | |
142 | 683335b1 | Stavros Sachtouris | def main(self, uuid, *more_uuids): |
143 | 683335b1 | Stavros Sachtouris | super(self.__class__, self)._run() |
144 | 683335b1 | Stavros Sachtouris | self._run([uuid] + list(more_uuids)) |
145 | 683335b1 | Stavros Sachtouris | |
146 | 683335b1 | Stavros Sachtouris | |
147 | 683335b1 | Stavros Sachtouris | @command(snfastakos_cmds)
|
148 | d1d0cec9 | Stavros Sachtouris | class astakos_user_uuid(_astakos_init, _optional_json): |
149 | 683335b1 | Stavros Sachtouris | """Get uuid(s) from username(s)"""
|
150 | 683335b1 | Stavros Sachtouris | |
151 | d1d0cec9 | Stavros Sachtouris | @errors.generic.all
|
152 | d1d0cec9 | Stavros Sachtouris | @astakoserror
|
153 | 683335b1 | Stavros Sachtouris | def _run(self, usernames): |
154 | 683335b1 | Stavros Sachtouris | assert usernames and isinstance(usernames, list), 'No valid usernames' |
155 | 683335b1 | Stavros Sachtouris | if 1 == len(usernames): |
156 | 683335b1 | Stavros Sachtouris | self._print(self.client.get_uuid(self.token, usernames[0])) |
157 | 683335b1 | Stavros Sachtouris | else:
|
158 | 683335b1 | Stavros Sachtouris | self._print(
|
159 | 683335b1 | Stavros Sachtouris | self.client.get_uuids(self.token, usernames), print_dict) |
160 | 683335b1 | Stavros Sachtouris | |
161 | 683335b1 | Stavros Sachtouris | def main(self, usernames, *more_usernames): |
162 | 683335b1 | Stavros Sachtouris | super(self.__class__, self)._run() |
163 | 683335b1 | Stavros Sachtouris | self._run([usernames] + list(more_usernames)) |
164 | 683335b1 | Stavros Sachtouris | |
165 | 683335b1 | Stavros Sachtouris | |
166 | 683335b1 | Stavros Sachtouris | @command(snfastakos_cmds)
|
167 | 683335b1 | Stavros Sachtouris | class astakos_quotas(_astakos_init, _optional_json): |
168 | 683335b1 | Stavros Sachtouris | """Get user (or service) quotas"""
|
169 | 683335b1 | Stavros Sachtouris | |
170 | 31618e2a | Stavros Sachtouris | @staticmethod
|
171 | 31618e2a | Stavros Sachtouris | def _print_with_format(d): |
172 | 31618e2a | Stavros Sachtouris | """ Print d with size formating when needed
|
173 | 31618e2a | Stavros Sachtouris | :param d: (dict) {system: {<service>: {usage: ..., limit: ..., }, ...}}
|
174 | 31618e2a | Stavros Sachtouris | """
|
175 | 31618e2a | Stavros Sachtouris | newd = dict()
|
176 | 31618e2a | Stavros Sachtouris | for k, service in d['system'].items(): |
177 | 31618e2a | Stavros Sachtouris | newd[k] = dict(service)
|
178 | 31618e2a | Stavros Sachtouris | for term in ('usage', 'limit'): |
179 | 31618e2a | Stavros Sachtouris | if term in service: |
180 | 31618e2a | Stavros Sachtouris | newd[k][term] = format_size(service[term]) |
181 | 31618e2a | Stavros Sachtouris | print_dict(newd) |
182 | 31618e2a | Stavros Sachtouris | |
183 | d1d0cec9 | Stavros Sachtouris | @errors.generic.all
|
184 | d1d0cec9 | Stavros Sachtouris | @astakoserror
|
185 | 683335b1 | Stavros Sachtouris | def _run(self): |
186 | 31618e2a | Stavros Sachtouris | self._print(
|
187 | 31618e2a | Stavros Sachtouris | self.client.get_quotas(self.token), self._print_with_format) |
188 | 683335b1 | Stavros Sachtouris | |
189 | 683335b1 | Stavros Sachtouris | def main(self): |
190 | 683335b1 | Stavros Sachtouris | super(self.__class__, self)._run() |
191 | 683335b1 | Stavros Sachtouris | self._run()
|
192 | 683335b1 | Stavros Sachtouris | |
193 | 683335b1 | Stavros Sachtouris | |
194 | 683335b1 | Stavros Sachtouris | @command(snfastakos_cmds)
|
195 | 683335b1 | Stavros Sachtouris | class astakos_services(_astakos_init): |
196 | 683335b1 | Stavros Sachtouris | """Astakos operations filtered by services"""
|
197 | 683335b1 | Stavros Sachtouris | |
198 | 683335b1 | Stavros Sachtouris | |
199 | 683335b1 | Stavros Sachtouris | @command(snfastakos_cmds)
|
200 | e1c18867 | Stavros Sachtouris | class astakos_services_list(_astakos_init, _optional_json): |
201 | 683335b1 | Stavros Sachtouris | """List available services"""
|
202 | 683335b1 | Stavros Sachtouris | |
203 | d1d0cec9 | Stavros Sachtouris | @errors.generic.all
|
204 | d1d0cec9 | Stavros Sachtouris | @astakoserror
|
205 | 683335b1 | Stavros Sachtouris | def _run(self): |
206 | 683335b1 | Stavros Sachtouris | self._print(self.client.get_services()) |
207 | 683335b1 | Stavros Sachtouris | |
208 | 683335b1 | Stavros Sachtouris | def main(self): |
209 | 683335b1 | Stavros Sachtouris | super(self.__class__, self)._run() |
210 | 683335b1 | Stavros Sachtouris | self._run()
|
211 | 683335b1 | Stavros Sachtouris | |
212 | 683335b1 | Stavros Sachtouris | |
213 | 683335b1 | Stavros Sachtouris | @command(snfastakos_cmds)
|
214 | 683335b1 | Stavros Sachtouris | class astakos_services_username(_astakos_init, _optional_json): |
215 | 683335b1 | Stavros Sachtouris | """Get service username(s) from uuid(s)"""
|
216 | 683335b1 | Stavros Sachtouris | |
217 | d1d0cec9 | Stavros Sachtouris | @errors.generic.all
|
218 | d1d0cec9 | Stavros Sachtouris | @astakoserror
|
219 | 683335b1 | Stavros Sachtouris | def _run(self, stoken, uuids): |
220 | 683335b1 | Stavros Sachtouris | assert uuids and isinstance(uuids, list), 'No valid uuids' |
221 | 683335b1 | Stavros Sachtouris | if 1 == len(uuids): |
222 | 683335b1 | Stavros Sachtouris | self._print(self.client.service_get_username(stoken, uuids[0])) |
223 | 683335b1 | Stavros Sachtouris | else:
|
224 | 683335b1 | Stavros Sachtouris | self._print(
|
225 | 683335b1 | Stavros Sachtouris | self.client.service_get_usernames(stoken, uuids), print_dict)
|
226 | 683335b1 | Stavros Sachtouris | |
227 | 683335b1 | Stavros Sachtouris | def main(self, service_token, uuid, *more_uuids): |
228 | 683335b1 | Stavros Sachtouris | super(self.__class__, self)._run() |
229 | 683335b1 | Stavros Sachtouris | self._run(service_token, [uuid] + list(more_uuids)) |
230 | 683335b1 | Stavros Sachtouris | |
231 | 683335b1 | Stavros Sachtouris | |
232 | 683335b1 | Stavros Sachtouris | @command(snfastakos_cmds)
|
233 | 683335b1 | Stavros Sachtouris | class astakos_services_uuid(_astakos_init, _optional_json): |
234 | 683335b1 | Stavros Sachtouris | """Get service uuid(s) from username(s)"""
|
235 | 683335b1 | Stavros Sachtouris | |
236 | d1d0cec9 | Stavros Sachtouris | @errors.generic.all
|
237 | d1d0cec9 | Stavros Sachtouris | @astakoserror
|
238 | 683335b1 | Stavros Sachtouris | def _run(self, stoken, usernames): |
239 | 683335b1 | Stavros Sachtouris | assert usernames and isinstance(usernames, list), 'No valid usernames' |
240 | 683335b1 | Stavros Sachtouris | if 1 == len(usernames): |
241 | 683335b1 | Stavros Sachtouris | self._print(self.client.service_get_uuid(self.token, usernames[0])) |
242 | 683335b1 | Stavros Sachtouris | else:
|
243 | 683335b1 | Stavros Sachtouris | self._print(
|
244 | 683335b1 | Stavros Sachtouris | self.client.service_get_uuids(self.token, usernames), |
245 | 683335b1 | Stavros Sachtouris | print_dict) |
246 | 683335b1 | Stavros Sachtouris | |
247 | 683335b1 | Stavros Sachtouris | def main(self, service_token, usernames, *more_usernames): |
248 | 683335b1 | Stavros Sachtouris | super(self.__class__, self)._run() |
249 | 683335b1 | Stavros Sachtouris | self._run(service_token, [usernames] + list(more_usernames)) |
250 | 683335b1 | Stavros Sachtouris | |
251 | 683335b1 | Stavros Sachtouris | |
252 | 683335b1 | Stavros Sachtouris | @command(snfastakos_cmds)
|
253 | 683335b1 | Stavros Sachtouris | class astakos_services_quotas(_astakos_init, _optional_json): |
254 | 683335b1 | Stavros Sachtouris | """Get user (or service) quotas"""
|
255 | 683335b1 | Stavros Sachtouris | |
256 | 683335b1 | Stavros Sachtouris | arguments = dict(
|
257 | 683335b1 | Stavros Sachtouris | uuid=ValueArgument('A user unique id to get quotas for', '--uuid') |
258 | 683335b1 | Stavros Sachtouris | ) |
259 | 683335b1 | Stavros Sachtouris | |
260 | d1d0cec9 | Stavros Sachtouris | @errors.generic.all
|
261 | d1d0cec9 | Stavros Sachtouris | @astakoserror
|
262 | 683335b1 | Stavros Sachtouris | def _run(self, stoken): |
263 | 683335b1 | Stavros Sachtouris | self._print(self.client.service_get_quotas(stoken, self['uuid'])) |
264 | 683335b1 | Stavros Sachtouris | |
265 | 683335b1 | Stavros Sachtouris | def main(self, service_token): |
266 | 97fc1e06 | Stavros Sachtouris | super(self.__class__, self)._run() |
267 | 683335b1 | Stavros Sachtouris | self._run(service_token)
|
268 | d1d0cec9 | Stavros Sachtouris | |
269 | d1d0cec9 | Stavros Sachtouris | |
270 | d1d0cec9 | Stavros Sachtouris | @command(snfastakos_cmds)
|
271 | d1d0cec9 | Stavros Sachtouris | class astakos_resources(_astakos_init, _optional_json): |
272 | d1d0cec9 | Stavros Sachtouris | """List user resources"""
|
273 | d1d0cec9 | Stavros Sachtouris | |
274 | d1d0cec9 | Stavros Sachtouris | @errors.generic.all
|
275 | d1d0cec9 | Stavros Sachtouris | @astakoserror
|
276 | d1d0cec9 | Stavros Sachtouris | def _run(self): |
277 | d1d0cec9 | Stavros Sachtouris | self._print(self.client.get_resources(), print_dict) |
278 | d1d0cec9 | Stavros Sachtouris | |
279 | d1d0cec9 | Stavros Sachtouris | def main(self): |
280 | d1d0cec9 | Stavros Sachtouris | super(self.__class__, self)._run() |
281 | d1d0cec9 | Stavros Sachtouris | self._run()
|
282 | d1d0cec9 | Stavros Sachtouris | |
283 | d1d0cec9 | Stavros Sachtouris | |
284 | d1d0cec9 | Stavros Sachtouris | @command(snfastakos_cmds)
|
285 | d1d0cec9 | Stavros Sachtouris | class astakos_feedback(_astakos_init): |
286 | d1d0cec9 | Stavros Sachtouris | """Send feedback to astakos server"""
|
287 | d1d0cec9 | Stavros Sachtouris | |
288 | d1d0cec9 | Stavros Sachtouris | @errors.generic.all
|
289 | d1d0cec9 | Stavros Sachtouris | @astakoserror
|
290 | d1d0cec9 | Stavros Sachtouris | def _run(self, msg, more_info=None): |
291 | 0155548b | Stavros Sachtouris | self.client.send_feedback(self.token, msg, more_info or '') |
292 | d1d0cec9 | Stavros Sachtouris | |
293 | d1d0cec9 | Stavros Sachtouris | def main(self, message, more_info=None): |
294 | d1d0cec9 | Stavros Sachtouris | super(self.__class__, self)._run() |
295 | d1d0cec9 | Stavros Sachtouris | self._run(message, more_info)
|
296 | d1d0cec9 | Stavros Sachtouris | |
297 | d1d0cec9 | Stavros Sachtouris | |
298 | d1d0cec9 | Stavros Sachtouris | @command(snfastakos_cmds)
|
299 | d1d0cec9 | Stavros Sachtouris | class astakos_endpoints(_astakos_init, _optional_json): |
300 | d1d0cec9 | Stavros Sachtouris | """Get endpoints service endpoints"""
|
301 | d1d0cec9 | Stavros Sachtouris | |
302 | 0155548b | Stavros Sachtouris | arguments = dict(uuid=ValueArgument('User uuid', '--uuid')) |
303 | 0155548b | Stavros Sachtouris | |
304 | 0155548b | Stavros Sachtouris | @errors.generic.all
|
305 | 0155548b | Stavros Sachtouris | @astakoserror
|
306 | 0155548b | Stavros Sachtouris | def _run(self): |
307 | 0155548b | Stavros Sachtouris | self._print(
|
308 | 0155548b | Stavros Sachtouris | self.client.get_endpoints(self.token, self['uuid']), |
309 | 0155548b | Stavros Sachtouris | print_dict) |
310 | 0155548b | Stavros Sachtouris | |
311 | 0155548b | Stavros Sachtouris | def main(self): |
312 | 0155548b | Stavros Sachtouris | super(self.__class__, self)._run() |
313 | 0155548b | Stavros Sachtouris | self._run()
|
314 | 0155548b | Stavros Sachtouris | |
315 | 0155548b | Stavros Sachtouris | |
316 | 0155548b | Stavros Sachtouris | @command(snfastakos_cmds)
|
317 | 0155548b | Stavros Sachtouris | class astakos_commission(_astakos_init): |
318 | 0155548b | Stavros Sachtouris | """Manage commissions (special privileges required)"""
|
319 | 0155548b | Stavros Sachtouris | |
320 | 0155548b | Stavros Sachtouris | |
321 | 0155548b | Stavros Sachtouris | @command(snfastakos_cmds)
|
322 | 0155548b | Stavros Sachtouris | class astakos_commission_pending(_astakos_init, _optional_json): |
323 | 0155548b | Stavros Sachtouris | """List pending commissions (special privileges required)"""
|
324 | 0155548b | Stavros Sachtouris | |
325 | 0155548b | Stavros Sachtouris | @errors.generic.all
|
326 | 0155548b | Stavros Sachtouris | @astakoserror
|
327 | 0155548b | Stavros Sachtouris | def _run(self): |
328 | 0155548b | Stavros Sachtouris | self._print(self.client.get_pending_commissions(self.token)) |
329 | 0155548b | Stavros Sachtouris | |
330 | 0155548b | Stavros Sachtouris | def main(self): |
331 | 0155548b | Stavros Sachtouris | super(self.__class__, self)._run() |
332 | 0155548b | Stavros Sachtouris | self._run()
|
333 | 0155548b | Stavros Sachtouris | |
334 | 0155548b | Stavros Sachtouris | |
335 | 0155548b | Stavros Sachtouris | @command(snfastakos_cmds)
|
336 | 0155548b | Stavros Sachtouris | class astakos_commission_info(_astakos_init, _optional_json): |
337 | 0155548b | Stavros Sachtouris | """Get commission info (special privileges required)"""
|
338 | 0155548b | Stavros Sachtouris | |
339 | 0155548b | Stavros Sachtouris | @errors.generic.all
|
340 | 0155548b | Stavros Sachtouris | @astakoserror
|
341 | 0155548b | Stavros Sachtouris | def _run(self, commission_id): |
342 | 0155548b | Stavros Sachtouris | commission_id = int(commission_id)
|
343 | 0155548b | Stavros Sachtouris | self._print(
|
344 | 0155548b | Stavros Sachtouris | self.client.get_commission_info(self.token, commission_id), |
345 | 0155548b | Stavros Sachtouris | print_dict) |
346 | 0155548b | Stavros Sachtouris | |
347 | 0155548b | Stavros Sachtouris | def main(self, commission_id): |
348 | 0155548b | Stavros Sachtouris | super(self.__class__, self)._run() |
349 | 0155548b | Stavros Sachtouris | self._run(commission_id)
|
350 | 0155548b | Stavros Sachtouris | |
351 | 0155548b | Stavros Sachtouris | |
352 | 0155548b | Stavros Sachtouris | @command(snfastakos_cmds)
|
353 | 0155548b | Stavros Sachtouris | class astakos_commission_action(_astakos_init, _optional_json): |
354 | 0155548b | Stavros Sachtouris | """Invoke an action in a commission (special privileges required)
|
355 | 0155548b | Stavros Sachtouris | Actions can be accept or reject
|
356 | 0155548b | Stavros Sachtouris | """
|
357 | 0155548b | Stavros Sachtouris | |
358 | 0155548b | Stavros Sachtouris | actions = ('accept', 'reject') |
359 | 0155548b | Stavros Sachtouris | |
360 | 0155548b | Stavros Sachtouris | @errors.generic.all
|
361 | 0155548b | Stavros Sachtouris | @astakoserror
|
362 | 0155548b | Stavros Sachtouris | def _run(self, commission_id, action): |
363 | 0155548b | Stavros Sachtouris | commission_id = int(commission_id)
|
364 | 0155548b | Stavros Sachtouris | action = action.lower() |
365 | 0155548b | Stavros Sachtouris | assert action in self.actions, 'Actions can be %s' % ( |
366 | 0155548b | Stavros Sachtouris | ' or '.join(self.actions)) |
367 | 0155548b | Stavros Sachtouris | self._print(
|
368 | 0155548b | Stavros Sachtouris | self.client.commission_acction(self.token, commission_id, action), |
369 | 0155548b | Stavros Sachtouris | print_dict) |
370 | 0155548b | Stavros Sachtouris | |
371 | 0155548b | Stavros Sachtouris | def main(self, commission_id, action): |
372 | 0155548b | Stavros Sachtouris | super(self.__class__, self)._run() |
373 | 0155548b | Stavros Sachtouris | self._run(commission_id, action)
|
374 | 0155548b | Stavros Sachtouris | |
375 | 0155548b | Stavros Sachtouris | |
376 | 0155548b | Stavros Sachtouris | @command(snfastakos_cmds)
|
377 | 0155548b | Stavros Sachtouris | class astakos_commission_accept(_astakos_init): |
378 | 0155548b | Stavros Sachtouris | """Accept a pending commission (special privileges required)"""
|
379 | 0155548b | Stavros Sachtouris | |
380 | 0155548b | Stavros Sachtouris | @errors.generic.all
|
381 | 0155548b | Stavros Sachtouris | @astakoserror
|
382 | 0155548b | Stavros Sachtouris | def _run(self, commission_id): |
383 | 0155548b | Stavros Sachtouris | commission_id = int(commission_id)
|
384 | 0155548b | Stavros Sachtouris | self.client.accept_commission(self.token, commission_id) |
385 | 0155548b | Stavros Sachtouris | |
386 | 0155548b | Stavros Sachtouris | def main(self, commission_id): |
387 | 0155548b | Stavros Sachtouris | super(self.__class__, self)._run() |
388 | 0155548b | Stavros Sachtouris | self._run(commission_id)
|
389 | 0155548b | Stavros Sachtouris | |
390 | 0155548b | Stavros Sachtouris | |
391 | 0155548b | Stavros Sachtouris | @command(snfastakos_cmds)
|
392 | 0155548b | Stavros Sachtouris | class astakos_commission_reject(_astakos_init): |
393 | 0155548b | Stavros Sachtouris | """Reject a pending commission (special privileges required)"""
|
394 | 0155548b | Stavros Sachtouris | |
395 | 0155548b | Stavros Sachtouris | @errors.generic.all
|
396 | 0155548b | Stavros Sachtouris | @astakoserror
|
397 | 0155548b | Stavros Sachtouris | def _run(self, commission_id): |
398 | 0155548b | Stavros Sachtouris | commission_id = int(commission_id)
|
399 | 0155548b | Stavros Sachtouris | self.client.reject_commission(self.token, commission_id) |
400 | 0155548b | Stavros Sachtouris | |
401 | 0155548b | Stavros Sachtouris | def main(self, commission_id): |
402 | 0155548b | Stavros Sachtouris | super(self.__class__, self)._run() |
403 | 0155548b | Stavros Sachtouris | self._run(commission_id)
|
404 | 0155548b | Stavros Sachtouris | |
405 | 0155548b | Stavros Sachtouris | |
406 | 0155548b | Stavros Sachtouris | @command(snfastakos_cmds)
|
407 | 0155548b | Stavros Sachtouris | class astakos_commission_resolve(_astakos_init, _optional_json): |
408 | 0155548b | Stavros Sachtouris | """Resolve multiple commissions (special privileges required)"""
|
409 | 0155548b | Stavros Sachtouris | |
410 | d1d0cec9 | Stavros Sachtouris | arguments = dict(
|
411 | 0155548b | Stavros Sachtouris | accept=CommaSeparatedListArgument( |
412 | 0155548b | Stavros Sachtouris | 'commission ids to accept (e.g. --accept=11,12,13,...',
|
413 | 0155548b | Stavros Sachtouris | '--accept'),
|
414 | 0155548b | Stavros Sachtouris | reject=CommaSeparatedListArgument( |
415 | 0155548b | Stavros Sachtouris | 'commission ids to reject (e.g. --reject=11,12,13,...',
|
416 | 0155548b | Stavros Sachtouris | '--reject'),
|
417 | d1d0cec9 | Stavros Sachtouris | ) |
418 | d1d0cec9 | Stavros Sachtouris | |
419 | d1d0cec9 | Stavros Sachtouris | @errors.generic.all
|
420 | d1d0cec9 | Stavros Sachtouris | @astakoserror
|
421 | d1d0cec9 | Stavros Sachtouris | def _run(self): |
422 | 0155548b | Stavros Sachtouris | print 'accepted ', self['accept'] |
423 | 0155548b | Stavros Sachtouris | print 'rejected ', self['reject'] |
424 | d1d0cec9 | Stavros Sachtouris | self._print(
|
425 | 0155548b | Stavros Sachtouris | self.client.resolve_commissions(
|
426 | 0155548b | Stavros Sachtouris | self.token, self['accept'], self['reject']), |
427 | d1d0cec9 | Stavros Sachtouris | print_dict) |
428 | d1d0cec9 | Stavros Sachtouris | |
429 | d1d0cec9 | Stavros Sachtouris | def main(self): |
430 | d1d0cec9 | Stavros Sachtouris | super(self.__class__, self)._run() |
431 | d1d0cec9 | Stavros Sachtouris | self._run()
|
432 | d1d0cec9 | Stavros Sachtouris | |
433 | 84b0517f | Stavros Sachtouris | |
434 | 84b0517f | Stavros Sachtouris | @command(snfastakos_cmds)
|
435 | 84b0517f | Stavros Sachtouris | class astakos_commission_issue(_astakos_init, _optional_json): |
436 | 84b0517f | Stavros Sachtouris | """Issue commissions as a json string (special privileges required)
|
437 | 84b0517f | Stavros Sachtouris | Parameters:
|
438 | 84b0517f | Stavros Sachtouris | holder -- user's id (string)
|
439 | 84b0517f | Stavros Sachtouris | source -- commission's source (ex system) (string)
|
440 | 84b0517f | Stavros Sachtouris | provisions -- resources with their quantity (json-dict from string to int)
|
441 | 84b0517f | Stavros Sachtouris | name -- description of the commission (string)
|
442 | 84b0517f | Stavros Sachtouris | """
|
443 | 84b0517f | Stavros Sachtouris | |
444 | 84b0517f | Stavros Sachtouris | arguments = dict(
|
445 | 84b0517f | Stavros Sachtouris | force=FlagArgument('Force commission', '--force'), |
446 | 84b0517f | Stavros Sachtouris | accept=FlagArgument('Do not wait for verification', '--accept') |
447 | 84b0517f | Stavros Sachtouris | ) |
448 | 84b0517f | Stavros Sachtouris | |
449 | 84b0517f | Stavros Sachtouris | @errors.generic.all
|
450 | 84b0517f | Stavros Sachtouris | @astakoserror
|
451 | 84b0517f | Stavros Sachtouris | def _run( |
452 | 84b0517f | Stavros Sachtouris | self, holder, source, provisions, name=''): |
453 | 84b0517f | Stavros Sachtouris | provisions = loads(provisions) |
454 | 84b0517f | Stavros Sachtouris | self._print(self.client.issue_one_commission( |
455 | 84b0517f | Stavros Sachtouris | self.token, holder, source, provisions, name,
|
456 | 84b0517f | Stavros Sachtouris | self['force'], self['accept'])) |
457 | 84b0517f | Stavros Sachtouris | |
458 | 84b0517f | Stavros Sachtouris | def main(self, holder, source, provisions, name=''): |
459 | 84b0517f | Stavros Sachtouris | super(self.__class__, self)._run() |
460 | 84b0517f | Stavros Sachtouris | self._run(holder, source, provisions, name)
|
461 | 84b0517f | Stavros Sachtouris | |
462 | 84b0517f | Stavros Sachtouris | |
463 | 84b0517f | Stavros Sachtouris | @command(snfastakos_cmds)
|
464 | 84b0517f | Stavros Sachtouris | class astakos_commission_issuejson(_astakos_init, _optional_json): |
465 | 84b0517f | Stavros Sachtouris | """Issue commissions as a json string (special privileges required)"""
|
466 | 84b0517f | Stavros Sachtouris | |
467 | 84b0517f | Stavros Sachtouris | @errors.generic.all
|
468 | 84b0517f | Stavros Sachtouris | @astakoserror
|
469 | 84b0517f | Stavros Sachtouris | def _run(self, info_json): |
470 | 84b0517f | Stavros Sachtouris | infodict = loads(info_json) |
471 | 84b0517f | Stavros Sachtouris | self._print(self.client.issue_commission(self.token, infodict)) |
472 | 84b0517f | Stavros Sachtouris | |
473 | 84b0517f | Stavros Sachtouris | def main(self, info_json): |
474 | 84b0517f | Stavros Sachtouris | super(self.__class__, self)._run() |
475 | 84b0517f | Stavros Sachtouris | self._run(info_json)
|
476 | 0155548b | Stavros Sachtouris | |
477 | 0155548b | Stavros Sachtouris | # XXX issue_commission, issue_one_commission
|
478 | 0155548b | Stavros Sachtouris | |
479 | d1d0cec9 | Stavros Sachtouris | |
480 | d1d0cec9 | Stavros Sachtouris | @command(snfastakos_cmds)
|
481 | d1d0cec9 | Stavros Sachtouris | class astakos_test(_astakos_init): |
482 | d1d0cec9 | Stavros Sachtouris | """Test an astakos command"""
|
483 | d1d0cec9 | Stavros Sachtouris | |
484 | d1d0cec9 | Stavros Sachtouris | @errors.generic.all
|
485 | d1d0cec9 | Stavros Sachtouris | @astakoserror
|
486 | d1d0cec9 | Stavros Sachtouris | def _run(self, *args): |
487 | 0155548b | Stavros Sachtouris | r = self.client.get_pending_commissions(self.token) |
488 | 0155548b | Stavros Sachtouris | print r
|
489 | d1d0cec9 | Stavros Sachtouris | |
490 | d1d0cec9 | Stavros Sachtouris | def main(self, *args): |
491 | d1d0cec9 | Stavros Sachtouris | super(self.__class__, self)._run() |
492 | d1d0cec9 | Stavros Sachtouris | self._run(*args) |