More shell completion cache additions

Closes-Bug: #1712835
Change-Id: I9326d5d92ff2e93dd0398d9a115210b376059064
This commit is contained in:
Eric Harney 2018-10-22 16:53:07 -04:00 committed by Rajat Dhasmana
parent 3c143d95b3
commit e40166740e
2 changed files with 44 additions and 1 deletions

View File

@ -309,7 +309,10 @@ class Manager(common_base.HookableMixin):
def write_to_completion_cache(self, cache_type, val):
cache = getattr(self, "_%s_cache" % cache_type, None)
if cache:
cache.write("%s\n" % val)
try:
cache.write("%s\n" % val)
except UnicodeEncodeError:
pass
def _get(self, url, response_key=None):
resp, body = self.api.client.get(url)

View File

@ -71,6 +71,19 @@ def do_type_list(cs, args):
vtypes = cs.volume_types.list(search_opts=search_opts)
shell_utils.print_volume_type_list(vtypes)
with cs.volume_types.completion_cache(
'uuid',
cinderclient.v3.volume_types.VolumeType,
mode="w"):
for vtype in vtypes:
cs.volume_types.write_to_completion_cache('uuid', vtype.id)
with cs.volume_types.completion_cache(
'name',
cinderclient.v3.volume_types.VolumeType,
mode="w"):
for vtype in vtypes:
cs.volume_types.write_to_completion_cache('name', vtype.name)
@utils.arg('--all-tenants',
metavar='<all_tenants>',
@ -182,6 +195,13 @@ def do_backup_list(cs, args):
mode="w"):
for backup in backups:
cs.backups.write_to_completion_cache('uuid', backup.id)
with cs.backups.completion_cache(
'name',
cinderclient.v3.volume_backups.VolumeBackup,
mode='w'):
for backup in backups:
if backup.name is not None:
cs.backups.write_to_completion_cache('name', backup.name)
@utils.arg('--detail',
@ -405,6 +425,14 @@ def do_list(cs, args):
for vol in volumes:
cs.volumes.write_to_completion_cache('uuid', vol.id)
with cs.volumes.completion_cache('name',
cinderclient.v3.volumes.Volume,
mode="w"):
for vol in volumes:
if vol.name is None:
continue
cs.volumes.write_to_completion_cache('name', vol.name)
if field_titles:
# Remove duplicate fields
key_list = ['ID']
@ -659,6 +687,11 @@ def do_create(cs, args):
cinderclient.v3.volumes.Volume,
mode="a"):
cs.volumes.write_to_completion_cache('uuid', volume.id)
if volume.name is not None:
with cs.volumes.completion_cache('name',
cinderclient.v3.volumes.Volume,
mode="a"):
cs.volumes.write_to_completion_cache('name', volume.name)
@utils.arg('volume',
@ -2045,6 +2078,13 @@ def do_snapshot_list(cs, args):
if show_count:
print("Snapshot in total: %s" % total_count)
with cs.volume_snapshots.completion_cache(
'uuid',
cinderclient.v3.volume_snapshots.Snapshot,
mode='w'):
for snapshot in snapshots:
cs.volume_snapshots.write_to_completion_cache('uuid', snapshot.id)
@api_versions.wraps('3.27')
@utils.arg('--all-tenants',