Add options to "server list" command
Add "--deleted" and "--changes-since" options to "server list" command. Change-Id: Id94f6e5831a60b172b6cfcfca29b1d89de8db621 Closes-Bug:#1647242
This commit is contained in:
parent
b69b539a42
commit
c46f9dc501
@ -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
|
||||
-----------
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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):
|
||||
|
||||
|
6
releasenotes/notes/bug-1647242-fdc39e564372857b.yaml
Normal file
6
releasenotes/notes/bug-1647242-fdc39e564372857b.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``--deleted`` and ``--changes-since`` options to ``server list``
|
||||
command.
|
||||
[Bug `1647242 <https://bugs.launchpad.net/bugs/1647272>`_]
|
Loading…
Reference in New Issue
Block a user