
Hi, I would like to create the following functions using the ovirt api 1. Rebuild VM 2. Restore the screenthots of one vm to another vm 3. Display cpu,network etc usages I couldn't find out any direct api method to do the above, Is it possible to do these operations using api ? If anyone knows it please help me to sort out it. -- Regards Shanil

On 08/20/2014 12:42 PM, Shanil S wrote:
Hi,
I would like to create the following functions using the ovirt api
1. Rebuild VM
What do you exactly mean by "rebuild vm"?
2. Restore the screenthots of one vm to another vm
What you can do is create a new VM from an existing snapshot, something like this: #!/bin/sh -ex url="https://ovirt.example.com/ovirt-engine/api" user="admin@internal" password="******" curl \ --verbose \ --insecure \ --request POST \ --header "Accept: application/xml" \ --header "Content-Type: application/xml" \ --user "${user}:${password}" \ --data " <vm> <name>myclone</name> <cluster id='00000001-0001-0001-0001-000000000171'/> <snapshots> <snapshot id='f09a98fd-2c7e-40eb-a9ae-6b7f86412bb0'/> </snapshots> </vm> " \ "${url}/vms" You need to modify that script with your URL, user name, password, cluster and snapshot id.
3. Display cpu,network etc usages
The statistics are available in the "statistics" sub-resource. For example, if you want to get the statistics of a host you can do the following: #!/bin/sh -ex url="https://ovirt.example.com/ovirt-engine/api" user="admin@internal" password="******" curl \ --verbose \ --insecure \ --request GET \ --header "Accept: application/xml" \ --user "${user}:${password}" \ "${url}/hosts/40cc4c33-2560-4516-b028-1d59638139c3/statistics" There you will find different statistics, like "memory.total", "memory.used", etc. Take a look. Once you know what statistic you want you can get its details like this: curl \ --verbose \ --insecure \ --request GET \ --header "Accept: application/xml" \ --user "${user}:${password}" \ "${url}/hosts/40cc4c33-2560-4516-b028-1d59638139c3/statistics/7816602b-c05c-3db7-a4da-3769f7ad8896" This can be cumbersome to do with a shell script, so you may want to use the Python or Java SDKs, or just use directly the ovirt-shell: $ ovirt-shell --insecure URL: https://ovirt.example.com/ovirt-engine/api Username: admin@internal Password: ****** [oVirt shell (connected)]# show statistic memory.total --host-identifier myhost id : 7816602b-c05c-3db7-a4da-3769f7ad8896 name : memory.total description : Total memory host-id : 40cc4c33-2560-4516-b028-1d59638139c3 type : GAUGE unit : BYTES values-type : INTEGER values-value-datum: 2099249152
I couldn't find out any direct api method to do the above, Is it possible to do these operations using api ? If anyone knows it please help me to sort out it.
-- Regards Shanil
-- Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta 3ºD, 28016 Madrid, Spain Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.

Hi Juan, Thanks for your replies.. Regarding the rebuild VM, Is that any method to reinstall the os on the VM without remove it or create a new one? -- Regards Shanil On Thu, Aug 21, 2014 at 4:55 PM, Juan Hernandez <jhernand@redhat.com> wrote:
On 08/20/2014 12:42 PM, Shanil S wrote:
Hi,
I would like to create the following functions using the ovirt api
1. Rebuild VM
What do you exactly mean by "rebuild vm"?
2. Restore the screenthots of one vm to another vm
What you can do is create a new VM from an existing snapshot, something like this:
#!/bin/sh -ex
url="https://ovirt.example.com/ovirt-engine/api" user="admin@internal" password="******"
curl \ --verbose \ --insecure \ --request POST \ --header "Accept: application/xml" \ --header "Content-Type: application/xml" \ --user "${user}:${password}" \ --data " <vm> <name>myclone</name> <cluster id='00000001-0001-0001-0001-000000000171'/> <snapshots> <snapshot id='f09a98fd-2c7e-40eb-a9ae-6b7f86412bb0'/> </snapshots> </vm> " \ "${url}/vms"
You need to modify that script with your URL, user name, password, cluster and snapshot id.
3. Display cpu,network etc usages
The statistics are available in the "statistics" sub-resource. For example, if you want to get the statistics of a host you can do the following:
#!/bin/sh -ex
url="https://ovirt.example.com/ovirt-engine/api" user="admin@internal" password="******"
curl \ --verbose \ --insecure \ --request GET \ --header "Accept: application/xml" \ --user "${user}:${password}" \ "${url}/hosts/40cc4c33-2560-4516-b028-1d59638139c3/statistics"
There you will find different statistics, like "memory.total", "memory.used", etc. Take a look. Once you know what statistic you want you can get its details like this:
curl \ --verbose \ --insecure \ --request GET \ --header "Accept: application/xml" \ --user "${user}:${password}" \
"${url}/hosts/40cc4c33-2560-4516-b028-1d59638139c3/statistics/7816602b-c05c-3db7-a4da-3769f7ad8896"
This can be cumbersome to do with a shell script, so you may want to use the Python or Java SDKs, or just use directly the ovirt-shell:
$ ovirt-shell --insecure URL: https://ovirt.example.com/ovirt-engine/api Username: admin@internal Password: ****** [oVirt shell (connected)]# show statistic memory.total --host-identifier myhost id : 7816602b-c05c-3db7-a4da-3769f7ad8896 name : memory.total description : Total memory host-id : 40cc4c33-2560-4516-b028-1d59638139c3 type : GAUGE unit : BYTES values-type : INTEGER values-value-datum: 2099249152
I couldn't find out any direct api method to do the above, Is it possible to do these operations using api ? If anyone knows it please help me to sort out it.
-- Regards Shanil
-- Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta 3ºD, 28016 Madrid, Spain Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.

