Changed compute_flavor_info module to use OpenStack SDK's proxy layer

Change-Id: Idad13228efe55b2dd35224cc37c61657590f9b8e
This commit is contained in:
Arx Cruz 2022-02-07 11:49:13 +01:00 committed by Jakob Meng
parent ffa826c0d0
commit 1ec9afe2ca
3 changed files with 71 additions and 2 deletions

View File

@ -0,0 +1,33 @@
---
- name: List flavors
openstack.cloud.compute_flavor_info:
cloud: "{{ cloud }}"
- name: List flavors with filter
openstack.cloud.compute_flavor_info:
cloud: "{{ cloud }}"
name: "m1.tiny"
register: flavor_name
- name: Check output of list flavors with filter
assert:
that:
- flavor_name.openstack_flavors | length == 1
- name: Assert fields on SDK 0.*
when: sdk_version is version(1.0, '<')
assert:
that:
- '["name", "description", "disk", "is_public", "ram",
"vcpus", "swap", "ephemeral", "is_disabled", "rxtx_factor", "id",
"extra_specs"] | difference(flavor_name.openstack_flavors.0.keys())
| length == 0'
- name: Assert fields on SDK 1.*
when: sdk_version is version(1.0, '>=')
assert:
that:
- '["name", "original_name", "description", "disk", "is_public", "ram",
"vcpus", "swap", "ephemeral", "is_disabled", "rxtx_factor", "id",
"extra_specs"] | difference(flavor_name.openstack_flavors.0.keys())
| length == 0'

View File

@ -35,6 +35,8 @@
- rbac
- neutron_rbac
- { role: nova_flavor, tags: nova_flavor }
- role: compute_flavor_info
tags: nova_flavor
- role: nova_services
tags: nova_services
when: sdk_version is version(0.44, '>=')

View File

@ -126,6 +126,34 @@ openstack_flavors:
returned: success
type: str
sample: "tiny"
original_name:
description: Original flavor name
returned: success
type: str
sample: "tiny"
description:
description: Description of the flavor
returned: success
type: str
sample: "Small flavor"
is_disabled:
description: Wether the flavor is enabled or not
returned: success
type: bool
sample: False
rxtx_factor:
description: Factor to be multiplied by the rxtx_base property of
the network it is attached to in order to have a
different bandwidth cap.
returned: success
type: float
sample: 1.0
extra_specs:
description: Optional parameters to configure different flavors
options.
returned: success
type: dict
sample: "{'hw_rng:allowed': True}"
disk:
description: Size of local disk, in GB.
returned: success
@ -196,16 +224,22 @@ class ComputeFlavorInfoModule(OpenStackModule):
filters['ephemeral'] = ephemeral
if name:
flavors = self.conn.search_flavors(filters={'name': name})
# extra_specs are exposed in the flavor representation since Rocky, so we do not
# need get_extra_specs=True which is not available in OpenStack SDK 0.36 (Train)
# Ref.: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html
flavor = self.conn.compute.find_flavor(name)
flavors = [flavor] if flavor else []
else:
flavors = self.conn.list_flavors()
flavors = list(self.conn.compute.flavors())
if filters:
flavors = self.conn.range_search(flavors, filters)
if limit is not None:
flavors = flavors[:limit]
# Transform entries to dict
flavors = [flavor.to_dict(computed=False) for flavor in flavors]
self.exit_json(changed=False, openstack_flavors=flavors)