diff --git a/ci/roles/compute_flavor_info/tasks/main.yml b/ci/roles/compute_flavor_info/tasks/main.yml new file mode 100644 index 00000000..982d0c29 --- /dev/null +++ b/ci/roles/compute_flavor_info/tasks/main.yml @@ -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' diff --git a/ci/run-collection.yml b/ci/run-collection.yml index 4a03d5f1..ec39c641 100644 --- a/ci/run-collection.yml +++ b/ci/run-collection.yml @@ -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, '>=') diff --git a/plugins/modules/compute_flavor_info.py b/plugins/modules/compute_flavor_info.py index f8900a01..facaf581 100644 --- a/plugins/modules/compute_flavor_info.py +++ b/plugins/modules/compute_flavor_info.py @@ -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)