More shell completion cache additions
Closes-Bug: #1712835
Change-Id: I9326d5d92ff2e93dd0398d9a115210b376059064
(cherry picked from commit e40166740e)
This commit is contained in:
committed by
Brian Rosmaita
parent
5a884fb68f
commit
47ef579824
@@ -309,7 +309,10 @@ class Manager(common_base.HookableMixin):
|
|||||||
def write_to_completion_cache(self, cache_type, val):
|
def write_to_completion_cache(self, cache_type, val):
|
||||||
cache = getattr(self, "_%s_cache" % cache_type, None)
|
cache = getattr(self, "_%s_cache" % cache_type, None)
|
||||||
if cache:
|
if cache:
|
||||||
cache.write("%s\n" % val)
|
try:
|
||||||
|
cache.write("%s\n" % val)
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
pass
|
||||||
|
|
||||||
def _get(self, url, response_key=None):
|
def _get(self, url, response_key=None):
|
||||||
resp, body = self.api.client.get(url)
|
resp, body = self.api.client.get(url)
|
||||||
|
|||||||
@@ -72,6 +72,19 @@ def do_type_list(cs, args):
|
|||||||
vtypes = cs.volume_types.list(search_opts=search_opts)
|
vtypes = cs.volume_types.list(search_opts=search_opts)
|
||||||
shell_utils.print_volume_type_list(vtypes)
|
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',
|
@utils.arg('--all-tenants',
|
||||||
metavar='<all_tenants>',
|
metavar='<all_tenants>',
|
||||||
@@ -183,6 +196,13 @@ def do_backup_list(cs, args):
|
|||||||
mode="w"):
|
mode="w"):
|
||||||
for backup in backups:
|
for backup in backups:
|
||||||
cs.backups.write_to_completion_cache('uuid', backup.id)
|
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',
|
@utils.arg('--detail',
|
||||||
@@ -406,6 +426,14 @@ def do_list(cs, args):
|
|||||||
for vol in volumes:
|
for vol in volumes:
|
||||||
cs.volumes.write_to_completion_cache('uuid', vol.id)
|
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:
|
if field_titles:
|
||||||
# Remove duplicate fields
|
# Remove duplicate fields
|
||||||
key_list = ['ID']
|
key_list = ['ID']
|
||||||
@@ -659,6 +687,11 @@ def do_create(cs, args):
|
|||||||
cinderclient.v3.volumes.Volume,
|
cinderclient.v3.volumes.Volume,
|
||||||
mode="a"):
|
mode="a"):
|
||||||
cs.volumes.write_to_completion_cache('uuid', volume.id)
|
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',
|
@utils.arg('volume',
|
||||||
@@ -2045,6 +2078,13 @@ def do_snapshot_list(cs, args):
|
|||||||
if show_count:
|
if show_count:
|
||||||
print("Snapshot in total: %s" % total_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')
|
@api_versions.wraps('3.27')
|
||||||
@utils.arg('--all-tenants',
|
@utils.arg('--all-tenants',
|
||||||
|
|||||||
Reference in New Issue
Block a user