mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-13 13:02:21 +00:00
Changed compute_flavor_info module to use OpenStack SDK's proxy layer
Change-Id: Idad13228efe55b2dd35224cc37c61657590f9b8e
This commit is contained in:
33
ci/roles/compute_flavor_info/tasks/main.yml
Normal file
33
ci/roles/compute_flavor_info/tasks/main.yml
Normal 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'
|
||||||
@@ -35,6 +35,8 @@
|
|||||||
- rbac
|
- rbac
|
||||||
- neutron_rbac
|
- neutron_rbac
|
||||||
- { role: nova_flavor, tags: nova_flavor }
|
- { role: nova_flavor, tags: nova_flavor }
|
||||||
|
- role: compute_flavor_info
|
||||||
|
tags: nova_flavor
|
||||||
- role: nova_services
|
- role: nova_services
|
||||||
tags: nova_services
|
tags: nova_services
|
||||||
when: sdk_version is version(0.44, '>=')
|
when: sdk_version is version(0.44, '>=')
|
||||||
|
|||||||
@@ -126,6 +126,34 @@ openstack_flavors:
|
|||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
sample: "tiny"
|
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:
|
disk:
|
||||||
description: Size of local disk, in GB.
|
description: Size of local disk, in GB.
|
||||||
returned: success
|
returned: success
|
||||||
@@ -196,16 +224,22 @@ class ComputeFlavorInfoModule(OpenStackModule):
|
|||||||
filters['ephemeral'] = ephemeral
|
filters['ephemeral'] = ephemeral
|
||||||
|
|
||||||
if name:
|
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:
|
else:
|
||||||
flavors = self.conn.list_flavors()
|
flavors = list(self.conn.compute.flavors())
|
||||||
if filters:
|
if filters:
|
||||||
flavors = self.conn.range_search(flavors, filters)
|
flavors = self.conn.range_search(flavors, filters)
|
||||||
|
|
||||||
if limit is not None:
|
if limit is not None:
|
||||||
flavors = flavors[:limit]
|
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)
|
self.exit_json(changed=False, openstack_flavors=flavors)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user