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