[Users] [rhevm-api] Assign IP address to VM using Java SDK
Sven Kieske
S.Kieske at mittwald.de
Thu Feb 13 13:58:00 UTC 2014
Hi,
what cloud-init version and which OS do you run inside the vm?
background:
the ovirt-payload function generates an iso file from your cloud-init
data and attaches this to the vm. this feature is just working if you
got cloud-init >= 0.7.2 inside the vm, which is not available e.g. in
centos < 6.5 and ubuntu 12.04.
I don't know which data format the java sdk uses as default, so make
sure you are passing XML, not JSON.
HTH
Am 13.02.2014 14:39, schrieb Tejesh M:
> Hi All,
>
> Thanks alot.
>
> I have created one VM with minimal installation & installed cloud-init
> package. And, converted that VM into Template. Then executed the code given
> in http://lists.ovirt.org/pipermail/users/2014-February/021302.html , but
> no luck, the code is not setting root password.
>
> Also, there is no option to set *Hostname *for the VM.
>
>
>
> *Code:*
>
> /*********************Begin Customize VM*********************/
> // Generate the random password, using whatever mechanism you
> // prefer:
> String password = "cJql3P9XLQG4drCYVG/6Q/";
>
> // You need to know the name of the template, the cluster and
> // the VM you are going to create:
> String templateName = "rhel2_temp";
> String clusterName = "testCluster";
> String vmName = "myvm";
>
> // Prepare the data to create the VM from the template:
> org.ovirt.engine.sdk.entities.Template templateData = new
> Template();
> templateData.setName(templateName);
> org.ovirt.engine.sdk.entities.Cluster clusterData = new Cluster();
> clusterData.setName(clusterName);
> org.ovirt.engine.sdk.entities.VM vmDataForCreate = new VM();
> vmDataForCreate.setName(vmName);
> vmDataForCreate.setCluster(clusterData);
> vmDataForCreate.setTemplate(templateData);
>
> // Send the request to create the VM to the server:
> api.getVMs().add(vmDataForCreate);
> String state;
> // White till the VM is down (it will be locked for a while):
> for (;;) {
> state = api.getVMs().get(vmName).getStatus().getState();
> if ("down".equals(state)) {
> break;
> }
> Thread.sleep(1000);
> }
> System.out.println("System Status:"+state);
> // Populate parameters for the action to start the VM with
> cloud-init:
> org.ovirt.engine.sdk.entities.User userData = new User();
> userData.setUserName("root");
> userData.setPassword(password);
> Users usersData = new Users();
> usersData.getUsers().add(userData);
> CloudInit cloudData = new CloudInit();
> cloudData.setUsers(usersData);
>
> Initialization initData = new Initialization();
> initData.setCloudInit(cloudData);
> VM vmDataForStart = new VM();
> vmDataForStart.setInitialization(initData);
> Action actionData = new Action();
> actionData.setVm(vmDataForStart);
>
> // Send the request to start the VM to the server:
> api.getVMs().get(vmName).start(actionData);
> System.out.println("After :
> "+api.getVMs().get(vmName).getStatus());
> /*********************End Customize VM*********************/
>
>
>
> Thanks & Regards,
> Tejesh
>
>
>
> On Thu, Feb 13, 2014 at 2:26 PM, Juan Hernandez <jhernand at redhat.com> wrote:
>
>> On 02/13/2014 09:29 AM, Shahar Havivi wrote:
>>> On 13.02.14 00:59, Oved Ourfalli wrote:
>>>>
>>>>
>>>> ----- Original Message -----
>>>>> From: "Shahar Havivi" <shaharh at redhat.com>
>>>>> To: users at ovirt.org
>>>>> Cc: "Juan Antonio Hernandez Fernandez" <jhernand at redhat.com>,
>> rhevm-api at lists.fedorahosted.org, "Tejesh M"
>>>>> <tejeshmk at gmail.com>
>>>>> Sent: Wednesday, February 12, 2014 11:22:20 PM
>>>>> Subject: Re: [Users] [rhevm-api] Assign IP address to VM using Java SDK
>>>>>
>>>>> On 12.02.14 22:55, Itamar Heim wrote:
>>>>>> On 02/12/2014 03:14 PM, Tejesh M wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> Can anyone share sample code on how to assign IP address to guest os
>> &
>>>>>>> changing the root password while creating VM from Template using
>> Java SDK?
>>>>> Hi Tejesh,
>>>>> You should start here:
>>>>> http://www.ovirt.org/Api
>>>>> This link will explain the basics for fetching VM via the API using
>> HTTP via
>>>>> curl command line.
>>>>>
>>>>> Every VM have a collection of networks and manipulating them can be
>> seeing
>>>>> here with the REST API examples:
>>>>> http://www.ovirt.org/Features/Design/Network/SetupNetworks#REST
>>>>> the section for you is "Attaching a network to a NIC" under the REST
>>>>> category.
>>>>>
>>>>> Shahar Havivi.
>>>>>
>>>>
>>>> Actually it looks like Tejesh is referring to the Guests and not the
>> hosts, so you can use cloud-init in order to do that.
>>>> See more in "http://www.ovirt.org/Features/Cloud-Init_Integration".
>>>> If the VM's operating system is defined as some kind of Linux, then
>> you'll be able to set some stuff using cloud-init, either via the Run-Once
>> Dialog, or in the regular VM properties dialog.
>>>>
>>>> Omer - we have REST API support for cloud-init, right?
>>> Yes, more on that can be found here:
>>> http://www.ovirt.org/Features/vm-init-persistent
>>>>
>>
>> Tajesh, you have a detailed example of how to set the password in the
>> following message:
>>
>> http://lists.ovirt.org/pipermail/users/2014-February/021302.html
>>
>> Setting the IP address is similar.
>>
>> --
>> 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.
>>
>
>
>
>
>
> _______________________________________________
> Users mailing list
> Users at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/users
>
--
Mit freundlichen Grüßen / Regards
Sven Kieske
Systemadministrator
Mittwald CM Service GmbH & Co. KG
Königsberger Straße 6
32339 Espelkamp
T: +49-5772-293-100
F: +49-5772-293-333
https://www.mittwald.de
Geschäftsführer: Robert Meyer
St.Nr.: 331/5721/1033, USt-IdNr.: DE814773217, HRA 6640, AG Bad Oeynhausen
Komplementärin: Robert Meyer Verwaltungs GmbH, HRB 13260, AG Bad Oeynhausen
More information about the Users
mailing list