On 08/22/2014 06:35 AM, Shanil S wrote:
Hi,
VM rebuild means...Rebuild the VM with the same existing
configuration...just erase the Vdisk and install again (like Fresh
install).
We want to rebuild the VM with the same existing OS template...also it
will be good if user can select other OS template also for the rebuild
purpose...
With CD_ISO it require the manual installation...we don't want the
manual installation...we looking for a way to rebuild the VM with OS
templates....
Is there any API method to achieve this ??
The usual process to do this is the following:
1. Manually, using the GUI, you create a VM and install the OS.
2. Manually seal the VM for use as a template. The idea is to remove
from the VM any configuration that may create a conflict when multiple
VMs are created from the template. There are different ways to do this,
depending on the OS that you are using. Here you can find some
documentation:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Virtuali...
3. Manually shut it down and create a template from it.
4. Manually remove the VM (you can keep it, but it isn't needed).
All these steps are usually done manually, as it isn't usually worth
automating them, but if you wish you can also do them with the API.
Once you have the template you can create multiple VMs from it, and for
this you will probably use the API. For example, assuming that you know
the ids of the cluster and the template:
#!/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>mynewvm</name>
<cluster id='5f840556-81de-427d-8d30-a06cdb15b7f9'/>
<template id='f9eb10b8-6f94-469f-a8a6-660c41b103d7'/>
</vm>
" \
"${url}/vms"
Or you may want to use the Python SDK:
#!/usr/bin/python
import ovirtsdk.api
import ovirtsdk.xml
api = ovirtsdk.api.API(
url="https://ovirt.example.com/ovirt-engine/api",
username="admin@internal",
password="******",
insecure=True
)
cluster =
ovirtsdk.xml.params.Cluster(id="5f840556-81de-427d-8d30-a06cdb15b7f9")
template =
ovirtsdk.xml.params.Template(id="f9eb10b8-6f94-469f-a8a6-660c41b103d7")
vm = ovirtsdk.xml.params.VM()
vm.set_name("mynewvm")
vm.set_cluster(cluster)
vm.set_template(template)
api.vms.add(vm)
api.disconnect()
There is also a Java SDK, if you prefer it.
In this scenario you will usually want to change the host name or other
properties of the new VM. That you can do with cloud-init (for Linux) or
Sysprep (for Windows). That can also be automated with the api.
Regarding the statitics report, is there any API method to fetch the
monthly and weekly usages report ?, we are planning to create a usage
chart by using these values.
The RESTAPI doesn't provide this kind of accumulated statistics. I'd
suggest to explore the oVirt reports DWH and reports applications:
http://www.ovirt.org/Ovirt_DWH
http://www.ovirt.org/Ovirt_Reports
--
Regards
Shanil
On Fri, Aug 22, 2014 at 9:46 AM, OvirtAndKvm <oVirt(a)goproject.info
<mailto:oVirt@goproject.info>> wrote:
Do you mean like; attach a new OS install ISO CD to the VM, change
the VM's boot order to CD first, reboot the VM and boot up on the CD
and install the new OS, selecting to reformat over the old installed
OS ?
or am I miss understanding your question ?
At Friday, 22-08-2014 on 13:58 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?
--
Regards
Shanil
On Thu, Aug 21, 2014 at 4:55 PM, Juan Hernandez
<jhernand(a)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.