Refactored compute_service_info module
Change-Id: I1773b72f8c7eaec77f0480045c45073dc522c5cf
This commit is contained in:
11
ci/roles/compute_service/defaults/main.yml
Normal file
11
ci/roles/compute_service/defaults/main.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
expected_fields:
|
||||||
|
- availability_zone
|
||||||
|
- binary
|
||||||
|
- disabled_reason
|
||||||
|
- host
|
||||||
|
- id
|
||||||
|
- is_forced_down
|
||||||
|
- name
|
||||||
|
- state
|
||||||
|
- status
|
||||||
|
- updated_at
|
||||||
23
ci/roles/compute_service/tasks/main.yml
Normal file
23
ci/roles/compute_service/tasks/main.yml
Normal file
@@ -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
|
||||||
@@ -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"
|
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
- { role: coe_cluster_template, tags: coe_cluster_template }
|
- { role: coe_cluster_template, tags: coe_cluster_template }
|
||||||
- { role: compute_flavor, tags: compute_flavor }
|
- { role: compute_flavor, tags: compute_flavor }
|
||||||
- { role: compute_flavor_access, tags: compute_flavor_access }
|
- { role: compute_flavor_access, tags: compute_flavor_access }
|
||||||
|
- { role: compute_service, tags: compute_service }
|
||||||
- { role: config, tags: config }
|
- { role: config, tags: config }
|
||||||
- { role: dns_zone, tags: dns_zone }
|
- { role: dns_zone, tags: dns_zone }
|
||||||
- { role: endpoint, tags: endpoint }
|
- { role: endpoint, tags: endpoint }
|
||||||
@@ -37,9 +38,6 @@
|
|||||||
- { role: logging, tags: logging }
|
- { role: logging, tags: logging }
|
||||||
- { role: network, tags: network }
|
- { role: network, tags: network }
|
||||||
- { role: neutron_rbac_policy, tags: neutron_rbac_policy }
|
- { 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, tags: object }
|
||||||
- { role: object_container, tags: object_container }
|
- { role: object_container, tags: object_container }
|
||||||
- { role: port, tags: port }
|
- { role: port, tags: port }
|
||||||
|
|||||||
@@ -4,94 +4,77 @@
|
|||||||
# Copyright (c) 2016 Hewlett-Packard Enterprise Corporation
|
# 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)
|
# 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
|
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
|
author: OpenStack Ansible SIG
|
||||||
description:
|
description:
|
||||||
- Retrieve information about nova compute services
|
- Fetch OpenStack Compute (Nova) services.
|
||||||
options:
|
options:
|
||||||
binary:
|
binary:
|
||||||
description:
|
description:
|
||||||
- Filter by service binary type. Requires openstacksdk>=0.53.
|
- Filter the service list result by binary name of the service.
|
||||||
type: str
|
type: str
|
||||||
host:
|
host:
|
||||||
description:
|
description:
|
||||||
- Filter by service host. Requires openstacksdk>=0.53.
|
- Filter the service list result by the host name.
|
||||||
type: str
|
type: str
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 3.6"
|
- "python >= 3.6"
|
||||||
- "openstacksdk"
|
- "openstacksdk"
|
||||||
|
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- openstack.cloud.openstack
|
- openstack.cloud.openstack
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = r'''
|
||||||
# Gather information about compute services
|
- name: Fetch all OpenStack Compute (Nova) services
|
||||||
- openstack.cloud.compute_service_info:
|
openstack.cloud.compute_service_info:
|
||||||
|
cloud: awesomecloud
|
||||||
|
|
||||||
|
- name: Fetch a subset of OpenStack Compute (Nova) services
|
||||||
|
openstack.cloud.compute_service_info:
|
||||||
cloud: awesomecloud
|
cloud: awesomecloud
|
||||||
binary: "nova-compute"
|
binary: "nova-compute"
|
||||||
host: "localhost"
|
host: "localhost"
|
||||||
register: result
|
|
||||||
- openstack.cloud.compute_service_info:
|
|
||||||
cloud: awesomecloud
|
|
||||||
register: result
|
|
||||||
- debug:
|
|
||||||
msg: "{{ result.openstack_compute_services }}"
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
RETURN = r'''
|
||||||
RETURN = '''
|
compute_services:
|
||||||
openstack_compute_services:
|
description: List of dictionaries describing Compute (Nova) services.
|
||||||
description: has all the OpenStack information about compute services
|
returned: always
|
||||||
returned: always, but can be null
|
type: list
|
||||||
type: complex
|
elements: dict
|
||||||
contains:
|
contains:
|
||||||
id:
|
availability_zone:
|
||||||
description: Unique UUID.
|
description: The availability zone name.
|
||||||
returned: success
|
|
||||||
type: str
|
type: str
|
||||||
binary:
|
binary:
|
||||||
description: The binary name of the service.
|
description: The binary name of the service.
|
||||||
returned: success
|
|
||||||
type: str
|
|
||||||
host:
|
|
||||||
description: The name of the host.
|
|
||||||
returned: success
|
|
||||||
type: str
|
type: str
|
||||||
disabled_reason:
|
disabled_reason:
|
||||||
description: The reason why the service is disabled
|
description: The reason why the service is disabled
|
||||||
returned: success and OpenStack SDK >= 0.53
|
|
||||||
type: str
|
type: str
|
||||||
disables_reason:
|
id:
|
||||||
description: The reason why the service is disabled
|
description: Unique UUID.
|
||||||
returned: success and OpenStack SDK < 0.53
|
|
||||||
type: str
|
|
||||||
availability_zone:
|
|
||||||
description: The availability zone name.
|
|
||||||
returned: success
|
|
||||||
type: str
|
type: str
|
||||||
is_forced_down:
|
is_forced_down:
|
||||||
description: If the service has been forced down or nova-compute
|
description: If the service has been forced down or nova-compute
|
||||||
returned: success
|
|
||||||
type: bool
|
type: bool
|
||||||
|
host:
|
||||||
|
description: The name of the host.
|
||||||
|
type: str
|
||||||
name:
|
name:
|
||||||
description: Service name
|
description: Service name
|
||||||
returned: success
|
|
||||||
type: str
|
|
||||||
status:
|
|
||||||
description: The status of the service. One of enabled or disabled.
|
|
||||||
returned: success
|
|
||||||
type: str
|
type: str
|
||||||
state:
|
state:
|
||||||
description: The state of the service. One of up or down.
|
description: The state of the service. One of up or down.
|
||||||
returned: success
|
type: str
|
||||||
|
status:
|
||||||
|
description: The status of the service. One of enabled or disabled.
|
||||||
type: str
|
type: str
|
||||||
update_at:
|
update_at:
|
||||||
description: The date and time when the resource was updated
|
description: The date and time when the resource was updated
|
||||||
returned: success
|
|
||||||
type: str
|
type: str
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@@ -100,19 +83,23 @@ from ansible_collections.openstack.cloud.plugins.module_utils.openstack import O
|
|||||||
|
|
||||||
class ComputeServiceInfoModule(OpenStackModule):
|
class ComputeServiceInfoModule(OpenStackModule):
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
binary=dict(min_ver='0.53.0'),
|
binary=dict(),
|
||||||
host=dict(min_ver='0.53.0'),
|
host=dict(),
|
||||||
)
|
)
|
||||||
|
|
||||||
module_kwargs = dict(
|
module_kwargs = dict(
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
filters = self.check_versioned(binary=self.params['binary'], host=self.params['host'])
|
kwargs = {k: self.params[k]
|
||||||
filters = {k: v for k, v in filters.items() if v is not None}
|
for k in ['binary', 'host']
|
||||||
services = self.conn.compute.services(**filters)
|
if self.params[k] is not None}
|
||||||
services = [service.to_dict(computed=False) for service in services]
|
compute_services = self.conn.compute.services(**kwargs)
|
||||||
self.exit_json(changed=False, openstack_compute_services=services)
|
|
||||||
|
self.exit_json(changed=False,
|
||||||
|
compute_services=[s.to_dict(computed=False)
|
||||||
|
for s in compute_services])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user