Add 'count' in list command
Add 'count' parameter in list share command. Change-Id: I2b7b41b3579c24703a1a67ab5dc6f920a3ccbdc3 Partial-Implements: bp add-amount-info-in-list-api
This commit is contained in:
parent
d4c581de4f
commit
6e8b3deef9
@ -27,7 +27,7 @@ from manilaclient import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
MAX_VERSION = '2.40'
|
||||
MAX_VERSION = '2.42'
|
||||
MIN_VERSION = '2.0'
|
||||
DEPRECATED_VERSION = '1.0'
|
||||
_VERSIONED_METHOD_MAP = {}
|
||||
|
@ -74,8 +74,12 @@ class Manager(utils.HookableMixin):
|
||||
|
||||
with self.completion_cache('human_id', obj_class, mode="w"):
|
||||
with self.completion_cache('uuid', obj_class, mode="w"):
|
||||
return [obj_class(self, res, loaded=True)
|
||||
resource = [obj_class(self, res, loaded=True)
|
||||
for res in data if res]
|
||||
if 'count' in body:
|
||||
return resource, body['count']
|
||||
else:
|
||||
return resource
|
||||
|
||||
@contextlib.contextmanager
|
||||
def completion_cache(self, cache_type, obj_class, mode):
|
||||
|
@ -233,7 +233,8 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
|
||||
"rel": "self"},
|
||||
],
|
||||
},
|
||||
]
|
||||
],
|
||||
'count': 2,
|
||||
}
|
||||
return (200, {}, shares)
|
||||
|
||||
|
@ -321,6 +321,16 @@ class SharesTest(utils.TestCase):
|
||||
+ value + '&is_public=True'))
|
||||
|
||||
def test_list_shares_detailed(self):
|
||||
search_opts = {
|
||||
'with_count': 'True',
|
||||
}
|
||||
shares, count = cs.shares.list(detailed=True, search_opts=search_opts)
|
||||
cs.assert_called(
|
||||
'GET', '/shares/detail?is_public=True&with_count=True')
|
||||
self.assertEqual(2, count)
|
||||
self.assertEqual(1, len(shares))
|
||||
|
||||
def test_list_shares_detailed_with_count(self):
|
||||
cs.shares.list(detailed=True)
|
||||
cs.assert_called('GET', '/shares/detail?is_public=True')
|
||||
|
||||
|
@ -397,6 +397,25 @@ class ShellTest(test_utils.TestCase):
|
||||
)
|
||||
self.assert_called('GET', '/share-networks/detail')
|
||||
|
||||
@ddt.data('True', 'False')
|
||||
def test_list_filter_with_count(self, value):
|
||||
except_url = '/shares/detail?with_count=' + value
|
||||
if value == 'False':
|
||||
except_url = '/shares/detail'
|
||||
|
||||
for separator in self.separators:
|
||||
self.run_command('list --count' + separator + value)
|
||||
self.assert_called('GET', except_url)
|
||||
|
||||
@ddt.data('True', 'False')
|
||||
def test_list_filter_with_count_invalid_version(self, value):
|
||||
self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.run_command,
|
||||
'list --count ' + value,
|
||||
version='2.41'
|
||||
)
|
||||
|
||||
@mock.patch.object(cliutils, 'print_list', mock.Mock())
|
||||
def test_share_instance_list(self):
|
||||
self.run_command('share-instance-list')
|
||||
|
@ -1627,6 +1627,14 @@ def do_snapshot_access_list(cs, args):
|
||||
action='single_alias',
|
||||
help='ID or path of the share export location. '
|
||||
'Available only for microversion >= 2.35.')
|
||||
@cliutils.arg(
|
||||
'--count',
|
||||
dest='count',
|
||||
metavar='<True|False>',
|
||||
choices=['True', 'False'],
|
||||
default=False,
|
||||
help='Display total number of shares to return. '
|
||||
'Available only for microversion >= 2.42.')
|
||||
@cliutils.service_type('sharev2')
|
||||
def do_list(cs, args):
|
||||
"""List NAS shares with filters."""
|
||||
@ -1692,12 +1700,26 @@ def do_list(cs, args):
|
||||
"Filtering by export location is only "
|
||||
"available with manila API version >= 2.35")
|
||||
|
||||
if (args.count and
|
||||
cs.api_version.matches(
|
||||
api_versions.APIVersion(), api_versions.APIVersion("2.41"))):
|
||||
raise exceptions.CommandError(
|
||||
"Display total number of shares is only "
|
||||
"available with manila API version >= 2.42")
|
||||
|
||||
if share_group:
|
||||
search_opts['share_group_id'] = share_group.id
|
||||
|
||||
total_count = 0
|
||||
if strutils.bool_from_string(args.count, strict=True):
|
||||
search_opts['with_count'] = args.count
|
||||
shares, total_count = cs.shares.list(
|
||||
search_opts=search_opts, sort_key=args.sort_key,
|
||||
sort_dir=args.sort_dir,
|
||||
)
|
||||
else:
|
||||
shares = cs.shares.list(
|
||||
search_opts=search_opts,
|
||||
sort_key=args.sort_key,
|
||||
search_opts=search_opts, sort_key=args.sort_key,
|
||||
sort_dir=args.sort_dir,
|
||||
)
|
||||
# NOTE(vponomaryov): usage of 'export_location' and
|
||||
@ -1712,6 +1734,8 @@ def do_list(cs, args):
|
||||
setattr(share, 'export_locations', els)
|
||||
setattr(share, 'export_location', els[0] if els else None)
|
||||
cliutils.print_list(shares, list_of_keys)
|
||||
if args.count:
|
||||
print("Shares in total: %s" % total_count)
|
||||
|
||||
|
||||
@cliutils.arg(
|
||||
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- Added ``with_count`` option in share's list commands since 2.42.
|
Loading…
Reference in New Issue
Block a user