mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ovirt hosts facts add cluster version filtration (#48664)
* ovirt hosts facts add cluster version filtration * update filtering of ovirt hosts and input of cluster version * ovirt host facts change compat version to string
This commit is contained in:
parent
8206ee96e3
commit
88bb555ab8
1 changed files with 28 additions and 0 deletions
|
@ -33,6 +33,12 @@ options:
|
|||
default: False
|
||||
version_added: "2.7"
|
||||
type: bool
|
||||
cluster_version:
|
||||
description:
|
||||
- "Filter the hosts based on the cluster version."
|
||||
type: str
|
||||
version_added: "2.8"
|
||||
|
||||
extends_documentation_fragment: ovirt_facts
|
||||
'''
|
||||
|
||||
|
@ -46,6 +52,12 @@ EXAMPLES = '''
|
|||
pattern: name=host* and datacenter=west
|
||||
- debug:
|
||||
var: ovirt_hosts
|
||||
# All hosts with cluster version 4.2:
|
||||
- ovirt_host_facts:
|
||||
pattern: name=host*
|
||||
cluster_version: "4.2"
|
||||
- debug:
|
||||
var: ovirt_hosts
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
|
@ -67,10 +79,22 @@ from ansible.module_utils.ovirt import (
|
|||
)
|
||||
|
||||
|
||||
def get_filtered_hosts(cluster_version, hosts):
|
||||
# Filtering by cluster version returns only those which have same cluster version as input
|
||||
filtered_hosts = []
|
||||
for host in hosts:
|
||||
cluster = host.cluster
|
||||
cluster_version_host = str(cluster.version.major) + '.' + str(cluster.version.minor)
|
||||
if cluster_version_host == cluster_version:
|
||||
filtered_hosts.append(host)
|
||||
return filtered_hosts
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = ovirt_facts_full_argument_spec(
|
||||
pattern=dict(default='', required=False),
|
||||
all_content=dict(default=False, type='bool'),
|
||||
cluster_version=dict(default=None, type='str'),
|
||||
)
|
||||
module = AnsibleModule(argument_spec)
|
||||
|
||||
|
@ -83,7 +107,11 @@ def main():
|
|||
hosts = hosts_service.list(
|
||||
search=module.params['pattern'],
|
||||
all_content=module.params['all_content'],
|
||||
follow='cluster',
|
||||
)
|
||||
cluster_version = module.params.get('cluster_version')
|
||||
if cluster_version is not None:
|
||||
hosts = get_filtered_hosts(cluster_version, hosts)
|
||||
module.exit_json(
|
||||
changed=False,
|
||||
ansible_facts=dict(
|
||||
|
|
Loading…
Reference in a new issue