Commit ed9af02c authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Add enumeration as optional for all list cmds

Refs: #3739
parent 8bdf3047
......@@ -27,4 +27,5 @@ Features:
- Implement purging a non-empty container [#3662]
- Add a -l option to upload, for listing uploaded objects details [#3730]
- Add option to cache container info for upload_object [#3707]
- Add enumeration to all listing commands, make it optional [#3739]
......@@ -93,7 +93,8 @@ class server_list(_init_cyclades):
limit=IntArgument('limit number of listed VMs', ('-n', '--number')),
more=FlagArgument(
'output results in pages (-n to set items per page, default 10)',
'--more')
'--more'),
enum=FlagArgument('Enumerate results', '--enumerate')
)
def _make_results_pretty(self, servers):
......@@ -122,10 +123,12 @@ class server_list(_init_cyclades):
if self['more']:
print_items(
servers,
page_size=self['limit'] if self['limit'] else 10)
page_size=self['limit'] if self['limit'] else 10,
with_enumeration=self['enum'])
else:
print_items(
servers[:self['limit'] if self['limit'] else len(servers)])
servers[:self['limit'] if self['limit'] else len(servers)],
with_enumeration=self['enum'])
def main(self):
super(self.__class__, self)._run()
......@@ -495,7 +498,8 @@ class flavor_list(_init_cyclades):
limit=IntArgument('limit # of listed flavors', ('-n', '--number')),
more=FlagArgument(
'output results in pages (-n to set items per page, default 10)',
'--more')
'--more'),
enum=FlagArgument('Enumerate results', '--enumerate')
)
@errors.generic.all
......@@ -503,7 +507,11 @@ class flavor_list(_init_cyclades):
def _run(self):
flavors = self.client.list_flavors(self['detail'])
pg_size = 10 if self['more'] and not self['limit'] else self['limit']
print_items(flavors, with_redundancy=self['detail'], page_size=pg_size)
print_items(
flavors,
with_redundancy=self['detail'],
page_size=pg_size,
with_enumeration=self['enum'])
def main(self):
super(self.__class__, self)._run()
......@@ -563,7 +571,8 @@ class network_list(_init_cyclades):
limit=IntArgument('limit # of listed networks', ('-n', '--number')),
more=FlagArgument(
'output results in pages (-n to set items per page, default 10)',
'--more')
'--more'),
enum=FlagArgument('Enumerate results', '--enumerate')
)
def _make_results_pretty(self, nets):
......@@ -577,11 +586,15 @@ class network_list(_init_cyclades):
if self['detail']:
self._make_results_pretty(networks)
if self['more']:
print_items(networks, page_size=self['limit'] or 10)
print_items(
networks,
page_size=self['limit'] or 10, with_enumeration=self['enum'])
elif self['limit']:
print_items(networks[:self['limit']])
print_items(
networks[:self['limit']],
with_enumeration=self['enum'])
else:
print_items(networks)
print_items(networks, with_enumeration=self['enum'])
def main(self):
super(self.__class__, self)._run()
......
......@@ -103,7 +103,8 @@ class image_list(_init_image):
limit=IntArgument('limit number of listed images', ('-n', '--number')),
more=FlagArgument(
'output results in pages (-n to set items per page, default 10)',
'--more')
'--more'),
enum=FlagArgument('Enumerate results', '--enumerate')
)
def _filtered_by_owner(self, detail, *list_params):
......@@ -150,16 +151,11 @@ class image_list(_init_image):
if self['more']:
print_items(
images,
title=('name',),
with_enumeration=True,
page_size=self['limit'] or 10)
with_enumeration=self['enum'], page_size=self['limit'] or 10)
elif self['limit']:
print_items(
images[:self['limit']],
title=('name',),
with_enumeration=True)
print_items(images[:self['limit']], with_enumeration=self['enum'])
else:
print_items(images, title=('name',), with_enumeration=True)
print_items(images, with_enumeration=self['enum'])
def main(self):
super(self.__class__, self)._run()
......@@ -355,7 +351,8 @@ class image_compute_list(_init_cyclades):
limit=IntArgument('limit number listed images', ('-n', '--number')),
more=FlagArgument(
'output results in pages (-n to set items per page, default 10)',
'--more')
'--more'),
enum=FlagArgument('Enumerate results', '--enumerate')
)
def _make_results_pretty(self, images):
......@@ -370,9 +367,11 @@ class image_compute_list(_init_cyclades):
if self['detail']:
self._make_results_pretty(images)
if self['more']:
print_items(images, page_size=self['limit'] or 10)
print_items(
images,
page_size=self['limit'] or 10, with_enumeration=self['enum'])
else:
print_items(images[:self['limit']])
print_items(images[:self['limit']], with_enumeration=self['enum'])
def main(self):
super(self.__class__, self)._run()
......
......@@ -328,7 +328,8 @@ class file_list(_file_container_command):
'--more'),
exact_match=FlagArgument(
'Show only objects that match exactly with path',
'--exact-match')
'--exact-match'),
enum=FlagArgument('Enumerate results', '--enumerate')
)
def print_objects(self, object_list):
......@@ -348,12 +349,13 @@ class file_list(_file_container_command):
size = format_size(obj['bytes'])
pretty_obj['bytes'] = '%s (%s)' % (obj['bytes'], size)
oname = bold(obj['name'])
prfx = ('%s%s. ' % (empty_space, index)) if self['enum'] else ''
if self['detail']:
print('%s%s. %s' % (empty_space, index, oname))
print('%s%s' % (prfx, oname))
print_dict(pretty_keys(pretty_obj), exclude=('name'))
print
else:
oname = '%s%s. %6s %s' % (empty_space, index, size, oname)
oname = '%s%9s %s' % (prfx, size, oname)
oname += '/' if isDir else ''
print(oname)
if self['more']:
......@@ -365,7 +367,8 @@ class file_list(_file_container_command):
for index, container in enumerate(container_list):
if 'bytes' in container:
size = format_size(container['bytes'])
cname = '%s. %s' % (index + 1, bold(container['name']))
prfx = ('%s. ' % (index + 1)) if self['enum'] else ''
cname = '%s%s' % (prfx, bold(container['name']))
if self['detail']:
print(cname)
pretty_c = container.copy()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment