[ovirt-users] Error while using REST API with Ovirt

Juan Hernandez jhernand at redhat.com
Thu Sep 18 13:00:18 UTC 2014


On 09/18/2014 01:39 PM, Chandrahasa S wrote:
> Dear Juan / All,
> 
> Thanks for reply.
> 
>  I tried to give the hostname with the tag mentioned "host_name". Its
> working.
> 
>         So below are the issues still remaining:
> 
>         1) The issue of internal server error still persits (rhev
> manager showing issues) even after following the advice of the expert
> and doing the initialization part just once(giving ip and            
>  hostname) after creating the vm.
> 

Actually this is a bug:

https://bugzilla.redhat.com/1144005

The reason is that when you use an incorrect boot protocol we end up
storing null in the corresponding place in the database, and later we
use the value without checking it, which triggers a null pointer exception.

The right value for the boot protocol is "static", not "STATIC_IP". The
"STATIC_IP" value is what we use in the backend and in the database, but
in the RESTAPI it is "static".

To workaround this issue you can delete the VMs and create them again
with the correct boot protocol.

If you don't want to create the VMs again you can fix the database
manually like this:

# su - postgres
# psql
postgres=# \c engine
engine=# update vm_init set networks = replace(networks, '"bootProtocol"
: null', '"bootProtocol" : "STATIC_IP"');

>         2) Please confirm if this is the case that  we can do
> initialization part only once on a particular vm , then we can
> reconfigure the network (ip, subnet, gateway etc)
>             or not for that vm.
> 

I'm reasonably sure that you can run initialization only once per VM,
but Shahar can confirm this better than me.

>         3) For Windows guest we are still unable to provide ip details
> and hostname using sysprep/payload.
> 

I'm not familiar with Sysprep. Can you provide an example of the code
that you are using for that?

> Error attached.
> 
> 
> 
> Regards,
> Chandrahasa S
> 
> 
> 
> From:        Juan Hernandez <jhernand at redhat.com>
> To:        Chandrahasa S <chandrahasa.s at tcs.com>, users at ovirt.org
> Cc:        Agarwal Ruchita <agarwal.ruchita at tcs.com>
> Date:        09/18/2014 03:35 PM
> Subject:        Re: [ovirt-users] Error while using REST API with Ovirt
> ------------------------------------------------------------------------
> 
> 
> 
> On 09/18/2014 08:18 AM, Chandrahasa S wrote:
>> Dear Experts.
>>
>> We are Integrating our internal cloud portal with  Ovirt / RHEVM version
>> 3.4.
>>
>> We are integrating our internal cloud with Ovirt / RHEVM. VM template
>> created using cloud init.
>>
>> Through REST API Nippet while codes passes command to template ( with
>> cloud init) IP, HOSTNAME, We are able to set IP and Hostname to VM
>> through code.
>>
>> But post this Manager getting handed. Error code is attached.
>>
>> Need your help please.
>>
> 
> If I understand correctly you already created a template with the cloud
> init configuration, then you created a VM from that template, and you
> want to modify it and start it. In order to update the VM you need to
> issue a PUT request, and the tag name for the host is "host_name":
> 
>    String updateXml =
>          "<?xml version=\"1.0\"?>"
>        + "<vm>"
>        +   "<initialization>"
>        +     "<host_name>meghaasadmin.ultimatixuat.net</host_name>"
>        +     "<regenerate_ssh_keys>false</regenerate_ssh_keys>"
>        +     "<nic_configurations>"
>        +       "<nic_configuration>"
>        +         "<name>eth0</name>"
>        +         "<ip address=\"1.1.1.1\" netmask=\"255.255.255.0\"
> gateway=\"13.3.3.3\"/>"
>        +         "<boot_protocol>static</boot_protocol>"
>        +         "<on_boot>true</on_boot>"
>        +       "</nic_configuration>"
>        +     "</nic_configurations>"
>        +   "</initialization>"
>        + "</vm>";
>    StringEntity updateEntity = new StringEntity(updateXml);
>    HttpPut updateRequest = new HttpPut(apiUrl + "/vms/" + vmId);
>    updateRequest.setHeader("Content-Type", "application/xml");
>    updateRequest.setHeader("Accept", "application/xml");
>    updateRequest.setEntity(updateEntity);
>    HttpResponse updateResponse = client.execute(updateRequest);
> 
> Then, after the update, you need to start the VM and it will use that
> configuration:
> 
>    String startXml =
>          "<?xml version=\"1.0\"?>"
>        + "<action/>";
>    StringEntity startEntity = new StringEntity(startXml);
>    HttpPost startRequest = new HttpPost(apiUrl + "/vms/" + vmId +
> "/start");
>    startRequest.setEntity(startEntity);
>    startRequest.setHeader("Content-Type", "application/xml");
>    startRequest.setHeader("Accept", "application/xml");
>    HttpResponse startResponse = client.execute(startRequest);
> 
> Some advices:
> 
> * Check the XML schema for the structure of the XML documents:
> 
>  https://rhevmanager/api?schema
> 
> * When sending requests to the RESTAPI makes sure to always explicitly
> add the Content-Type and Accept headers:
> 
>  yourRequest.setHeader("Content-Type", "application/xml");
>  yourRequest.setHeader("Accept", "application/xml");
> 
> * Take into account that the initialization with cloud-init will only be
> executed the first time you start the VM, so in your tests you will need
> to remove the VM and create it again.
> 
> * If you are planning to do complex things you may find it helpful the
> Java SDK:
> 
>  http://www.ovirt.org/Java-sdk
> 

-- 
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.



More information about the Users mailing list