diff options
author | Matt Riedemann <mriedem.os@gmail.com> | 2017-12-14 18:20:45 -0500 |
---|---|---|
committer | Yikun Jiang <yikunkero@gmail.com> | 2018-01-15 14:42:53 +0800 |
commit | 038cfdd5b3395acbf483dc982cae3eba34ddf1c5 (patch) | |
tree | fc020977e18a1d40293957bc0e6e9a089361900b /novaclient/v2/servers.py | |
parent | fefc3ba723865307f4cc2ca287eb59faa4e8a5b1 (diff) | |
download | python-novaclient-038cfdd5b3395acbf483dc982cae3eba34ddf1c5.tar.gz |
Add support for the 2.57 microversion
With the 2.57 microversion, we:
* Deprecate the --file option from the nova boot and
nova rebuild CLIs and API bindings.
* Add --user-data and --user-data-unset to the nova rebuild
CLI and API bindings.
* Deprecate the maxPersonality and maxPersonalitySize fields
from the nova limits and nova absolute-limits CLIs and API
bindings.
* Deprecate injected_files, injected_file_content_bytes, and
injected_file_path_bytes from the nova quota-show,
nova quota-update, nova quota-defaults, nova quota-class-show,
and nova quota-class-update CLIs and API bindings.
Part of blueprint deprecate-file-injection
Change-Id: Id13e3eac3ef87d429454042ac7046e865774ff8e
Diffstat (limited to 'novaclient/v2/servers.py')
-rw-r--r-- | novaclient/v2/servers.py | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/novaclient/v2/servers.py b/novaclient/v2/servers.py index e305253e..79ab0cdc 100644 --- a/novaclient/v2/servers.py +++ b/novaclient/v2/servers.py @@ -621,6 +621,27 @@ class SecurityGroup(base.Resource): class ServerManager(base.BootingManagerWithFind): resource_class = Server + @staticmethod + def transform_userdata(userdata): + if hasattr(userdata, 'read'): + userdata = userdata.read() + + # NOTE(melwitt): Text file data is converted to bytes prior to + # base64 encoding. The utf-8 encoding will fail for binary files. + if six.PY3: + try: + userdata = userdata.encode("utf-8") + except AttributeError: + # In python 3, 'bytes' object has no attribute 'encode' + pass + else: + try: + userdata = encodeutils.safe_encode(userdata) + except UnicodeDecodeError: + pass + + return base64.b64encode(userdata).decode('utf-8') + def _boot(self, response_key, name, image, flavor, meta=None, files=None, userdata=None, reservation_id=False, return_raw=False, min_count=None, @@ -639,25 +660,7 @@ class ServerManager(base.BootingManagerWithFind): "flavorRef": str(base.getid(flavor)), }} if userdata: - if hasattr(userdata, 'read'): - userdata = userdata.read() - - # NOTE(melwitt): Text file data is converted to bytes prior to - # base64 encoding. The utf-8 encoding will fail for binary files. - if six.PY3: - try: - userdata = userdata.encode("utf-8") - except AttributeError: - # In python 3, 'bytes' object has no attribute 'encode' - pass - else: - try: - userdata = encodeutils.safe_encode(userdata) - except UnicodeDecodeError: - pass - - userdata_b64 = base64.b64encode(userdata).decode('utf-8') - body["server"]["user_data"] = userdata_b64 + body["server"]["user_data"] = self.transform_userdata(userdata) if meta: body["server"]["metadata"] = meta if reservation_id: @@ -1204,6 +1207,7 @@ class ServerManager(base.BootingManagerWithFind): are the file contents (either as a string or as a file-like object). A maximum of five entries is allowed, and each file must be 10k or less. + (deprecated starting with microversion 2.57) :param reservation_id: return a reservation_id for the set of servers being requested, boolean. :param min_count: (optional extension) The minimum number of @@ -1284,6 +1288,10 @@ class ServerManager(base.BootingManagerWithFind): if "tags" in kwargs and self.api_version < boot_tags_microversion: raise exceptions.UnsupportedAttribute("tags", "2.52") + personality_files_deprecation = api_versions.APIVersion('2.57') + if files and self.api_version >= personality_files_deprecation: + raise exceptions.UnsupportedAttribute('files', '2.0', '2.56') + boot_kwargs = dict( meta=meta, files=files, userdata=userdata, reservation_id=reservation_id, min_count=min_count, @@ -1397,11 +1405,17 @@ class ServerManager(base.BootingManagerWithFind): are the file contents (either as a string or as a file-like object). A maximum of five entries is allowed, and each file must be 10k or less. + (deprecated starting with microversion 2.57) :param description: optional description of the server (allowed since microversion 2.19) :param key_name: optional key pair name for rebuild operation; passing None will unset the key for the server instance (starting from microversion 2.54) + :param userdata: optional user data to pass to be exposed by the + metadata server; this can be a file type object as + well or a string. If None is specified, the existing + user_data is unset. + (starting from microversion 2.57) :returns: :class:`Server` """ descr_microversion = api_versions.APIVersion("2.19") @@ -1414,6 +1428,14 @@ class ServerManager(base.BootingManagerWithFind): self.api_version < api_versions.APIVersion('2.54')): raise exceptions.UnsupportedAttribute('key_name', '2.54') + # Microversion 2.57 deprecates personality files and adds support + # for user_data. + files_and_userdata = api_versions.APIVersion('2.57') + if files and self.api_version >= files_and_userdata: + raise exceptions.UnsupportedAttribute('files', '2.0', '2.56') + if 'userdata' in kwargs and self.api_version < files_and_userdata: + raise exceptions.UnsupportedAttribute('userdata', '2.57') + body = {'imageRef': base.getid(image)} if password is not None: body['adminPass'] = password @@ -1443,6 +1465,12 @@ class ServerManager(base.BootingManagerWithFind): 'path': filepath, 'contents': cont, }) + if 'userdata' in kwargs: + # If userdata is specified but None, it means unset the existing + # user_data on the instance. + userdata = kwargs['userdata'] + body['user_data'] = (userdata if userdata is None else + self.transform_userdata(userdata)) resp, body = self._action_return_resp_and_body('rebuild', server, body, **kwargs) |