diff options
author | jiahui.qiang <jiahui.qiang@easystack.cn> | 2016-11-24 17:05:25 +0800 |
---|---|---|
committer | Dean Troyer <dtroyer@gmail.com> | 2017-01-25 21:31:45 +0000 |
commit | c46f9dc501441ef449f41e726ec3cfbbe9f3de9d (patch) | |
tree | a1a85ad25a26a9c5c235543208b104f60db76cd8 | |
parent | b69b539a422860bfb402093ff9d93a1b6e338b26 (diff) | |
download | python-openstackclient-c46f9dc501441ef449f41e726ec3cfbbe9f3de9d.tar.gz |
Add options to "server list" command
Add "--deleted" and "--changes-since" options to "server list" command.
Change-Id: Id94f6e5831a60b172b6cfcfca29b1d89de8db621
Closes-Bug:#1647242
-rw-r--r-- | doc/source/command-objects/server.rst | 11 | ||||
-rw-r--r-- | openstackclient/compute/v2/server.py | 25 | ||||
-rw-r--r-- | openstackclient/tests/unit/compute/v2/test_server.py | 46 | ||||
-rw-r--r-- | releasenotes/notes/bug-1647242-fdc39e564372857b.yaml | 6 |
4 files changed, 88 insertions, 0 deletions
diff --git a/doc/source/command-objects/server.rst b/doc/source/command-objects/server.rst index 40ecc047..f18d0918 100644 --- a/doc/source/command-objects/server.rst +++ b/doc/source/command-objects/server.rst @@ -253,6 +253,8 @@ List servers [--long] [--marker <server>] [--limit <limit>] + [--deleted] + [--changes-since <changes-since>] .. option:: --reservation-id <reservation-id> @@ -327,6 +329,15 @@ List servers be displayed. If limit is greater than 'osapi_max_limit' option of Nova API, 'osapi_max_limit' will be used instead. +.. option:: --deleted + + Only display deleted servers (Admin only). + +.. option:: --changes-since <changes-since> + + List only servers changed after a certain point of time. The provided time + should be an ISO 8061 formatted time. ex 2016-03-04T06:27:59Z. + server lock ----------- diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index a1330e01..dc32add5 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -26,6 +26,7 @@ from osc_lib.cli import parseractions from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils +from oslo_utils import timeutils import six try: @@ -793,6 +794,20 @@ class ListServer(command.Lister): " 'osapi_max_limit' option of Nova API," " 'osapi_max_limit' will be used instead."), ) + parser.add_argument( + '--deleted', + action="store_true", + default=False, + help=_('Only display deleted servers (Admin only).') + ) + parser.add_argument( + '--changes-since', + metavar='<changes-since>', + default=None, + help=_("List only servers changed after a certain point of time." + " The provided time should be an ISO 8061 formatted time." + " ex 2016-03-04T06:27:59Z .") + ) return parser def take_action(self, parsed_args): @@ -844,9 +859,19 @@ class ListServer(command.Lister): 'tenant_id': project_id, 'all_tenants': parsed_args.all_projects, 'user_id': user_id, + 'deleted': parsed_args.deleted, + 'changes_since': parsed_args.changes_since, } LOG.debug('search options: %s', search_opts) + if search_opts['changes_since']: + try: + timeutils.parse_isotime(search_opts['changes_since']) + except ValueError: + raise exceptions.CommandError(_('Invalid changes-since value:' + ' %s') % search_opts['changes' + '_since']) + if parsed_args.long: columns = ( 'ID', diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 54f36209..deba4435 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -19,6 +19,7 @@ from mock import call from osc_lib import exceptions from osc_lib import utils as common_utils +from oslo_utils import timeutils from openstackclient.compute.v2 import server from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes @@ -826,6 +827,8 @@ class TestServerList(TestServer): 'tenant_id': None, 'all_tenants': False, 'user_id': None, + 'deleted': False, + 'changes_since': None, } # Default params of the core function of the command in the case of no @@ -902,6 +905,7 @@ class TestServerList(TestServer): verifylist = [ ('all_projects', False), ('long', False), + ('deleted', False), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -967,6 +971,48 @@ class TestServerList(TestServer): self.assertEqual(self.columns, columns) self.assertEqual(tuple(self.data), tuple(data)) + def test_server_list_with_changes_since(self): + + arglist = [ + '--changes-since', '2016-03-04T06:27:59Z', + '--deleted' + ] + verifylist = [ + ('changes_since', '2016-03-04T06:27:59Z'), + ('deleted', True), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.search_opts['changes_since'] = '2016-03-04T06:27:59Z' + self.search_opts['deleted'] = True + self.servers_mock.list.assert_called_with(**self.kwargs) + + self.assertEqual(self.columns, columns) + self.assertEqual(tuple(self.data), tuple(data)) + + @mock.patch.object(timeutils, 'parse_isotime', side_effect=ValueError) + def test_server_list_with_invalid_changes_since(self, mock_parse_isotime): + + arglist = [ + '--changes-since', 'Invalid time value', + ] + verifylist = [ + ('changes_since', 'Invalid time value'), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + try: + self.cmd.take_action(parsed_args) + self.fail('CommandError should be raised.') + except exceptions.CommandError as e: + self.assertEqual('Invalid changes-since value: Invalid time ' + 'value', str(e)) + mock_parse_isotime.assert_called_once_with( + 'Invalid time value' + ) + class TestServerLock(TestServer): diff --git a/releasenotes/notes/bug-1647242-fdc39e564372857b.yaml b/releasenotes/notes/bug-1647242-fdc39e564372857b.yaml new file mode 100644 index 00000000..d4b3bdaa --- /dev/null +++ b/releasenotes/notes/bug-1647242-fdc39e564372857b.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Add ``--deleted`` and ``--changes-since`` options to ``server list`` + command. + [Bug `1647242 <https://bugs.launchpad.net/bugs/1647272>`_] |