Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ovirt_vm_info: add current_cd #144

Merged
merged 5 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/ovirt_vm_info-add-current_cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- ovirt_vm_info - Add current_cd (https://github.com/oVirt/ovirt-ansible-collection/pull/144).
18 changes: 18 additions & 0 deletions plugins/modules/ovirt_vm_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
the virtual machine with the modifications that have already been performed but that will only come into
effect when the virtual machine is restarted. By default the value is set by engine."
type: bool
current_cd:
description:
- "If I(true) it will get from all virtual machines current attached cd."
type: bool
version_added: 1.2.0
extends_documentation_fragment: @NAMESPACE@.@NAME@.ovirt_info
'''

Expand Down Expand Up @@ -112,6 +117,7 @@ def main():
argument_spec = ovirt_info_full_argument_spec(
pattern=dict(default='', required=False),
all_content=dict(default=False, type='bool'),
current_cd=dict(default=False, type='bool'),
next_run=dict(default=None, type='bool'),
case_sensitive=dict(default=True, type='bool'),
max=dict(default=None, type='int'),
Expand Down Expand Up @@ -142,6 +148,18 @@ def main():
) for c in vms
],
)
for i, vm in enumerate(result['ovirt_vms']):
if module.params['current_cd']:
vm_service = vms_service.vm_service(vm['id'])
cdroms_service = vm_service.cdroms_service()
cdrom_device = cdroms_service.list()[0]
cdrom_service = cdroms_service.cdrom_service(cdrom_device.id)
result['ovirt_vms'][i]['current_cd'] = get_dict_of_struct(
struct=cdrom_service.get(current=True),
connection=connection,
)
else:
result['ovirt_vms'][i]['current_cd'] = {}
module.exit_json(changed=False, **result)
except Exception as e:
module.fail_json(msg=str(e), exception=traceback.format_exc())
Expand Down