On Wed, May 10, 2017 at 12:38 PM, Nathanaël Blanchet <blanchet@abes.fr> wrote:
Le 10/05/2017 à 10:29, Ondra Machacek a écrit :
Not sure I understand. You can use Ansible module to list VMs, you
can use ovirt_vms _facts[1] module.

For example to get only stopped VMs, you can use following:

- name: Get stopped VMs
  ovirt_vms_facts:
    auth:
      url: https://ovirt.example.com/ovirt-engine/api
      username: admin@internal
      password: password
      ca_file: /etc/pki/ovirt-engine/ca.pem
    pattern: "status = down"
I want a list of vms sorted by any possible attributes, i.e. sorted by datacenter or cluster, not only by status.
  • For example, ovirt_vms_facts doesn't allow to get the datacenter the vm belongs to , and the pattern filter doesn't return a list of vms as expected:

- hosts: localhost
  connection: local
  tasks:
  - name: Get stopped VMs
    ovirt_vms_facts:
      auth:
        url: https://acore.v100.abes.fr/ovirt-engine/api
        username: admin@internal
        password: ovirt123
        insecure: true
        pattern: name=centos* and cluster=west
  - debug:
      var: ovirt_vms
  - shell: echo "{{ ovirt_vms.name }}"


Ok, I understand, now.
You have few options here.
If you want for example only VMs from datacenter 'X', you can use following:

- hosts: localhost
  connection: local
  tasks:
  - name: Get VMs from datacenter X
    ovirt_vms_facts:

      pattern: datacenter=X
      auth:
        url: https://acore.v100.abes.fr/ovirt-engine/api
        username: admin@internal
        password: ovirt123
        insecure: true
  - debug:
      msg: "{{ ovirt_vms | map(attribute='name') | list }}"
 

How can I successfully display this list of vms like described here :
name description returned type sample
ovirt_vms List of dictionaries describing the VMs. VM attribues are mapped to dictionary keys, all VMs attributes can be found at following url: https://ovirt.example.com/ovirt-engine/api/model#types/vm. On success. list

  • About the python SDK:
list_vms.py could be what I expect, but vm.datacenter_name doesn't exist

Yes, because the 'data_center' parameter isn't part of the VM type. Take a look here[1],
you will find there all attributes the VM has. As you can see there is no 'datacenter', but
there is a 'cluster', but as said in documentation, it's just a reference to the cluster. That
means that it contains the ID of the cluster and the 'href' to the cluster, so you can get
the cluster object by following that reference using this code:

 vm_cluster = connection.follow_link(vm.cluster)
 print vm_cluster.name

 # Same for datacenter:
 vm_dc = connection.follow_link(vm_cluster.data_center)
 print vm_dc.name

What you need to understand is, what is the difference between the 'full'
object and the reference to the object. It's good to take a look at the XML
output of the API and learn to read the API specification documentation,
when working with oVirt Ansible and Python SDK.

[1] http://ovirt.github.io/ovirt-engine-api-model/master/#types/vm
 


On Wed, May 10, 2017 at 10:13 AM, Nathanaël Blanchet <blanchet@abes.fr> wrote:

Thanks, I knew this python script, but I believed it was possible to do the same with an ansible module.

That's mean we need several tools to do different tasks, it is not a very convergent way to proceed... but it is feasable.


Le 10/05/2017 à 07:56, Ondra Machacek a écrit :


On Tue, May 9, 2017 at 6:52 PM, Nathanaël Blanchet <blanchet@abes.fr> wrote:
Hello,

I didn't find anyway to easy list all my vms thanks to the ansible modules...
I tried the ovirt4.py script which is able to list the whole facts, so vms list, when the number of them is small in a test datacenter, but in a production datacenter, I get an issue:

  File "./ovirt4.py", line 262, in <module>
    main()
  File "./ovirt4.py", line 254, in main
    vm_name=args.host,
  File "./ovirt4.py", line 213, in get_data
    vms[name] = get_dict_of_struct(connection, vm)
  File "./ovirt4.py", line 185, in get_dict_of_struct
    (device.name, [ip.address for ip in device.ips]) for device in devices
  File "./ovirt4.py", line 185, in <genexpr>
    (device.name, [ip.address for ip in device.ips]) for device in devices
TypeError: 'NoneType' object is not iterable

This error was fixed already, try to download latest ovirt4.py file.

The other way is to use fatcs[1] module.

[1] http://docs.ansible.com/ansible/ovirt_vms_facts_module.html
 


What is the simpliest way to get this basic information with sdk4??? (with sdk3 : ovirt-shell -E "list vms")

 



--
Nathanaël Blanchet

Supervision réseau
Pôle Infrastrutures Informatiques
227 avenue Professeur-Jean-Louis-Viala
34193 MONTPELLIER CEDEX 5       
Tél. 33 (0)4 67 54 84 55
Fax  33 (0)4 67 54 84 14
blanchet@abes.fr

_______________________________________________
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


-- 
Nathanaël Blanchet

Supervision réseau
Pôle Infrastrutures Informatiques
227 avenue Professeur-Jean-Louis-Viala
34193 MONTPELLIER CEDEX 5 	
Tél. 33 (0)4 67 54 84 55
Fax  33 (0)4 67 54 84 14
blanchet@abes.fr 


-- 
Nathanaël Blanchet

Supervision réseau
Pôle Infrastrutures Informatiques
227 avenue Professeur-Jean-Louis-Viala
34193 MONTPELLIER CEDEX 5 	
Tél. 33 (0)4 67 54 84 55
Fax  33 (0)4 67 54 84 14
blanchet@abes.fr