<div dir="ltr"><div><div><div><div><div><div>Hi All,<br><br></div>Thanks alot. <br><br></div>I have created one VM with minimal installation & installed cloud-init package. And, converted that VM into Template. Then executed the code given in <a href="http://lists.ovirt.org/pipermail/users/2014-February/021302.html">http://lists.ovirt.org/pipermail/users/2014-February/021302.html</a> , but no luck, the code is not setting root password.<br>
<br></div>Also, there is no option to set <b>Hostname </b>for the VM.<br><br><br></div><br></div><div><u><b>Code:</b></u><br><br> /*********************Begin Customize VM*********************/<br> // Generate the random password, using whatever mechanism you<br>
// prefer:<br> String password = "cJql3P9XLQG4drCYVG/6Q/";<br><br> // You need to know the name of the template, the cluster and<br> // the VM you are going to create:<br> String templateName = "rhel2_temp";<br>
String clusterName = "testCluster";<br> String vmName = "myvm";<br><br> // Prepare the data to create the VM from the template:<br> org.ovirt.engine.sdk.entities.Template templateData = new Template();<br>
templateData.setName(templateName);<br> org.ovirt.engine.sdk.entities.Cluster clusterData = new Cluster();<br> clusterData.setName(clusterName);<br> org.ovirt.engine.sdk.entities.VM vmDataForCreate = new VM();<br>
vmDataForCreate.setName(vmName);<br> vmDataForCreate.setCluster(clusterData);<br> vmDataForCreate.setTemplate(templateData);<br><br> // Send the request to create the VM to the server:<br>
api.getVMs().add(vmDataForCreate);<br> String state;<br> // White till the VM is down (it will be locked for a while):<br> for (;;) {<br> state = api.getVMs().get(vmName).getStatus().getState();<br>
if ("down".equals(state)) {<br> break;<br> }<br> Thread.sleep(1000);<br> }<br> System.out.println("System Status:"+state);<br> // Populate parameters for the action to start the VM with cloud-init:<br>
org.ovirt.engine.sdk.entities.User userData = new User();<br> userData.setUserName("root");<br> userData.setPassword(password);<br> Users usersData = new Users();<br> usersData.getUsers().add(userData);<br>
CloudInit cloudData = new CloudInit();<br> cloudData.setUsers(usersData);<br> <br> Initialization initData = new Initialization();<br> initData.setCloudInit(cloudData);<br> VM vmDataForStart = new VM();<br>
vmDataForStart.setInitialization(initData);<br> Action actionData = new Action();<br> actionData.setVm(vmDataForStart);<br><br> // Send the request to start the VM to the server:<br> api.getVMs().get(vmName).start(actionData);<br>
System.out.println("After : "+api.getVMs().get(vmName).getStatus());<br> /*********************End Customize VM*********************/ <br> <br><br><br></div>Thanks & Regards,<br></div>
Tejesh<br><div><div><div><br></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Feb 13, 2014 at 2:26 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">On 02/13/2014 09:29 AM, Shahar Havivi wrote:<br>
> On 13.02.14 00:59, Oved Ourfalli wrote:<br>
>><br>
>><br>
>> ----- Original Message -----<br>
>>> From: "Shahar Havivi" <<a href="mailto:shaharh@redhat.com">shaharh@redhat.com</a>><br>
>>> To: <a href="mailto:users@ovirt.org">users@ovirt.org</a><br>
>>> Cc: "Juan Antonio Hernandez Fernandez" <<a href="mailto:jhernand@redhat.com">jhernand@redhat.com</a>>, <a href="mailto:rhevm-api@lists.fedorahosted.org">rhevm-api@lists.fedorahosted.org</a>, "Tejesh M"<br>
>>> <<a href="mailto:tejeshmk@gmail.com">tejeshmk@gmail.com</a>><br>
>>> Sent: Wednesday, February 12, 2014 11:22:20 PM<br>
>>> Subject: Re: [Users] [rhevm-api] Assign IP address to VM using Java SDK<br>
>>><br>
>>> On 12.02.14 22:55, Itamar Heim wrote:<br>
>>>> On 02/12/2014 03:14 PM, Tejesh M wrote:<br>
>>>>> Hi,<br>
>>>>><br>
>>>>> Can anyone share sample code on how to assign IP address to guest os &<br>
>>>>> changing the root password while creating VM from Template using Java SDK?<br>
>>> Hi Tejesh,<br>
>>> You should start here:<br>
>>> <a href="http://www.ovirt.org/Api" target="_blank">http://www.ovirt.org/Api</a><br>
>>> This link will explain the basics for fetching VM via the API using HTTP via<br>
>>> curl command line.<br>
>>><br>
>>> Every VM have a collection of networks and manipulating them can be seeing<br>
>>> here with the REST API examples:<br>
>>> <a href="http://www.ovirt.org/Features/Design/Network/SetupNetworks#REST" target="_blank">http://www.ovirt.org/Features/Design/Network/SetupNetworks#REST</a><br>
>>> the section for you is "Attaching a network to a NIC" under the REST<br>
>>> category.<br>
>>><br>
>>> Shahar Havivi.<br>
>>><br>
>><br>
>> 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.<br>
>> See more in "<a href="http://www.ovirt.org/Features/Cloud-Init_Integration" target="_blank">http://www.ovirt.org/Features/Cloud-Init_Integration</a>".<br>
>> 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.<br>
>><br>
>> Omer - we have REST API support for cloud-init, right?<br>
> Yes, more on that can be found here:<br>
> <a href="http://www.ovirt.org/Features/vm-init-persistent" target="_blank">http://www.ovirt.org/Features/vm-init-persistent</a><br>
>><br>
<br>
Tajesh, you have a detailed example of how to set the password in the<br>
following message:<br>
<br>
<a href="http://lists.ovirt.org/pipermail/users/2014-February/021302.html" target="_blank">http://lists.ovirt.org/pipermail/users/2014-February/021302.html</a><br>
<br>
Setting the IP address is similar.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<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><br clear="all"><br>-- <br><div>Thanks & Regards</div>
<div>Tejesh</div>
</div>