Revision 76f58e2e
b/kamaki/cli/commands/__init__.py | ||
---|---|---|
103 | 103 |
|
104 | 104 |
def print_list(self, *args, **kwargs): |
105 | 105 |
kwargs.setdefault('out', self._out) |
106 |
return print_list(*args, out=self._out, **kwargs)
|
|
106 |
return print_list(*args, **kwargs) |
|
107 | 107 |
|
108 | 108 |
def print_dict(self, *args, **kwargs): |
109 | 109 |
kwargs.setdefault('out', self._out) |
110 |
return print_dict(*args, out=self._out, **kwargs)
|
|
110 |
return print_dict(*args, **kwargs) |
|
111 | 111 |
|
112 | 112 |
def print_json(self, *args, **kwargs): |
113 | 113 |
kwargs.setdefault('out', self._out) |
114 |
return print_json(*args, out=self._out, **kwargs)
|
|
114 |
return print_json(*args, **kwargs) |
|
115 | 115 |
|
116 | 116 |
def print_items(self, *args, **kwargs): |
117 | 117 |
kwargs.setdefault('out', self._out) |
118 |
return print_items(*args, out=self._out, **kwargs)
|
|
118 |
return print_items(*args, **kwargs) |
|
119 | 119 |
|
120 | 120 |
def ask_user(self, *args, **kwargs): |
121 | 121 |
kwargs.setdefault('user_in', self._in) |
122 | 122 |
kwargs.setdefault('out', self._out) |
123 |
return print_items(*args, out=self._out, **kwargs)
|
|
123 |
return ask_user(*args, **kwargs)
|
|
124 | 124 |
|
125 | 125 |
@DontRaiseKeyError |
126 | 126 |
def _custom_url(self, service): |
b/kamaki/cli/commands/astakos.py | ||
---|---|---|
37 | 37 |
_command_init, errors, _optional_json, addLogSettings) |
38 | 38 |
from kamaki.cli.command_tree import CommandTree |
39 | 39 |
from kamaki.cli.errors import CLIBaseUrlError, CLIError |
40 |
from kamaki.cli.utils import print_dict, ask_user, stdout |
|
41 | 40 |
|
42 | 41 |
user_cmds = CommandTree('user', 'Astakos API commands') |
43 | 42 |
_commands = [user_cmds] |
... | ... | |
93 | 92 |
token_bu = self.client.token |
94 | 93 |
try: |
95 | 94 |
r = self.client.authenticate(custom_token) |
96 |
if (token_bu != self.client.token and |
|
97 |
ask_user('Permanently save token as cloud.%s.token ?' % (
|
|
95 |
if (token_bu != self.client.token and self.ask_user(
|
|
96 |
'Permanently save token as cloud.%s.token ?' % ( |
|
98 | 97 |
self.cloud))): |
99 | 98 |
self._write_main_token(self.client.token) |
100 | 99 |
except Exception: |
... | ... | |
103 | 102 |
raise |
104 | 103 |
|
105 | 104 |
def _print_access(r, out): |
106 |
print_dict(r['access'], out=out) |
|
105 |
self.print_dict(r['access'], out=out)
|
|
107 | 106 |
|
108 | 107 |
self._print(r, _print_access) |
109 | 108 |
|
... | ... | |
131 | 130 |
|
132 | 131 |
@errors.generic.all |
133 | 132 |
def _run(self): |
134 |
self._print(self.client.user_info(), print_dict) |
|
133 |
self._print(self.client.user_info(), self.print_dict)
|
|
135 | 134 |
|
136 | 135 |
def main(self): |
137 | 136 |
super(self.__class__, self)._run() |
... | ... | |
163 | 162 |
self.error('Session user set to %s (%s)' % ( |
164 | 163 |
self.client.user_term('name'), |
165 | 164 |
self.client.user_term('id'))) |
166 |
if ask_user( |
|
165 |
if self.ask_user(
|
|
167 | 166 |
'Permanently make %s the main user?' % ( |
168 |
self.client.user_term('name')), |
|
169 |
out=self._out, user_in=self._in): |
|
167 |
self.client.user_term('name'))): |
|
170 | 168 |
self._write_main_token(self.client.token) |
171 | 169 |
return |
172 | 170 |
raise CLIError( |
b/kamaki/cli/commands/config.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from sys import stdout |
|
35 |
|
|
36 | 34 |
from kamaki.cli import command |
37 | 35 |
from kamaki.cli.argument import FlagArgument |
38 | 36 |
from kamaki.cli.commands import _command_init, errors |
b/kamaki/cli/commands/cyclades.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from base64 import b64encode |
|
35 |
from os.path import exists |
|
36 |
from io import StringIO |
|
37 |
from pydoc import pager |
|
38 |
|
|
34 | 39 |
from kamaki.cli import command |
35 | 40 |
from kamaki.cli.command_tree import CommandTree |
36 |
from kamaki.cli.utils import ( |
|
37 |
print_dict, remove_from_items, filter_dicts_by_dict, pager) |
|
41 |
from kamaki.cli.utils import remove_from_items, filter_dicts_by_dict |
|
38 | 42 |
from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError |
39 | 43 |
from kamaki.clients.cyclades import CycladesClient, ClientError |
40 | 44 |
from kamaki.cli.argument import FlagArgument, ValueArgument, KeyValueArgument |
... | ... | |
43 | 47 |
from kamaki.cli.commands import ( |
44 | 48 |
_optional_output_cmd, _optional_json, _name_filter, _id_filter) |
45 | 49 |
|
46 |
from base64 import b64encode |
|
47 |
from os.path import exists |
|
48 |
from io import StringIO |
|
49 |
|
|
50 | 50 |
|
51 | 51 |
server_cmds = CommandTree('server', 'Cyclades/Compute API server commands') |
52 | 52 |
flavor_cmds = CommandTree('flavor', 'Cyclades/Compute API flavor commands') |
... | ... | |
270 | 270 |
uuids = self._uuids2usernames([vm['user_id'], vm['tenant_id']]) |
271 | 271 |
vm['user_id'] += ' (%s)' % uuids[vm['user_id']] |
272 | 272 |
vm['tenant_id'] += ' (%s)' % uuids[vm['tenant_id']] |
273 |
self._print(vm, print_dict) |
|
273 |
self._print(vm, self.print_dict)
|
|
274 | 274 |
|
275 | 275 |
def main(self, server_id): |
276 | 276 |
super(self.__class__, self)._run() |
... | ... | |
335 | 335 |
usernames = self._uuids2usernames([r['user_id'], r['tenant_id']]) |
336 | 336 |
r['user_id'] += ' (%s)' % usernames[r['user_id']] |
337 | 337 |
r['tenant_id'] += ' (%s)' % usernames[r['tenant_id']] |
338 |
self._print(r, print_dict) |
|
338 |
self._print(r, self.print_dict)
|
|
339 | 339 |
if self['wait']: |
340 | 340 |
self._wait(r['id'], r['status']) |
341 | 341 |
|
... | ... | |
488 | 488 |
@errors.cyclades.server_id |
489 | 489 |
def _run(self, server_id): |
490 | 490 |
self._print( |
491 |
self.client.get_server_console(int(server_id)), print_dict) |
|
491 |
self.client.get_server_console(int(server_id)), self.print_dict)
|
|
492 | 492 |
|
493 | 493 |
def main(self, server_id): |
494 | 494 |
super(self.__class__, self)._run() |
... | ... | |
592 | 592 |
@errors.cyclades.metadata |
593 | 593 |
def _run(self, server_id, key=''): |
594 | 594 |
self._print( |
595 |
self.client.get_server_metadata(int(server_id), key), print_dict) |
|
595 |
self.client.get_server_metadata(int(server_id), key), |
|
596 |
self.print_dict) |
|
596 | 597 |
|
597 | 598 |
def main(self, server_id, key=''): |
598 | 599 |
super(self.__class__, self)._run() |
... | ... | |
627 | 628 |
'key1=value1 key2=value2']) |
628 | 629 |
self._print( |
629 | 630 |
self.client.update_server_metadata(int(server_id), **metadata), |
630 |
print_dict) |
|
631 |
self.print_dict)
|
|
631 | 632 |
|
632 | 633 |
def main(self, server_id, *key_equals_val): |
633 | 634 |
super(self.__class__, self)._run() |
... | ... | |
659 | 660 |
@errors.cyclades.connection |
660 | 661 |
@errors.cyclades.server_id |
661 | 662 |
def _run(self, server_id): |
662 |
self._print(self.client.get_server_stats(int(server_id)), print_dict) |
|
663 |
self._print( |
|
664 |
self.client.get_server_stats(int(server_id)), self.print_dict) |
|
663 | 665 |
|
664 | 666 |
def main(self, server_id): |
665 | 667 |
super(self.__class__, self)._run() |
... | ... | |
754 | 756 |
@errors.cyclades.flavor_id |
755 | 757 |
def _run(self, flavor_id): |
756 | 758 |
self._print( |
757 |
self.client.get_flavor_details(int(flavor_id)), print_dict) |
|
759 |
self.client.get_flavor_details(int(flavor_id)), self.print_dict)
|
|
758 | 760 |
|
759 | 761 |
def main(self, flavor_id): |
760 | 762 |
super(self.__class__, self)._run() |
... | ... | |
787 | 789 |
def _run(self, network_id): |
788 | 790 |
network = self.client.get_network_details(int(network_id)) |
789 | 791 |
_add_name(self, network) |
790 |
self._print(network, print_dict, exclude=('id')) |
|
792 |
self._print(network, self.print_dict, exclude=('id'))
|
|
791 | 793 |
|
792 | 794 |
def main(self, network_id): |
793 | 795 |
super(self.__class__, self)._run() |
... | ... | |
919 | 921 |
dhcp=self['dhcp'], |
920 | 922 |
type=self['type']) |
921 | 923 |
_add_name(self, r) |
922 |
self._print(r, print_dict) |
|
924 |
self._print(r, self.print_dict)
|
|
923 | 925 |
if self['wait']: |
924 | 926 |
self._wait(r['id'], 'PENDING') |
925 | 927 |
|
... | ... | |
1079 | 1081 |
@errors.generic.all |
1080 | 1082 |
@errors.cyclades.connection |
1081 | 1083 |
def _run(self, ip): |
1082 |
self._print(self.client.get_floating_ip(ip), print_dict) |
|
1084 |
self._print(self.client.get_floating_ip(ip), self.print_dict)
|
|
1083 | 1085 |
|
1084 | 1086 |
def main(self, ip): |
1085 | 1087 |
super(self.__class__, self)._run() |
b/kamaki/cli/commands/history.py | ||
---|---|---|
41 | 41 |
from kamaki.cli.commands import _command_init, errors |
42 | 42 |
from kamaki.cli import exec_cmd, print_error_message |
43 | 43 |
from kamaki.cli.errors import CLIError, raiseCLIError |
44 |
from kamaki.cli.utils import split_input, print_list
|
|
44 |
from kamaki.cli.utils import split_input |
|
45 | 45 |
from kamaki.clients import ClientError |
46 | 46 |
|
47 | 47 |
|
... | ... | |
111 | 111 |
ret = self.history.get(match_terms=self['match'], limit=self['limit']) |
112 | 112 |
|
113 | 113 |
if not cmd_ids: |
114 |
print_list(ret, out=self._out)
|
|
114 |
self.print_list(ret)
|
|
115 | 115 |
return |
116 | 116 |
|
117 | 117 |
num_list = [] |
b/kamaki/cli/commands/image.py | ||
---|---|---|
35 | 35 |
from os import path |
36 | 36 |
from logging import getLogger |
37 | 37 |
from io import StringIO |
38 |
from pydoc import pager |
|
38 | 39 |
|
39 | 40 |
from kamaki.cli import command |
40 | 41 |
from kamaki.cli.command_tree import CommandTree |
41 |
from kamaki.cli.utils import ( |
|
42 |
print_dict, print_json, filter_dicts_by_dict, pager) |
|
42 |
from kamaki.cli.utils import filter_dicts_by_dict |
|
43 | 43 |
from kamaki.clients.image import ImageClient |
44 | 44 |
from kamaki.clients.pithos import PithosClient |
45 | 45 |
from kamaki.clients.astakos import AstakosClient |
... | ... | |
303 | 303 |
meta = self.client.get_meta(image_id) |
304 | 304 |
if not self['json_output']: |
305 | 305 |
meta['owner'] += ' (%s)' % self._uuid2username(meta['owner']) |
306 |
self._print(meta, print_dict) |
|
306 |
self._print(meta, self.print_dict)
|
|
307 | 307 |
|
308 | 308 |
def main(self, image_id): |
309 | 309 |
super(self.__class__, self)._run() |
... | ... | |
627 | 627 |
img_path, dst_cont)] + howto_image_file) |
628 | 628 |
raise |
629 | 629 |
r['owner'] += ' (%s)' % self._uuid2username(r['owner']) |
630 |
self._print(r, print_dict) |
|
630 |
self._print(r, self.print_dict)
|
|
631 | 631 |
|
632 | 632 |
#upload the metadata file |
633 | 633 |
if pclient: |
... | ... | |
640 | 640 |
'Failed to dump metafile %s:%s' % (dst_cont, meta_path)) |
641 | 641 |
return |
642 | 642 |
if self['json_output']: |
643 |
print_json(dict( |
|
643 |
self.print_json(dict(
|
|
644 | 644 |
metafile_location='%s:%s' % (dst_cont, meta_path), |
645 | 645 |
headers=meta_headers)) |
646 | 646 |
else: |
... | ... | |
855 | 855 |
usernames = self._uuids2usernames(uuids) |
856 | 856 |
image['user_id'] += ' (%s)' % usernames[image['user_id']] |
857 | 857 |
image['tenant_id'] += ' (%s)' % usernames[image['tenant_id']] |
858 |
self._print(image, print_dict) |
|
858 |
self._print(image, self.print_dict)
|
|
859 | 859 |
|
860 | 860 |
def main(self, image_id): |
861 | 861 |
super(self.__class__, self)._run() |
... | ... | |
890 | 890 |
@errors.cyclades.connection |
891 | 891 |
@errors.plankton.id |
892 | 892 |
def _run(self, image_id): |
893 |
self._print(self.client.get_image_metadata(image_id), print_dict) |
|
893 |
self._print(self.client.get_image_metadata(image_id), self.print_dict)
|
|
894 | 894 |
|
895 | 895 |
def main(self, image_id): |
896 | 896 |
super(self.__class__, self)._run() |
... | ... | |
906 | 906 |
@errors.plankton.id |
907 | 907 |
@errors.plankton.metadata |
908 | 908 |
def _run(self, image_id, key): |
909 |
self._print(self.client.get_image_metadata(image_id, key), print_dict) |
|
909 |
self._print( |
|
910 |
self.client.get_image_metadata(image_id, key), self.print_dict) |
|
910 | 911 |
|
911 | 912 |
def main(self, image_id, key): |
912 | 913 |
super(self.__class__, self)._run() |
... | ... | |
929 | 930 |
key, sep, val = keyval.partition('=') |
930 | 931 |
meta[key] = val |
931 | 932 |
self._print( |
932 |
self.client.update_image_metadata(image_id, **meta), print_dict) |
|
933 |
self.client.update_image_metadata(image_id, **meta), |
|
934 |
self.print_dict) |
|
933 | 935 |
|
934 | 936 |
def main(self, image_id, *key_equals_value): |
935 | 937 |
super(self.__class__, self)._run() |
b/kamaki/cli/commands/pithos.py | ||
---|---|---|
34 | 34 |
from time import localtime, strftime |
35 | 35 |
from os import path, makedirs, walk |
36 | 36 |
from io import StringIO |
37 |
from pydoc import pager |
|
37 | 38 |
|
38 | 39 |
from kamaki.cli import command |
39 | 40 |
from kamaki.cli.command_tree import CommandTree |
40 | 41 |
from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError |
41 | 42 |
from kamaki.cli.utils import ( |
42 |
format_size, to_bytes, print_dict, print_items, pager, bold, ask_user, |
|
43 |
get_path_size, guess_mime_type) |
|
43 |
format_size, to_bytes, bold, get_path_size, guess_mime_type) |
|
44 | 44 |
from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument |
45 | 45 |
from kamaki.cli.argument import KeyValueArgument, DateArgument |
46 | 46 |
from kamaki.cli.argument import ProgressBarArgument |
... | ... | |
363 | 363 |
'%s%s. ' % (empty_space, index)) if self['enum'] else '' |
364 | 364 |
if self['detail']: |
365 | 365 |
self.writeln('%s%s' % (prfx, oname)) |
366 |
print_dict(pretty_obj, exclude=('name'), out=self._out)
|
|
366 |
self.print_dict(pretty_obj, exclude=('name'))
|
|
367 | 367 |
self.writeln() |
368 | 368 |
else: |
369 | 369 |
oname = '%s%9s %s' % (prfx, size, oname) |
... | ... | |
383 | 383 |
pretty_c = container.copy() |
384 | 384 |
if 'bytes' in container: |
385 | 385 |
pretty_c['bytes'] = '%s (%s)' % (container['bytes'], size) |
386 |
print_dict(pretty_c, exclude=('name'), out=self._out)
|
|
386 |
self.print_dict(pretty_c, exclude=('name'))
|
|
387 | 387 |
self.writeln() |
388 | 388 |
else: |
389 | 389 |
if 'count' in container and 'bytes' in container: |
... | ... | |
1408 | 1408 |
if_match=self['if_match'], |
1409 | 1409 |
if_none_match=self['if_none_match'], |
1410 | 1410 |
if_modified_since=self['if_modified_since'], |
1411 |
if_unmodified_since=self['if_unmodified_since']), print_dict) |
|
1411 |
if_unmodified_since=self['if_unmodified_since']), self.print_dict)
|
|
1412 | 1412 |
|
1413 | 1413 |
def main(self, container___path): |
1414 | 1414 |
super(self.__class__, self)._run( |
... | ... | |
1451 | 1451 |
@errors.pithos.object_path |
1452 | 1452 |
def _run(self): |
1453 | 1453 |
if self.path: |
1454 |
if self['yes'] or ask_user( |
|
1455 |
'Delete %s:%s ?' % (self.container, self.path), |
|
1456 |
out=self._out, user_in=self._in): |
|
1454 |
if self['yes'] or self.ask_user( |
|
1455 |
'Delete %s:%s ?' % (self.container, self.path)): |
|
1457 | 1456 |
self._optional_output(self.client.del_object( |
1458 | 1457 |
self.path, |
1459 | 1458 |
until=self['until'], |
... | ... | |
1465 | 1464 |
ask_msg = 'Delete container contents' |
1466 | 1465 |
else: |
1467 | 1466 |
ask_msg = 'Delete container' |
1468 |
if self['yes'] or ask_user( |
|
1469 |
'%s %s ?' % (ask_msg, self.container), |
|
1470 |
out=self._out, user_in=self._in): |
|
1467 |
if self['yes'] or self.ask_user( |
|
1468 |
'%s %s ?' % (ask_msg, self.container)): |
|
1471 | 1469 |
self._optional_output(self.client.del_container( |
1472 | 1470 |
until=self['until'], |
1473 | 1471 |
delimiter='/' if self['recursive'] else self['delimiter'])) |
... | ... | |
1501 | 1499 |
@errors.pithos.connection |
1502 | 1500 |
@errors.pithos.container |
1503 | 1501 |
def _run(self): |
1504 |
if self['yes'] or ask_user( |
|
1505 |
'Purge container %s?' % self.container, |
|
1506 |
out=self._out, user_in=self._in): |
|
1502 |
if self['yes'] or self.ask_user( |
|
1503 |
'Purge container %s?' % self.container): |
|
1507 | 1504 |
try: |
1508 | 1505 |
r = self.client.purge_container() |
1509 | 1506 |
except ClientError as ce: |
... | ... | |
1571 | 1568 |
""" |
1572 | 1569 |
|
1573 | 1570 |
|
1574 |
def print_permissions(permissions_dict, out): |
|
1575 |
expected_keys = ('read', 'write') |
|
1576 |
if set(permissions_dict).issubset(expected_keys): |
|
1577 |
print_dict(permissions_dict, out=out) |
|
1578 |
else: |
|
1579 |
invalid_keys = set(permissions_dict.keys()).difference(expected_keys) |
|
1580 |
raiseCLIError( |
|
1581 |
'Illegal permission keys: %s' % ', '.join(invalid_keys), |
|
1582 |
importance=1, details=[ |
|
1583 |
'Valid permission types: %s' % ' '.join(expected_keys)]) |
|
1584 |
|
|
1585 |
|
|
1586 | 1571 |
@command(pithos_cmds) |
1587 | 1572 |
class file_permissions_get(_file_container_command, _optional_json): |
1588 | 1573 |
"""Get read and write permissions of an object""" |
1589 | 1574 |
|
1575 |
def print_permissions(self, permissions_dict, out): |
|
1576 |
expected_keys = ('read', 'write') |
|
1577 |
if set(permissions_dict).issubset(expected_keys): |
|
1578 |
self.print_dict(permissions_dict, out) |
|
1579 |
else: |
|
1580 |
invalid_keys = set(permissions_dict.keys()).difference( |
|
1581 |
expected_keys) |
|
1582 |
raiseCLIError( |
|
1583 |
'Illegal permission keys: %s' % ', '.join(invalid_keys), |
|
1584 |
importance=1, details=[ |
|
1585 |
'Valid permission types: %s' % ' '.join(expected_keys)]) |
|
1586 |
|
|
1590 | 1587 |
@errors.generic.all |
1591 | 1588 |
@errors.pithos.connection |
1592 | 1589 |
@errors.pithos.container |
1593 | 1590 |
@errors.pithos.object_path |
1594 | 1591 |
def _run(self): |
1595 | 1592 |
self._print( |
1596 |
self.client.get_object_sharing(self.path), print_permissions) |
|
1593 |
self.client.get_object_sharing(self.path), self.print_permissions)
|
|
1597 | 1594 |
|
1598 | 1595 |
def main(self, container___path): |
1599 | 1596 |
super(self.__class__, self)._run( |
... | ... | |
1686 | 1683 |
else: |
1687 | 1684 |
r = self.client.get_object_info( |
1688 | 1685 |
self.path, version=self['object_version']) |
1689 |
self._print(r, print_dict) |
|
1686 |
self._print(r, self.print_dict)
|
|
1690 | 1687 |
|
1691 | 1688 |
def main(self, container____path__=None): |
1692 | 1689 |
super(self.__class__, self)._run(container____path__) |
... | ... | |
1742 | 1739 |
self.path, |
1743 | 1740 |
version=self['object_version']) |
1744 | 1741 |
if r: |
1745 |
self._print(r, print_dict) |
|
1742 |
self._print(r, self.print_dict)
|
|
1746 | 1743 |
|
1747 | 1744 |
def main(self, container____path__=None): |
1748 | 1745 |
super(self.__class__, self)._run(container____path__) |
... | ... | |
1813 | 1810 |
if not self['in_bytes']: |
1814 | 1811 |
for k in output: |
1815 | 1812 |
output[k] = format_size(output[k]) |
1816 |
print_dict(output, '-', out=self._out)
|
|
1813 |
self.print_dict(output, '-')
|
|
1817 | 1814 |
|
1818 | 1815 |
self._print( |
1819 | 1816 |
self.client.get_account_quota(), pretty_print, out=self._out) |
... | ... | |
1844 | 1841 |
if not self['in_bytes']: |
1845 | 1842 |
for k, v in output.items(): |
1846 | 1843 |
output[k] = 'unlimited' if '0' == v else format_size(v) |
1847 |
print_dict(output, '-') |
|
1844 |
self.print_dict(output, '-')
|
|
1848 | 1845 |
|
1849 | 1846 |
self._print( |
1850 | 1847 |
self.client.get_container_limit(self.container), pretty_print) |
... | ... | |
1918 | 1915 |
@errors.pithos.container |
1919 | 1916 |
def _run(self): |
1920 | 1917 |
self._print( |
1921 |
self.client.get_container_versioning(self.container), print_dict) |
|
1918 |
self.client.get_container_versioning(self.container), |
|
1919 |
self.print_dict) |
|
1922 | 1920 |
|
1923 | 1921 |
def main(self, container): |
1924 | 1922 |
super(self.__class__, self)._run() |
... | ... | |
1961 | 1959 |
@errors.generic.all |
1962 | 1960 |
@errors.pithos.connection |
1963 | 1961 |
def _run(self): |
1964 |
self._print(self.client.get_account_group(), print_dict, delim='-') |
|
1962 |
self._print( |
|
1963 |
self.client.get_account_group(), self.print_dict, delim='-') |
|
1965 | 1964 |
|
1966 | 1965 |
def main(self): |
1967 | 1966 |
super(self.__class__, self)._run() |
... | ... | |
2027 | 2026 |
self._run() |
2028 | 2027 |
|
2029 | 2028 |
|
2030 |
def version_print(versions, out): |
|
2031 |
print_items( |
|
2032 |
[dict(id=vitem[0], created=strftime( |
|
2033 |
'%d-%m-%Y %H:%M:%S', |
|
2034 |
localtime(float(vitem[1])))) for vitem in versions], |
|
2035 |
out=out) |
|
2036 |
|
|
2037 |
|
|
2038 | 2029 |
@command(pithos_cmds) |
2039 | 2030 |
class file_versions(_file_container_command, _optional_json): |
2040 | 2031 |
"""Get the list of object versions |
... | ... | |
2045 | 2036 |
/file info -h |
2046 | 2037 |
""" |
2047 | 2038 |
|
2039 |
def version_print(self, versions, out): |
|
2040 |
self.print_items( |
|
2041 |
[dict(id=vitem[0], created=strftime( |
|
2042 |
'%d-%m-%Y %H:%M:%S', |
|
2043 |
localtime(float(vitem[1])))) for vitem in versions], |
|
2044 |
out=out) |
|
2045 |
|
|
2048 | 2046 |
@errors.generic.all |
2049 | 2047 |
@errors.pithos.connection |
2050 | 2048 |
@errors.pithos.container |
2051 | 2049 |
@errors.pithos.object_path |
2052 | 2050 |
def _run(self): |
2053 | 2051 |
self._print( |
2054 |
self.client.get_object_versionlist(self.path), version_print) |
|
2052 |
self.client.get_object_versionlist(self.path), self.version_print)
|
|
2055 | 2053 |
|
2056 | 2054 |
def main(self, container___path): |
2057 | 2055 |
super(file_versions, self)._run( |
b/kamaki/cli/commands/snf-astakos.py | ||
---|---|---|
42 | 42 |
from kamaki.cli.commands import ( |
43 | 43 |
_command_init, errors, _optional_json, addLogSettings) |
44 | 44 |
from kamaki.cli.command_tree import CommandTree |
45 |
from kamaki.cli.utils import print_dict, format_size
|
|
45 |
from kamaki.cli.utils import format_size |
|
46 | 46 |
from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument |
47 | 47 |
from kamaki.cli.argument import CommaSeparatedListArgument |
48 | 48 |
from kamaki.cli.logger import get_logger |
... | ... | |
115 | 115 |
@astakoserror |
116 | 116 |
def _run(self): |
117 | 117 |
self._print( |
118 |
self.client.get_user_info(self.token, self['usage']), print_dict) |
|
118 |
self.client.get_user_info(self.token, self['usage']), |
|
119 |
self.print_dict) |
|
119 | 120 |
|
120 | 121 |
def main(self): |
121 | 122 |
super(self.__class__, self)._run() |
... | ... | |
139 | 140 |
self._print(self.client.get_username(self.token, uuids[0])) |
140 | 141 |
else: |
141 | 142 |
self._print( |
142 |
self.client.get_usernames(self.token, uuids), print_dict) |
|
143 |
self.client.get_usernames(self.token, uuids), self.print_dict)
|
|
143 | 144 |
|
144 | 145 |
def main(self, uuid, *more_uuids): |
145 | 146 |
super(self.__class__, self)._run() |
... | ... | |
158 | 159 |
self._print(self.client.get_uuid(self.token, usernames[0])) |
159 | 160 |
else: |
160 | 161 |
self._print( |
161 |
self.client.get_uuids(self.token, usernames), print_dict) |
|
162 |
self.client.get_uuids(self.token, usernames), self.print_dict)
|
|
162 | 163 |
|
163 | 164 |
def main(self, usernames, *more_usernames): |
164 | 165 |
super(self.__class__, self)._run() |
... | ... | |
169 | 170 |
class astakos_quotas(_astakos_init, _optional_json): |
170 | 171 |
"""Get user (or service) quotas""" |
171 | 172 |
|
172 |
@staticmethod |
|
173 |
def _print_with_format(d): |
|
173 |
def _print_with_format(self, d, out): |
|
174 | 174 |
""" Print d with size formating when needed |
175 | 175 |
:param d: (dict) {system: {<service>: {usage: ..., limit: ..., }, ...}} |
176 | 176 |
""" |
... | ... | |
180 | 180 |
for term in ('usage', 'limit'): |
181 | 181 |
if term in service: |
182 | 182 |
newd[k][term] = format_size(service[term]) |
183 |
print_dict(newd)
|
|
183 |
self.print_dict(newd, out=out)
|
|
184 | 184 |
|
185 | 185 |
@errors.generic.all |
186 | 186 |
@astakoserror |
... | ... | |
224 | 224 |
self._print(self.client.service_get_username(stoken, uuids[0])) |
225 | 225 |
else: |
226 | 226 |
self._print( |
227 |
self.client.service_get_usernames(stoken, uuids), print_dict) |
|
227 |
self.client.service_get_usernames(stoken, uuids), |
|
228 |
self.print_dict) |
|
228 | 229 |
|
229 | 230 |
def main(self, service_token, uuid, *more_uuids): |
230 | 231 |
super(self.__class__, self)._run() |
... | ... | |
244 | 245 |
else: |
245 | 246 |
self._print( |
246 | 247 |
self.client.service_get_uuids(self.token, usernames), |
247 |
print_dict) |
|
248 |
self.print_dict)
|
|
248 | 249 |
|
249 | 250 |
def main(self, service_token, usernames, *more_usernames): |
250 | 251 |
super(self.__class__, self)._run() |
... | ... | |
276 | 277 |
@errors.generic.all |
277 | 278 |
@astakoserror |
278 | 279 |
def _run(self): |
279 |
self._print(self.client.get_resources(), print_dict) |
|
280 |
self._print(self.client.get_resources(), self.print_dict)
|
|
280 | 281 |
|
281 | 282 |
def main(self): |
282 | 283 |
super(self.__class__, self)._run() |
... | ... | |
308 | 309 |
def _run(self): |
309 | 310 |
self._print( |
310 | 311 |
self.client.get_endpoints(self.token, self['uuid']), |
311 |
print_dict) |
|
312 |
self.print_dict)
|
|
312 | 313 |
|
313 | 314 |
def main(self): |
314 | 315 |
super(self.__class__, self)._run() |
... | ... | |
344 | 345 |
commission_id = int(commission_id) |
345 | 346 |
self._print( |
346 | 347 |
self.client.get_commission_info(self.token, commission_id), |
347 |
print_dict) |
|
348 |
self.print_dict)
|
|
348 | 349 |
|
349 | 350 |
def main(self, commission_id): |
350 | 351 |
super(self.__class__, self)._run() |
... | ... | |
368 | 369 |
' or '.join(self.actions)) |
369 | 370 |
self._print( |
370 | 371 |
self.client.commission_acction(self.token, commission_id, action), |
371 |
print_dict) |
|
372 |
self.print_dict)
|
|
372 | 373 |
|
373 | 374 |
def main(self, commission_id, action): |
374 | 375 |
super(self.__class__, self)._run() |
... | ... | |
426 | 427 |
self._print( |
427 | 428 |
self.client.resolve_commissions( |
428 | 429 |
self.token, self['accept'], self['reject']), |
429 |
print_dict) |
|
430 |
self.print_dict)
|
|
430 | 431 |
|
431 | 432 |
def main(self): |
432 | 433 |
super(self.__class__, self)._run() |
... | ... | |
540 | 541 |
@astakoserror |
541 | 542 |
def _run(self, project_id): |
542 | 543 |
self._print( |
543 |
self.client.get_project(self.token, project_id), print_dict) |
|
544 |
self.client.get_project(self.token, project_id), self.print_dict)
|
|
544 | 545 |
|
545 | 546 |
def main(self, project_id): |
546 | 547 |
super(self.__class__, self)._run() |
... | ... | |
568 | 569 |
input_stream = open(abspath(self['specs_path'])) if ( |
569 | 570 |
self['specs_path']) else stdin |
570 | 571 |
specs = load(input_stream) |
571 |
self._print(self.client.create_project(self.token, specs), print_dict) |
|
572 |
self._print( |
|
573 |
self.client.create_project(self.token, specs), self.print_dict) |
|
572 | 574 |
|
573 | 575 |
def main(self): |
574 | 576 |
super(self.__class__, self)._run() |
... | ... | |
598 | 600 |
specs = load(input_stream) |
599 | 601 |
self._print( |
600 | 602 |
self.client.modify_project(self.token, project_id, specs), |
601 |
print_dict) |
|
603 |
self.print_dict)
|
|
602 | 604 |
|
603 | 605 |
def main(self, project_id): |
604 | 606 |
super(self.__class__, self)._run() |
... | ... | |
675 | 677 |
@astakoserror |
676 | 678 |
def _run(self, app_id): |
677 | 679 |
self._print( |
678 |
self.client.get_application(self.token, app_id), print_dict) |
|
680 |
self.client.get_application(self.token, app_id), self.print_dict)
|
|
679 | 681 |
|
680 | 682 |
def main(self, application_id): |
681 | 683 |
super(self.__class__, self)._run() |
... | ... | |
751 | 753 |
@errors.generic.all |
752 | 754 |
@astakoserror |
753 | 755 |
def _run(self, memb_id): |
754 |
self._print(self.client.get_membership(self.token, memb_id),
|
|
755 |
print_dict)
|
|
756 |
self._print( |
|
757 |
self.client.get_membership(self.token, memb_id), self.print_dict)
|
|
756 | 758 |
|
757 | 759 |
def main(self, membership_id): |
758 | 760 |
super(self.__class__, self)._run() |
Also available in: Unified diff