Deprecate special value 'auto' for attribute 'id' of compute_flavor

Across our modules we use the None values to mark default values for
module attributes. This is in line with openstacksdk's behaviour.

Change-Id: I5920aeeb8eef2ee1c2066a71a273ba52f02305c3
This commit is contained in:
Jakob Meng 2022-08-10 10:47:10 +02:00
parent d47cf4333c
commit b99218c143

View File

@ -10,7 +10,8 @@ module: compute_flavor
short_description: Manage OpenStack compute flavors short_description: Manage OpenStack compute flavors
author: OpenStack Ansible SIG author: OpenStack Ansible SIG
description: description:
- Add or remove flavors from OpenStack. - Add or remove compute flavors from OpenStack.
- Updating a flavor consists of deleting and (re)creating a flavor.
options: options:
state: state:
description: description:
@ -63,7 +64,10 @@ options:
- ID for the flavor. This is optional as a unique UUID will be - ID for the flavor. This is optional as a unique UUID will be
assigned if a value is not specified. assigned if a value is not specified.
- Note that this ID will only be used when first creating the flavor. - Note that this ID will only be used when first creating the flavor.
default: "auto" - The ID of an existing flavor cannot be changed.
- When I(id) is set to C(auto), a new id will be autogenerated.
C(auto) is kept for backward compatibility and
will be dropped in the next major release.
type: str type: str
aliases: ['flavorid'] aliases: ['flavorid']
extra_specs: extra_specs:
@ -201,7 +205,7 @@ class ComputeFlavorModule(OpenStackModule):
swap=dict(default=0, type='int'), swap=dict(default=0, type='int'),
rxtx_factor=dict(default=1.0, type='float'), rxtx_factor=dict(default=1.0, type='float'),
is_public=dict(default=True, type='bool'), is_public=dict(default=True, type='bool'),
id=dict(default='auto', aliases=['flavorid']), id=dict(aliases=['flavorid']),
extra_specs=dict(type='dict'), extra_specs=dict(type='dict'),
) )
@ -251,24 +255,25 @@ class ComputeFlavorModule(OpenStackModule):
flavor, extra_specs, old_extra_specs)) flavor, extra_specs, old_extra_specs))
if state == 'present': if state == 'present':
flavorid = self.params['id'] flavor_id = self.params['id']
# Keep for backward compatibility
flavor_id = None if flavor_id == 'auto' else flavor_id
if flavor and self._needs_update(flavor): if flavor and self._needs_update(flavor):
# Because only flavor descriptions are updateable, we have to # Because only flavor descriptions are updateable, we have to
# delete and recreate a flavor to "update" it # delete and recreate a flavor to "update" it
flavor_id = flavor['id']
self.conn.compute.delete_flavor(flavor) self.conn.compute.delete_flavor(flavor)
old_extra_specs = {} old_extra_specs = {}
if flavorid == 'auto':
flavorid = flavor['id']
flavor = None flavor = None
changed = False changed = False
if not flavor: if not flavor:
flavor = self.conn.create_flavor( flavor = self.conn.compute.create_flavor(
name=name, name=name,
ram=self.params['ram'], ram=self.params['ram'],
vcpus=self.params['vcpus'], vcpus=self.params['vcpus'],
disk=self.params['disk'], disk=self.params['disk'],
flavorid=flavorid, id=flavor_id,
ephemeral=self.params['ephemeral'], ephemeral=self.params['ephemeral'],
swap=self.params['swap'], swap=self.params['swap'],
rxtx_factor=self.params['rxtx_factor'], rxtx_factor=self.params['rxtx_factor'],