On 08/22/2014 05:58 AM, Shanil S wrote:
Hi Juan,
Thanks for your replies..
Regarding the rebuild VM, Is that any method to reinstall the os on the VM without remove it or create a new one?
This is the same that with a physical machine: it all depends on the facilities that you have available to boot the machine to the re-install process. You can, for example, set you VM to boot from the network, using PXE, and use your favorite system (manual setup of TFTP, cobbler, foreman, etc) to re-install the OS. There are tons of options for this. However, unless you have data in the VM that you want to preserve, it may be easier and faster (specially if you are using templates) to remove it and create a new one.
-- Regards Shanil
On Thu, Aug 21, 2014 at 4:55 PM, Juan Hernandez <jhernand@redhat.com <mailto:jhernand@redhat.com>> wrote:
On 08/20/2014 12:42 PM, Shanil S wrote: > Hi, > > > I would like to create the following functions using the ovirt api > > 1. Rebuild VM
What do you exactly mean by "rebuild vm"?
> 2. Restore the screenthots of one vm to another vm
What you can do is create a new VM from an existing snapshot, something like this:
#!/bin/sh -ex
url="https://ovirt.example.com/ovirt-engine/api" user="admin@internal" password="******"
curl \ --verbose \ --insecure \ --request POST \ --header "Accept: application/xml" \ --header "Content-Type: application/xml" \ --user "${user}:${password}" \ --data " <vm> <name>myclone</name> <cluster id='00000001-0001-0001-0001-000000000171'/> <snapshots> <snapshot id='f09a98fd-2c7e-40eb-a9ae-6b7f86412bb0'/> </snapshots> </vm> " \ "${url}/vms"
You need to modify that script with your URL, user name, password, cluster and snapshot id.
> 3. Display cpu,network etc usages >
The statistics are available in the "statistics" sub-resource. For example, if you want to get the statistics of a host you can do the following:
#!/bin/sh -ex
url="https://ovirt.example.com/ovirt-engine/api" user="admin@internal" password="******"
curl \ --verbose \ --insecure \ --request GET \ --header "Accept: application/xml" \ --user "${user}:${password}" \ "${url}/hosts/40cc4c33-2560-4516-b028-1d59638139c3/statistics"
There you will find different statistics, like "memory.total", "memory.used", etc. Take a look. Once you know what statistic you want you can get its details like this:
curl \ --verbose \ --insecure \ --request GET \ --header "Accept: application/xml" \ --user "${user}:${password}" \ "${url}/hosts/40cc4c33-2560-4516-b028-1d59638139c3/statistics/7816602b-c05c-3db7-a4da-3769f7ad8896"
This can be cumbersome to do with a shell script, so you may want to use the Python or Java SDKs, or just use directly the ovirt-shell:
$ ovirt-shell --insecure URL: https://ovirt.example.com/ovirt-engine/api Username: admin@internal Password: ****** [oVirt shell (connected)]# show statistic memory.total --host-identifier myhost id : 7816602b-c05c-3db7-a4da-3769f7ad8896 name : memory.total description : Total memory host-id : 40cc4c33-2560-4516-b028-1d59638139c3 type : GAUGE unit : BYTES values-type : INTEGER values-value-datum: 2099249152
> I couldn't find out any direct api method to do the above, Is it > possible to do these operations using api ? If anyone knows it please > help me to sort out it. > > > > -- > Regards > Shanil
-- Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta 3ºD, 28016 Madrid, Spain Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.
participants (2)
-
Juan Hernandez
-
Shanil S