Skip to content

Commit d189e80

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add options to "server list" command"
2 parents d4c1367 + c46f9dc commit d189e80

4 files changed

Lines changed: 88 additions & 0 deletions

File tree

doc/source/command-objects/server.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ List servers
253253
[--long]
254254
[--marker <server>]
255255
[--limit <limit>]
256+
[--deleted]
257+
[--changes-since <changes-since>]
256258
257259
.. option:: --reservation-id <reservation-id>
258260
@@ -327,6 +329,15 @@ List servers
327329
be displayed. If limit is greater than 'osapi_max_limit' option of Nova
328330
API, 'osapi_max_limit' will be used instead.
329331
332+
.. option:: --deleted
333+
334+
Only display deleted servers (Admin only).
335+
336+
.. option:: --changes-since <changes-since>
337+
338+
List only servers changed after a certain point of time. The provided time
339+
should be an ISO 8061 formatted time. ex 2016-03-04T06:27:59Z.
340+
330341
server lock
331342
-----------
332343

openstackclient/compute/v2/server.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from osc_lib.command import command
2727
from osc_lib import exceptions
2828
from osc_lib import utils
29+
from oslo_utils import timeutils
2930
import six
3031

3132
try:
@@ -805,6 +806,20 @@ def get_parser(self, prog_name):
805806
" 'osapi_max_limit' option of Nova API,"
806807
" 'osapi_max_limit' will be used instead."),
807808
)
809+
parser.add_argument(
810+
'--deleted',
811+
action="store_true",
812+
default=False,
813+
help=_('Only display deleted servers (Admin only).')
814+
)
815+
parser.add_argument(
816+
'--changes-since',
817+
metavar='<changes-since>',
818+
default=None,
819+
help=_("List only servers changed after a certain point of time."
820+
" The provided time should be an ISO 8061 formatted time."
821+
" ex 2016-03-04T06:27:59Z .")
822+
)
808823
return parser
809824

810825
def take_action(self, parsed_args):
@@ -856,9 +871,19 @@ def take_action(self, parsed_args):
856871
'tenant_id': project_id,
857872
'all_tenants': parsed_args.all_projects,
858873
'user_id': user_id,
874+
'deleted': parsed_args.deleted,
875+
'changes_since': parsed_args.changes_since,
859876
}
860877
LOG.debug('search options: %s', search_opts)
861878

879+
if search_opts['changes_since']:
880+
try:
881+
timeutils.parse_isotime(search_opts['changes_since'])
882+
except ValueError:
883+
raise exceptions.CommandError(_('Invalid changes-since value:'
884+
' %s') % search_opts['changes'
885+
'_since'])
886+
862887
if parsed_args.long:
863888
columns = (
864889
'ID',

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from osc_lib import exceptions
2121
from osc_lib import utils as common_utils
22+
from oslo_utils import timeutils
2223

2324
from openstackclient.compute.v2 import server
2425
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
@@ -831,6 +832,8 @@ def setUp(self):
831832
'tenant_id': None,
832833
'all_tenants': False,
833834
'user_id': None,
835+
'deleted': False,
836+
'changes_since': None,
834837
}
835838

836839
# Default params of the core function of the command in the case of no
@@ -907,6 +910,7 @@ def test_server_list_no_option(self):
907910
verifylist = [
908911
('all_projects', False),
909912
('long', False),
913+
('deleted', False),
910914
]
911915
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
912916

@@ -972,6 +976,48 @@ def test_server_list_with_flavor(self):
972976
self.assertEqual(self.columns, columns)
973977
self.assertEqual(tuple(self.data), tuple(data))
974978

979+
def test_server_list_with_changes_since(self):
980+
981+
arglist = [
982+
'--changes-since', '2016-03-04T06:27:59Z',
983+
'--deleted'
984+
]
985+
verifylist = [
986+
('changes_since', '2016-03-04T06:27:59Z'),
987+
('deleted', True),
988+
]
989+
990+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
991+
columns, data = self.cmd.take_action(parsed_args)
992+
993+
self.search_opts['changes_since'] = '2016-03-04T06:27:59Z'
994+
self.search_opts['deleted'] = True
995+
self.servers_mock.list.assert_called_with(**self.kwargs)
996+
997+
self.assertEqual(self.columns, columns)
998+
self.assertEqual(tuple(self.data), tuple(data))
999+
1000+
@mock.patch.object(timeutils, 'parse_isotime', side_effect=ValueError)
1001+
def test_server_list_with_invalid_changes_since(self, mock_parse_isotime):
1002+
1003+
arglist = [
1004+
'--changes-since', 'Invalid time value',
1005+
]
1006+
verifylist = [
1007+
('changes_since', 'Invalid time value'),
1008+
]
1009+
1010+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1011+
try:
1012+
self.cmd.take_action(parsed_args)
1013+
self.fail('CommandError should be raised.')
1014+
except exceptions.CommandError as e:
1015+
self.assertEqual('Invalid changes-since value: Invalid time '
1016+
'value', str(e))
1017+
mock_parse_isotime.assert_called_once_with(
1018+
'Invalid time value'
1019+
)
1020+
9751021

9761022
class TestServerLock(TestServer):
9771023

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Add ``--deleted`` and ``--changes-since`` options to ``server list``
5+
command.
6+
[Bug `1647242 <https://bugs.launchpad.net/bugs/1647272>`_]

0 commit comments

Comments
 (0)