From 20c0421857139a49a466c8a03019bdbfd4957d20 Mon Sep 17 00:00:00 2001 From: Deepti Ramakrishna Date: Sat, 27 Feb 2016 22:13:49 -0800 Subject: [PATCH] snapshot-list now supports filtering by tenant Admin can now filter snapshots on the basis of tenant. No changes are needed on server side since snapshot model contains project_id as a column which means that it supports native filtering by tenant (i.e, project) via SQL. This closely follows similar functionality for volume listing added in the change-id - fa8c7e3d84bd93cdfc3641554e10d422281ea018 DocImpact After this patch is merged we need to regenerate the CLI reference guide so that the added documentation for the new option "--tenant " for "cinder snapshot-list" command gets included. Change-Id: I0bbd8e0b4aaf25da738c67638fb497337ead312b Co-Authored-By: wuyuting --- cinderclient/tests/unit/v2/test_shell.py | 10 ++++++++++ cinderclient/v2/shell.py | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index deddff0a4..ba3511ee0 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -475,6 +475,16 @@ class ShellTest(utils.TestCase): mock_print_list.assert_called_once_with(mock.ANY, columns, sortby_index=None) + def test_snapshot_list_filter_tenant_with_all_tenants(self): + self.run_command('snapshot-list --all-tenants=1 --tenant 123') + self.assert_called('GET', + '/snapshots/detail?all_tenants=1&project_id=123') + + def test_snapshot_list_filter_tenant_without_all_tenants(self): + self.run_command('snapshot-list --tenant 123') + self.assert_called('GET', + '/snapshots/detail?all_tenants=1&project_id=123') + def test_rename(self): # basic rename with positional arguments self.run_command('rename 1234 new-name') diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index 7f83dbc69..c0a35a1ca 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -665,10 +665,17 @@ def do_image_metadata(cs, args): 'form of [:]. ' 'Valid keys: %s. ' 'Default=None.') % ', '.join(base.SORT_KEY_VALUES))) +@utils.arg('--tenant', + type=str, + dest='tenant', + nargs='?', + metavar='', + help='Display information from single tenant (Admin only).') @utils.service_type('volumev2') def do_snapshot_list(cs, args): """Lists all snapshots.""" - all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) + all_tenants = (1 if args.tenant else + int(os.environ.get("ALL_TENANTS", args.all_tenants))) if args.display_name is not None: args.name = args.display_name @@ -678,6 +685,7 @@ def do_snapshot_list(cs, args): 'display_name': args.name, 'status': args.status, 'volume_id': args.volume_id, + 'project_id': args.tenant, } snapshots = cs.volume_snapshots.list(search_opts=search_opts,