<p dir="ltr">I'm using rhevm 3.3 java sdk,which doesn't have NetworkConfiguration class. </p>
<div class="gmail_quote">On 20 Feb 2014 20:58, "Juan Hernandez" <<a href="mailto:jhernand@redhat.com">jhernand@redhat.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 02/20/2014 10:40 AM, Tejesh M wrote:<br>
> I wrote this code to assign IP address to VM interface eth0, but not<br>
> luck. Also, have attached debug log.<br>
><br>
<br>
I'm attaching a complete examaple of how to do this. However, I think<br>
that setting the DNS information doesn't currently work. Apparently<br>
cloud-init is expecting a network configuration containing the DNS<br>
settings inside the network interface, something like this:<br>
<br>
iface eth0 inet static<br>
dns-nameservers 1.1.2.2 1.2.3.4<br>
dns-search <a href="http://google.com" target="_blank">google.com</a><br>
address 192.168.1.102<br>
netmask 255.255.0.0<br>
gateway 192.168.2.1<br>
auto eth0<br>
<br>
But we actually pass them outside of the network interface, like this:<br>
<br>
dns-nameservers 1.1.2.2 1.2.3.4<br>
dns-search <a href="http://google.com" target="_blank">google.com</a><br>
iface eth0 inet static<br>
address 192.168.1.102<br>
netmask 255.255.0.0<br>
gateway 192.168.2.1<br>
auto eth0<br>
<br>
I need to check it.<br>
<br>
> _*Java Code:*_<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>
><br>
><br>
> cloudData.setUsers(usersData);<br>
> Host hostData = new Host();<br>
> hostData.setAddress(vmName);<br>
> cloudData.setHost(hostData);<br>
><br>
> org.ovirt.engine.sdk.entities.CloudInit.Network<br>
> networkConfiguration=new org.ovirt.engine.sdk.entities.CloudInit.Network();<br>
><br>
> DNS dns = new DNS();<br>
> dns.setServers(createServersList("1.1.2.2", "1.2.3.4"));<br>
> dns.setSearchDomains(createServersList("<a href="http://google.com" target="_blank">google.com</a><br>
> <<a href="http://google.com" target="_blank">http://google.com</a>>"));<br>
> networkConfiguration.setDns(dns);<br>
> networkConfiguration.setNics(new Nics());<br>
><br>
> Nics nics = networkConfiguration.getNics();<br>
> nics.getNics().add(createNic("eth0", "STATIC",<br>
> createNetwork("192.168.1.102", "255.255.0.0", "192.168.2.1"), true));<br>
><br>
> networkConfiguration.setNics(nics);<br>
><br>
> cloudData.setNetwork(networkConfiguration);<br>
><br>
> Initialization initData = new Initialization();<br>
><br>
> initData.setCloudInit(cloudData);<br>
><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>
><br>
><br>
><br>
><br>
><br>
><br>
> On Thu, Feb 20, 2014 at 1:39 PM, Moti Asayag <<a href="mailto:masayag@redhat.com">masayag@redhat.com</a><br>
> <mailto:<a href="mailto:masayag@redhat.com">masayag@redhat.com</a>>> wrote:<br>
><br>
><br>
><br>
> ----- Original Message -----<br>
> > From: "Tejesh M" <<a href="mailto:tejeshmk@gmail.com">tejeshmk@gmail.com</a> <mailto:<a href="mailto:tejeshmk@gmail.com">tejeshmk@gmail.com</a>>><br>
> > To: "Moti Asayag" <<a href="mailto:masayag@redhat.com">masayag@redhat.com</a> <mailto:<a href="mailto:masayag@redhat.com">masayag@redhat.com</a>>><br>
> > Cc: "users@oVirt.org" <<a href="mailto:users@ovirt.org">users@ovirt.org</a> <mailto:<a href="mailto:users@ovirt.org">users@ovirt.org</a>>><br>
> > Sent: Thursday, February 20, 2014 8:52:52 AM<br>
> > Subject: Re: [Users] Fwd: Sample code for setting NIC - CloudInit<br>
> ><br>
> > I'm not getting below class:<br>
> ><br>
> > import org.ovirt.engine.sdk.entities.*NetworkConfiguration*;<br>
><br>
> Which version of ovirt-engine-sdk-java are you using ?<br>
><br>
> I used ovirt-engine-sdk-java-3.4.0.1-1, added to my project's pom.xml:<br>
><br>
> <dependency><br>
> <groupId>org.ovirt.engine.sdk</groupId><br>
> <artifactId>ovirt-engine-sdk-java</artifactId><br>
> <version>3.4.0.1-1</version><br>
> <type>jar</type><br>
> <scope>compile</scope><br>
> </dependency><br>
><br>
> ><br>
> ><br>
> > On Thu, Feb 20, 2014 at 4:11 AM, Moti Asayag <<a href="mailto:masayag@redhat.com">masayag@redhat.com</a><br>
> <mailto:<a href="mailto:masayag@redhat.com">masayag@redhat.com</a>>> wrote:<br>
> ><br>
> > ><br>
> > ><br>
> > > ----- Original Message -----<br>
> > > > From: "Tejesh M" <<a href="mailto:tejeshmk@gmail.com">tejeshmk@gmail.com</a> <mailto:<a href="mailto:tejeshmk@gmail.com">tejeshmk@gmail.com</a>>><br>
> > > > To: "users@oVirt.org" <<a href="mailto:users@ovirt.org">users@ovirt.org</a> <mailto:<a href="mailto:users@ovirt.org">users@ovirt.org</a>>><br>
> > > > Sent: Wednesday, February 19, 2014 3:24:40 PM<br>
> > > > Subject: [Users] Fwd: Sample code for setting NIC - CloudInit<br>
> > > ><br>
> > > > Hi,<br>
> > > ><br>
> > > > Can someone share me sample java code for assigning IP address<br>
> for VM on<br>
> > > eth0<br>
> > > > through Java SDK via CloudInit ?<br>
> > > ><br>
> > ><br>
> > > Hi Tejesh,<br>
> > ><br>
> > > I've attached a sample code that sends the required request (as<br>
> the output<br>
> > > is demonstrated in debug mode).<br>
> > > Note that the code is jdk-7 compliant.<br>
> > > I haven't configured cloud-init and haven't tested it end-to-end.<br>
> > > Please try to test it on your environment and provide a feedback<br>
> for it.<br>
> > ><br>
> > > Thanks,<br>
> > > Moti<br>
> > ><br>
> > > > Something Like this but in Java:<br>
> > > > <network_configuration><br>
> > > > <nics><br>
> > > > <nic><br>
> > > > <name>eth0</name><br>
> > > > <boot_protocol>STATIC</boot_protocol><br>
> > > > <network><br>
> > > > <ip address="192.168.2.11" netmask="255.255.0.0"<br>
> > > > gateway="192.168.2.1" /><br>
> > > > </network><br>
> > > > <on_boot>true</on_boot><br>
> > > > </nic><br>
> > > > <nic><br>
> > > > <name>eth1</name><br>
> > > > <boot_protocol>DHCP</boot_protocol><br>
> > > > </nic><br>
> > > > <nic><br>
> > > > <name>eth2</name><br>
> > > > <boot_protocol>NONE</boot_protocol><br>
> > > > <on_boot>true</on_boot><br>
> > > > </nic><br>
> > > > </nics><br>
> > > > <dns><br>
> > > > <servers><br>
> > > > <host><br>
> > > > <address>1.1.2.2</address><br>
> > > > </host><br>
> > > > <host><br>
> > > > <address>1.2.3.4</address><br>
> > > > </host><br>
> > > > </servers><br>
> > > > <search_domains><br>
> > > > <host><br>
> > > > <address>qa.lab</address><br>
> > > > </host><br>
> > > > <host><br>
> > > > <address> <a href="http://google.com" target="_blank">google.com</a> <<a href="http://google.com" target="_blank">http://google.com</a>> </address><br>
> > > > </host><br>
> > > > </search_domains><br>
> > > > </dns><br>
> > > > </network_configuration><br>
<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>
</blockquote></div>