diff --git a/ci/roles/compute_service/defaults/main.yml b/ci/roles/compute_service/defaults/main.yml new file mode 100644 index 00000000..c5ac3d02 --- /dev/null +++ b/ci/roles/compute_service/defaults/main.yml @@ -0,0 +1,11 @@ +expected_fields: + - availability_zone + - binary + - disabled_reason + - host + - id + - is_forced_down + - name + - state + - status + - updated_at diff --git a/ci/roles/compute_service/tasks/main.yml b/ci/roles/compute_service/tasks/main.yml new file mode 100644 index 00000000..6d045786 --- /dev/null +++ b/ci/roles/compute_service/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: Fetch compute services + openstack.cloud.compute_service_info: + cloud: "{{ cloud }}" + register: compute_services + +- name: Assert return values of compute_service_info module + assert: + that: + - compute_services.compute_services | length > 0 + # allow new fields to be introduced but prevent fields from being removed + - expected_fields|difference(compute_services.compute_services[0].keys())|length == 0 + +- name: Fetch compute services with filters + openstack.cloud.compute_service_info: + cloud: "{{ cloud }}" + binary: "nova-compute" + register: compute_services + +- name: Assert return values of compute_service_info module + assert: + that: + - compute_services.compute_services | length > 0 diff --git a/ci/roles/nova_services/tasks/main.yml b/ci/roles/nova_services/tasks/main.yml deleted file mode 100644 index c871fbad..00000000 --- a/ci/roles/nova_services/tasks/main.yml +++ /dev/null @@ -1,33 +0,0 @@ ---- - -- name: Get nova compute services info - openstack.cloud.compute_service_info: - cloud: "{{ cloud }}" - register: result - failed_when: "result.openstack_compute_services | length <= 0" - -- name: Assert fields on OpenStack SDK before 0.53 - when: sdk_version is version(0.53, '<') - assert: - that: - - '["availability_zone", "binary", "disables_reason", - "host", "name", "state", "status", "id"] | - difference(result.openstack_compute_services.0.keys()) | length == 0' - -- name: Assert fields on OpenStack SDK 0.53 and later - when: sdk_version is version(0.53, '>=') - assert: - that: - - '["availability_zone", "binary", "disabled_reason", "is_forced_down", - "host", "name", "state", "status", "updated_at", "id"] | - difference(result.openstack_compute_services.0.keys()) | length == 0' - -- name: Filter compute services. Supported since OpenStack SDK 0.53.0 (Wallaby). - when: sdk_version is version(0.53, '>=') - block: - - name: Get nova compute services info - openstack.cloud.compute_service_info: - cloud: "{{ cloud }}" - binary: "nova-compute" - register: result - failed_when: "result.openstack_compute_services | length <= 0" diff --git a/ci/run-collection.yml b/ci/run-collection.yml index fa0b63dc..e4f0de2b 100644 --- a/ci/run-collection.yml +++ b/ci/run-collection.yml @@ -11,6 +11,7 @@ - { role: coe_cluster_template, tags: coe_cluster_template } - { role: compute_flavor, tags: compute_flavor } - { role: compute_flavor_access, tags: compute_flavor_access } + - { role: compute_service, tags: compute_service } - { role: config, tags: config } - { role: dns_zone, tags: dns_zone } - { role: endpoint, tags: endpoint } @@ -37,9 +38,6 @@ - { role: logging, tags: logging } - { role: network, tags: network } - { role: neutron_rbac_policy, tags: neutron_rbac_policy } - - role: nova_services - tags: nova_services - when: sdk_version is version(0.44, '>=') - { role: object, tags: object } - { role: object_container, tags: object_container } - { role: port, tags: port } diff --git a/plugins/modules/compute_service_info.py b/plugins/modules/compute_service_info.py index dae452d0..9e922bc1 100644 --- a/plugins/modules/compute_service_info.py +++ b/plugins/modules/compute_service_info.py @@ -4,95 +4,78 @@ # Copyright (c) 2016 Hewlett-Packard Enterprise Corporation # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: compute_service_info -short_description: Retrieve information about one or more OpenStack compute services +short_description: Fetch OpenStack Compute (Nova) services author: OpenStack Ansible SIG description: - - Retrieve information about nova compute services + - Fetch OpenStack Compute (Nova) services. options: - binary: - description: - - Filter by service binary type. Requires openstacksdk>=0.53. - type: str - host: - description: - - Filter by service host. Requires openstacksdk>=0.53. - type: str + binary: + description: + - Filter the service list result by binary name of the service. + type: str + host: + description: + - Filter the service list result by the host name. + type: str requirements: - - "python >= 3.6" - - "openstacksdk" - + - "python >= 3.6" + - "openstacksdk" extends_documentation_fragment: -- openstack.cloud.openstack + - openstack.cloud.openstack ''' -EXAMPLES = ''' -# Gather information about compute services -- openstack.cloud.compute_service_info: +EXAMPLES = r''' +- name: Fetch all OpenStack Compute (Nova) services + openstack.cloud.compute_service_info: + cloud: awesomecloud + +- name: Fetch a subset of OpenStack Compute (Nova) services + openstack.cloud.compute_service_info: cloud: awesomecloud binary: "nova-compute" host: "localhost" - register: result -- openstack.cloud.compute_service_info: - cloud: awesomecloud - register: result -- debug: - msg: "{{ result.openstack_compute_services }}" ''' - -RETURN = ''' -openstack_compute_services: - description: has all the OpenStack information about compute services - returned: always, but can be null - type: complex - contains: - id: - description: Unique UUID. - returned: success - type: str - binary: - description: The binary name of the service. - returned: success - type: str - host: - description: The name of the host. - returned: success - type: str - disabled_reason: - description: The reason why the service is disabled - returned: success and OpenStack SDK >= 0.53 - type: str - disables_reason: - description: The reason why the service is disabled - returned: success and OpenStack SDK < 0.53 - type: str - availability_zone: - description: The availability zone name. - returned: success - type: str - is_forced_down: - description: If the service has been forced down or nova-compute - returned: success - type: bool - name: - description: Service name - returned: success - type: str - status: - description: The status of the service. One of enabled or disabled. - returned: success - type: str - state: - description: The state of the service. One of up or down. - returned: success - type: str - update_at: - description: The date and time when the resource was updated - returned: success - type: str +RETURN = r''' +compute_services: + description: List of dictionaries describing Compute (Nova) services. + returned: always + type: list + elements: dict + contains: + availability_zone: + description: The availability zone name. + type: str + binary: + description: The binary name of the service. + type: str + disabled_reason: + description: The reason why the service is disabled + type: str + id: + description: Unique UUID. + type: str + is_forced_down: + description: If the service has been forced down or nova-compute + type: bool + host: + description: The name of the host. + type: str + name: + description: Service name + type: str + state: + description: The state of the service. One of up or down. + type: str + status: + description: The status of the service. One of enabled or disabled. + type: str + update_at: + description: The date and time when the resource was updated + type: str ''' from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule @@ -100,19 +83,23 @@ from ansible_collections.openstack.cloud.plugins.module_utils.openstack import O class ComputeServiceInfoModule(OpenStackModule): argument_spec = dict( - binary=dict(min_ver='0.53.0'), - host=dict(min_ver='0.53.0'), + binary=dict(), + host=dict(), ) + module_kwargs = dict( supports_check_mode=True ) def run(self): - filters = self.check_versioned(binary=self.params['binary'], host=self.params['host']) - filters = {k: v for k, v in filters.items() if v is not None} - services = self.conn.compute.services(**filters) - services = [service.to_dict(computed=False) for service in services] - self.exit_json(changed=False, openstack_compute_services=services) + kwargs = {k: self.params[k] + for k in ['binary', 'host'] + if self.params[k] is not None} + compute_services = self.conn.compute.services(**kwargs) + + self.exit_json(changed=False, + compute_services=[s.to_dict(computed=False) + for s in compute_services]) def main():