Add changes-since support when list servers
Nova API supports change-since filter when list servers: https://github.com/openstack/nova/blob/master/nova/api/openstack/compute/servers.py#L325-L331 but in python-novaclient we don't. This patch add the support for change-since when list servers. Closes-bug: #1551591 depends-on: Ic2f239f634f917a5771b0401a5073546c710c036 Change-Id: I27f2d1e33a56d357e247111b338c93861716cfee
This commit is contained in:
parent
a7bffe8a71
commit
7cefdd36a6
novaclient
@ -13,6 +13,7 @@
|
||||
import uuid
|
||||
|
||||
from novaclient.tests.functional import base
|
||||
from oslo_utils import timeutils
|
||||
|
||||
|
||||
class TestServersBootNovaClient(base.ClientTestBase):
|
||||
@ -84,6 +85,16 @@ class TestServersListNovaClient(base.ClientTestBase):
|
||||
servers = output.split("\n")[3:-2]
|
||||
self.assertEqual(1, len(servers), output)
|
||||
|
||||
def test_list_with_changes_since(self):
|
||||
now = timeutils.isotime()
|
||||
name = str(uuid.uuid4())
|
||||
self._create_servers(name, 1)
|
||||
output = self.nova("list", params="--changes-since %s" % now)
|
||||
self.assertIn(name, output, output)
|
||||
now = timeutils.isotime()
|
||||
output = self.nova("list", params="--changes-since %s" % now)
|
||||
self.assertNotIn(name, output, output)
|
||||
|
||||
def test_list_all_servers(self):
|
||||
name = str(uuid.uuid4())
|
||||
precreated_servers = self._create_servers(name, 3)
|
||||
|
@ -1063,6 +1063,15 @@ class ShellTest(utils.TestCase):
|
||||
self.run_command('list --limit 3')
|
||||
self.assert_called('GET', '/servers/detail?limit=3')
|
||||
|
||||
def test_list_with_changes_since(self):
|
||||
self.run_command('list --changes-since 2016-02-29T06:23:22')
|
||||
self.assert_called(
|
||||
'GET', '/servers/detail?changes-since=2016-02-29T06%3A23%3A22')
|
||||
|
||||
def test_list_with_changes_since_invalid_value(self):
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
self.run_command, 'list --changes-since 0123456789')
|
||||
|
||||
def test_meta_parsing(self):
|
||||
meta = ['key1=meta1', 'key2=meta2']
|
||||
ref = {'key1': 'meta1', 'key2': 'meta2'}
|
||||
|
@ -1458,6 +1458,14 @@ def do_image_delete(cs, args):
|
||||
"will be displayed. If limit is bigger than 'osapi_max_limit' "
|
||||
"option of Nova API, limit 'osapi_max_limit' will be used "
|
||||
"instead."))
|
||||
@utils.arg(
|
||||
'--changes-since',
|
||||
dest='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 formated time."
|
||||
"ex 2016-03-04T06:27:59Z ."))
|
||||
def do_list(cs, args):
|
||||
"""List active servers."""
|
||||
imageid = None
|
||||
@ -1482,7 +1490,8 @@ def do_list(cs, args):
|
||||
'user_id': args.user,
|
||||
'host': args.host,
|
||||
'deleted': args.deleted,
|
||||
'instance_name': args.instance_name}
|
||||
'instance_name': args.instance_name,
|
||||
'changes-since': args.changes_since}
|
||||
|
||||
filters = {'flavor': lambda f: f['id'],
|
||||
'security_groups': utils._format_security_groups}
|
||||
@ -1504,6 +1513,13 @@ def do_list(cs, args):
|
||||
sort_keys.append(sort_key)
|
||||
sort_dirs.append(sort_dir)
|
||||
|
||||
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'])
|
||||
|
||||
servers = cs.servers.list(detailed=detailed,
|
||||
search_opts=search_opts,
|
||||
sort_keys=sort_keys,
|
||||
@ -1554,6 +1570,8 @@ def do_list(cs, args):
|
||||
# Tenant ID as well
|
||||
if search_opts['all_tenants']:
|
||||
columns.insert(2, 'Tenant ID')
|
||||
if search_opts['changes-since']:
|
||||
columns.append('Updated')
|
||||
formatters['Networks'] = utils._format_servers_list_networks
|
||||
sortby_index = 1
|
||||
if args.sort:
|
||||
|
Loading…
x
Reference in New Issue
Block a user