summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin_Zheng <zhengzhenyu@huawei.com>2017-07-18 11:50:04 +0800
committerMatt Riedemann <mriedem.os@gmail.com>2017-07-19 14:19:56 -0400
commit30c9215da730d13c7b96422621aecbfbadfb517c (patch)
tree66cc2408bc1fc2255b1067fe008f4263bceceb68
parent24e4e92c1e9bfc8cfa15816ac42cd2e5e1914146 (diff)
downloadpython-novaclient-30c9215da730d13c7b96422621aecbfbadfb517c.tar.gz
Microversion 2.52 - Support tag when boot
Change-Id: Ib65894f0e128c599db8d3440fe5a8427e62d5782 Depends-On: Ifcaaf285c8f98a1d0e8bbbc87b2f57fbce057346 Implements: blueprint support-tag-instance-when-boot
-rw-r--r--novaclient/__init__.py2
-rw-r--r--novaclient/tests/unit/v2/test_servers.py44
-rw-r--r--novaclient/tests/unit/v2/test_shell.py40
-rw-r--r--novaclient/v2/servers.py11
-rw-r--r--novaclient/v2/shell.py10
-rw-r--r--releasenotes/notes/microversion-v2_52-2fe81b3bf2e4b4ea.yaml8
6 files changed, 113 insertions, 2 deletions
diff --git a/novaclient/__init__.py b/novaclient/__init__.py
index d6ebb963..926bfff6 100644
--- a/novaclient/__init__.py
+++ b/novaclient/__init__.py
@@ -25,4 +25,4 @@ API_MIN_VERSION = api_versions.APIVersion("2.1")
# when client supported the max version, and bumped sequentially, otherwise
# the client may break due to server side new version may include some
# backward incompatible change.
-API_MAX_VERSION = api_versions.APIVersion("2.51")
+API_MAX_VERSION = api_versions.APIVersion("2.52")
diff --git a/novaclient/tests/unit/v2/test_servers.py b/novaclient/tests/unit/v2/test_servers.py
index 04772306..b807a7dc 100644
--- a/novaclient/tests/unit/v2/test_servers.py
+++ b/novaclient/tests/unit/v2/test_servers.py
@@ -1483,3 +1483,47 @@ class ServersV249Test(ServersV2_37Test):
# novaclient.v2.servers.Server.remove_fixed_ip()
# is not available after 2.44
pass
+
+
+class ServersV252Test(ServersV249Test):
+
+ api_version = "2.52"
+
+ def test_create_server_with_tags(self):
+ self.cs.servers.create(
+ name="My server",
+ image=1,
+ flavor=1,
+ meta={'foo': 'bar'},
+ userdata="hello moto",
+ key_name="fakekey",
+ nics=self._get_server_create_default_nics(),
+ tags=['tag1', 'tag2']
+ )
+ self.assert_called('POST', '/servers',
+ {'server': {
+ 'flavorRef': '1',
+ 'imageRef': '1',
+ 'key_name': 'fakekey',
+ 'max_count': 1,
+ 'metadata': {'foo': 'bar'},
+ 'min_count': 1,
+ 'name': 'My server',
+ 'networks': 'auto',
+ 'tags': ['tag1', 'tag2'],
+ 'user_data': 'aGVsbG8gbW90bw=='
+ }}
+ )
+
+ def test_create_server_with_tags_pre_252_fails(self):
+ self.cs.api_version = api_versions.APIVersion('2.51')
+ self.assertRaises(exceptions.UnsupportedAttribute,
+ self.cs.servers.create,
+ name="My server",
+ image=1,
+ flavor=1,
+ meta={'foo': 'bar'},
+ userdata="hello moto",
+ key_name="fakekey",
+ nics=self._get_server_create_default_nics(),
+ tags=['tag1', 'tag2'])
diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py
index dbda0b7d..66c462d9 100644
--- a/novaclient/tests/unit/v2/test_shell.py
+++ b/novaclient/tests/unit/v2/test_shell.py
@@ -1068,6 +1068,45 @@ class ShellTest(utils.TestCase):
FAKE_UUID_1)
self.assertRaises(argparse.ArgumentTypeError, self.run_command, cmd)
+ def test_boot_with_tags(self):
+ self.run_command('boot --flavor 1 --image %s --nic auto '
+ 'some-server --tags tag1,tag2' % FAKE_UUID_1,
+ api_version='2.52')
+ self.assert_called_anytime(
+ 'POST', '/servers',
+ {'server': {
+ 'flavorRef': '1',
+ 'name': 'some-server',
+ 'imageRef': FAKE_UUID_1,
+ 'min_count': 1,
+ 'max_count': 1,
+ 'networks': 'auto',
+ 'tags': ['tag1', 'tag2']
+ }},
+ )
+
+ def test_boot_without_tags_v252(self):
+ self.run_command('boot --flavor 1 --image %s --nic auto '
+ 'some-server' % FAKE_UUID_1,
+ api_version='2.52')
+ self.assert_called_anytime(
+ 'POST', '/servers',
+ {'server': {
+ 'flavorRef': '1',
+ 'name': 'some-server',
+ 'imageRef': FAKE_UUID_1,
+ 'min_count': 1,
+ 'max_count': 1,
+ 'networks': 'auto',
+ }},
+ )
+
+ def test_boot_with_tags_pre_v2_52(self):
+ cmd = ('boot --flavor 1 --image %s some-server '
+ '--tags tag1,tag2' % FAKE_UUID_1)
+ self.assertRaises(SystemExit, self.run_command,
+ cmd, api_version='2.51')
+
def test_flavor_list(self):
self.run_command('flavor-list')
self.assert_called_anytime('GET', '/flavors/detail')
@@ -3020,6 +3059,7 @@ class ShellTest(utils.TestCase):
# within the server details
48, # There are no version-wrapped shell method changes for this.
51, # There are no version-wrapped shell method changes for this.
+ 52, # There are no version-wrapped shell method changes for this.
])
versions_supported = set(range(0,
novaclient.API_MAX_VERSION.ver_minor + 1))
diff --git a/novaclient/v2/servers.py b/novaclient/v2/servers.py
index b60b0b6d..81a0b96b 100644
--- a/novaclient/v2/servers.py
+++ b/novaclient/v2/servers.py
@@ -663,7 +663,7 @@ class ServerManager(base.BootingManagerWithFind):
block_device_mapping_v2=None, nics=None, scheduler_hints=None,
config_drive=None, admin_pass=None, disk_config=None,
access_ip_v4=None, access_ip_v6=None, description=None,
- **kwargs):
+ tags=None, **kwargs):
"""
Create (boot) a new server.
"""
@@ -795,6 +795,9 @@ class ServerManager(base.BootingManagerWithFind):
if description:
body['server']['description'] = description
+ if tags:
+ body['server']['tags'] = tags
+
return self._create(resource_url, body, response_key,
return_raw=return_raw, **kwargs)
@@ -1337,6 +1340,8 @@ class ServerManager(base.BootingManagerWithFind):
:param access_ip_v6: (optional extension) add alternative access ip v6
:param description: optional description of the server (allowed since
microversion 2.19)
+ :param tags: A list of arbitrary strings to be added to the
+ server as tags (allowed since microversion 2.52)
"""
if not min_count:
min_count = 1
@@ -1369,6 +1374,10 @@ class ServerManager(base.BootingManagerWithFind):
"unsupported before microversion "
"2.32")
+ boot_tags_microversion = api_versions.APIVersion("2.52")
+ if "tags" in kwargs and self.api_version < boot_tags_microversion:
+ raise exceptions.UnsupportedAttribute("tags", "2.52")
+
boot_kwargs = dict(
meta=meta, files=files, userdata=userdata,
reservation_id=reservation_id, min_count=min_count,
diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py
index e390c26e..c00f88be 100644
--- a/novaclient/v2/shell.py
+++ b/novaclient/v2/shell.py
@@ -530,6 +530,9 @@ def _boot(cs, args):
if 'description' in args:
boot_kwargs["description"] = args.description
+ if 'tags' in args and args.tags:
+ boot_kwargs["tags"] = args.tags.split(',')
+
return boot_args, boot_kwargs
@@ -877,6 +880,13 @@ def _boot(cs, args):
default=None,
help=_('Description for the server.'),
start_version="2.19")
+@utils.arg(
+ '--tags',
+ metavar='<tags>',
+ default=None,
+ help=_('Tags for the server.'
+ 'Tags must be separated by commas: --tags <tag1,tag2>'),
+ start_version="2.52")
def do_boot(cs, args):
"""Boot a new server."""
boot_args, boot_kwargs = _boot(cs, args)
diff --git a/releasenotes/notes/microversion-v2_52-2fe81b3bf2e4b4ea.yaml b/releasenotes/notes/microversion-v2_52-2fe81b3bf2e4b4ea.yaml
new file mode 100644
index 00000000..0f7eeedc
--- /dev/null
+++ b/releasenotes/notes/microversion-v2_52-2fe81b3bf2e4b4ea.yaml
@@ -0,0 +1,8 @@
+---
+features:
+ - |
+ `Microversion 2.52`_ is now supported which adds the ``--tags`` option to
+ the ``nova boot`` command and a ``tags`` kwarg to the
+ ``novaclient.v2.servers.ServerManager.create()`` python API binding method.
+
+ .. _Microversion 2.52: https://docs.openstack.org/nova/latest/api_microversion_history.html#id47