Skip to content

Commit

Permalink
ovirt_disk: fix vm names search and allow attaching to vm (#361)
Browse files Browse the repository at this point in the history
* ovirt_disk: fix vm_names search when attaching to vm

* fix force_create to allow attaching vm

* add changelogs
  • Loading branch information
mnecas authored Sep 2, 2022
1 parent f3f3085 commit 9c01cf3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/361-ovirt_disk-fix-disk-attachment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- ovirt_disk - Fix disk attachment to VM (https://github.com/oVirt/ovirt-ansible-collection/pull/361).
4 changes: 2 additions & 2 deletions plugins/modules/ovirt_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def searchable_attributes(module):
attributes = {
'name': module.params.get('name'),
'Storage.name': module.params.get('storage_domain'),
'vm_names': module.params.get('vm_name'),
'vm_names': module.params.get('vm_name') if module.params.get('state') != 'attached' else None,
}
return dict((k, v) for k, v in attributes.items() if v is not None)

Expand Down Expand Up @@ -867,7 +867,7 @@ def main():
disk = _search_by_lun(disks_service, lun.get('id'))
else:
disk = disks_module.search_entity(search_params=searchable_attributes(module))
if vm_service and disk:
if vm_service and disk and state != 'attached':
# If the VM don't exist in VMs disks, but still it's found it means it was found
# for template with same name as VM, so we should force create the VM disk.
force_create = disk.id not in [a.disk.id for a in vm_service.disk_attachments_service().list() if a.disk]
Expand Down

0 comments on commit 9c01cf3

Please sign in to comment.