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

Update ovirt_vm_info.py - enable tags #59

Closed

Conversation

lunarnexus
Copy link

Currently, tags dict is empty when retrieving info on VMs. This enables the vms_service.list() method to follow the tags link and return the tag data.

update module to follow tags link, enables a list of tags attached to the VM in the info retrieved
@ovirt-infra
Copy link

Hello contributor, thanks for submitting a PR for this project!

I am the bot who triggers "standard-CI" builds for this project.
As a security measure, I will not run automated tests on PRs that are not from white-listed contributors.

In order to allow automated tests to run, please ask one of the project maintainers to review the code and then do one of the following:

  1. Type ci test please on this PR to trigger automated tests for it.
  2. Type ci add to whitelist on this PR to trigger automated tests for it and also add you to the contributor white-list so that your future PRs will be tested automatically. ( keep in mind this list might be overwritten if the job XML is refreshed, for permanent whitelisting, please follow ovirt dynamic plugin improvements #3 option )
  3. If you are planning to contribute to more than one project, maybe it's better to ask them to add you to the project organization, so you'll be able to run tests for all the organization's projects.

@mnecas
Copy link
Member

mnecas commented Jun 15, 2020

Hi @lunarnexus,
you can gather any data from nested attributes by the following example

    - ovirt_vm_info:
        auth: "{{ ovirt_auth }}"
        pattern: name=test
        fetch_nested: True
        nested_attributes: 
          - "name"
          - "vm"
          - "description"

To explain all info modules have the same logic around gathering info.
fetch_nested will gather IDs of nested facts
nested_attributes list of attributes that should be gathered with the ID like name, description, etc.

@lunarnexus
Copy link
Author

That works perfect, thanks!

I'd like to add an example to the ansible docs page (https://docs.ansible.com/ansible/latest/modules/ovirt_vm_info_module.html) but I'm unsure how.

This is the code I used to get the tag info:

- name: "Get VM Info"
  ovirt_vm_info:
    auth: "{{ ovirt_auth }}"
    pattern: name=hostname
    fetch_nested: true
    nested_attributes:
      - "tags"
      - "name"
  register: vm_result

@lunarnexus lunarnexus closed this Jun 15, 2020
@mnecas
Copy link
Member

mnecas commented Jun 15, 2020

I think you don't need to specify the "tags" in nested_attributes.
An example can be added to this string.

EXAMPLES = '''
# Examples don't contain auth parameter for simplicity,
# look at ovirt_auth module to see how to reuse authentication:
# Gather information about all VMs which names start with C(centos) and
# belong to cluster C(west):
- ovirt_vm_info:
pattern: name=centos* and cluster=west
register: result
- debug:
msg: "{{ result.ovirt_vms }}"
# Gather info about next run configuration of virtual machine named myvm
- ovirt_vm_info:
pattern: name=myvm
next_run: true
register: result
- debug:
msg: "{{ result.ovirt_vms[0] }}"
'''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants