1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

ovirt_templates: Add searching by cluster (#40934)

* ovirt_templates: Add searching by cluster

* ovirt_disks: Add searching by sd and vm_name

* Fix python syntax
This commit is contained in:
Ondra Machacek 2018-05-31 12:40:30 +02:00 committed by ansibot
parent 43af09fc8f
commit 142cc48ca9
2 changed files with 25 additions and 0 deletions

View file

@ -555,6 +555,18 @@ class DiskAttachmentsModule(DisksModule):
) )
def searchable_attributes(module):
"""
Return all searchable disk attributes passed to module.
"""
attributes = {
'name': module.params.get('name'),
'Storage.name': module.params.get('storage_domain'),
'vm_names': module.params.get('vm_name'),
}
return dict((k, v) for k, v in attributes.items() if v is not None)
def main(): def main():
argument_spec = ovirt_full_argument_spec( argument_spec = ovirt_full_argument_spec(
state=dict( state=dict(
@ -616,6 +628,7 @@ def main():
if state in ('present', 'detached', 'attached'): if state in ('present', 'detached', 'attached'):
ret = disks_module.create( ret = disks_module.create(
entity=disk, entity=disk,
search_params=searchable_attributes(module),
result_state=otypes.DiskStatus.OK if lun is None else None, result_state=otypes.DiskStatus.OK if lun is None else None,
fail_condition=lambda d: d.status == otypes.DiskStatus.ILLEGAL if lun is None else False, fail_condition=lambda d: d.status == otypes.DiskStatus.ILLEGAL if lun is None else False,
) )

View file

@ -422,6 +422,17 @@ def _get_vnic_profile_mappings(module):
return vnicProfileMappings return vnicProfileMappings
def searchable_attributes(module):
"""
Return all searchable template attributes passed to module.
"""
attributes = {
'name': module.params.get('name'),
'cluster': module.params.get('cluster'),
}
return dict((k, v) for k, v in attributes.items() if v is not None)
def main(): def main():
argument_spec = ovirt_full_argument_spec( argument_spec = ovirt_full_argument_spec(
state=dict( state=dict(
@ -474,6 +485,7 @@ def main():
if state == 'present': if state == 'present':
ret = templates_module.create( ret = templates_module.create(
result_state=otypes.TemplateStatus.OK, result_state=otypes.TemplateStatus.OK,
search_params=searchable_attributes(module),
clone_permissions=module.params['clone_permissions'], clone_permissions=module.params['clone_permissions'],
seal=module.params['seal'], seal=module.params['seal'],
) )