mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-03 06:49:10 -07: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
|
default: False
|
||||||
version_added: "2.7"
|
version_added: "2.7"
|
||||||
type: bool
|
type: bool
|
||||||
|
cluster_version:
|
||||||
|
description:
|
||||||
|
- "Filter the hosts based on the cluster version."
|
||||||
|
type: str
|
||||||
|
version_added: "2.8"
|
||||||
|
|
||||||
extends_documentation_fragment: ovirt_facts
|
extends_documentation_fragment: ovirt_facts
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -46,6 +52,12 @@ EXAMPLES = '''
|
||||||
pattern: name=host* and datacenter=west
|
pattern: name=host* and datacenter=west
|
||||||
- debug:
|
- debug:
|
||||||
var: ovirt_hosts
|
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 = '''
|
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():
|
def main():
|
||||||
argument_spec = ovirt_facts_full_argument_spec(
|
argument_spec = ovirt_facts_full_argument_spec(
|
||||||
pattern=dict(default='', required=False),
|
pattern=dict(default='', required=False),
|
||||||
all_content=dict(default=False, type='bool'),
|
all_content=dict(default=False, type='bool'),
|
||||||
|
cluster_version=dict(default=None, type='str'),
|
||||||
)
|
)
|
||||||
module = AnsibleModule(argument_spec)
|
module = AnsibleModule(argument_spec)
|
||||||
|
|
||||||
|
@ -83,7 +107,11 @@ def main():
|
||||||
hosts = hosts_service.list(
|
hosts = hosts_service.list(
|
||||||
search=module.params['pattern'],
|
search=module.params['pattern'],
|
||||||
all_content=module.params['all_content'],
|
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(
|
module.exit_json(
|
||||||
changed=False,
|
changed=False,
|
||||||
ansible_facts=dict(
|
ansible_facts=dict(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue