[Users] Fwd: Sample code for setting NIC - CloudInit

Juan Hernandez jhernand at redhat.com
Fri Feb 21 10:40:40 UTC 2014


On 02/20/2014 08:42 PM, Greg Padgett wrote:
> On 02/20/2014 02:26 PM, Juan Hernandez wrote:
>> On 02/20/2014 04:28 PM, Juan Hernandez wrote:
>>> On 02/20/2014 10:40 AM, Tejesh M wrote:
>>>> I wrote this code to assign IP address to VM interface eth0, but not
>>>> luck. Also, have attached debug log.
>>>>
>>>
>>> I'm attaching a complete examaple of how to do this. However, I think
>>> that setting the DNS information doesn't currently work. Apparently
>>> cloud-init is expecting a network configuration containing the DNS
>>> settings inside the network interface, something like this:
>>>
>>> iface eth0 inet static
>>>    dns-nameservers 1.1.2.2 1.2.3.4
>>>    dns-search google.com
>>>    address 192.168.1.102
>>>    netmask 255.255.0.0
>>>    gateway 192.168.2.1
>>> auto eth0
>>>
>>> But we actually pass them outside of the network interface, like this:
>>>
>>> dns-nameservers 1.1.2.2 1.2.3.4
>>> dns-search google.com
>>> iface eth0 inet static
>>>    address 192.168.1.102
>>>    netmask 255.255.0.0
>>>    gateway 192.168.2.1
>>> auto eth0
>>>
>>> I need to check it.
>>>
>>
>> I have modified the code that generates the cloud-init files to put the
>> DNS configuration inside the "iface" configuration, and then it works:
>>
>> http://gerrit.ovirt.org/24850
>>
>> So this is probably a bug, either in our side or in cloud-init itself.
>> Greg, Shahar, you know cloud-init better, what do you think?
>>

I opened the following bug to track it:

https://bugzilla.redhat.com/1067906

> 
> It looks like our bug.  Cloud-init wants to see a standard debian/ubuntu 
> style /etc/network/interfaces, and the documentation for that format 
> supports your change.  Thanks for posting the patch!
> 
>>>> _*Java Code:*_
>>>>            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);
>>>>            Host hostData = new Host();
>>>>            hostData.setAddress(vmName);
>>>>            cloudData.setHost(hostData);
>>>>
>>>>            org.ovirt.engine.sdk.entities.CloudInit.Network
>>>> networkConfiguration=new org.ovirt.engine.sdk.entities.CloudInit.Network();
>>>>
>>>>            DNS dns = new DNS();
>>>>            dns.setServers(createServersList("1.1.2.2", "1.2.3.4"));
>>>>            dns.setSearchDomains(createServersList("google.com
>>>> <http://google.com>"));
>>>>            networkConfiguration.setDns(dns);
>>>>            networkConfiguration.setNics(new Nics());
>>>>
>>>>            Nics nics = networkConfiguration.getNics();
>>>>            nics.getNics().add(createNic("eth0", "STATIC",
>>>> createNetwork("192.168.1.102", "255.255.0.0", "192.168.2.1"), true));
>>>>
>>>>            networkConfiguration.setNics(nics);
>>>>
>>>>            cloudData.setNetwork(networkConfiguration);
>>>>
>>>>            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);
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Thu, Feb 20, 2014 at 1:39 PM, Moti Asayag <masayag at redhat.com
>>>> <mailto:masayag at redhat.com>> wrote:
>>>>
>>>>
>>>>
>>>>      ----- Original Message -----
>>>>      > From: "Tejesh M" <tejeshmk at gmail.com <mailto:tejeshmk at gmail.com>>
>>>>      > To: "Moti Asayag" <masayag at redhat.com <mailto:masayag at redhat.com>>
>>>>      > Cc: "users at oVirt.org" <users at ovirt.org <mailto:users at ovirt.org>>
>>>>      > Sent: Thursday, February 20, 2014 8:52:52 AM
>>>>      > Subject: Re: [Users] Fwd: Sample code for setting NIC - CloudInit
>>>>      >
>>>>      > I'm not getting below class:
>>>>      >
>>>>      > import org.ovirt.engine.sdk.entities.*NetworkConfiguration*;
>>>>
>>>>      Which version of ovirt-engine-sdk-java are you using ?
>>>>
>>>>      I used ovirt-engine-sdk-java-3.4.0.1-1, added to my project's pom.xml:
>>>>
>>>>              <dependency>
>>>>                      <groupId>org.ovirt.engine.sdk</groupId>
>>>>                      <artifactId>ovirt-engine-sdk-java</artifactId>
>>>>                      <version>3.4.0.1-1</version>
>>>>                      <type>jar</type>
>>>>                      <scope>compile</scope>
>>>>              </dependency>
>>>>
>>>>      >
>>>>      >
>>>>      > On Thu, Feb 20, 2014 at 4:11 AM, Moti Asayag <masayag at redhat.com
>>>>      <mailto:masayag at redhat.com>> wrote:
>>>>      >
>>>>      > >
>>>>      > >
>>>>      > > ----- Original Message -----
>>>>      > > > From: "Tejesh M" <tejeshmk at gmail.com <mailto:tejeshmk at gmail.com>>
>>>>      > > > To: "users at oVirt.org" <users at ovirt.org <mailto:users at ovirt.org>>
>>>>      > > > Sent: Wednesday, February 19, 2014 3:24:40 PM
>>>>      > > > Subject: [Users] Fwd: Sample code for setting NIC - CloudInit
>>>>      > > >
>>>>      > > > Hi,
>>>>      > > >
>>>>      > > > Can someone share me sample java code for assigning IP address
>>>>      for VM on
>>>>      > > eth0
>>>>      > > > through Java SDK via CloudInit ?
>>>>      > > >
>>>>      > >
>>>>      > > Hi Tejesh,
>>>>      > >
>>>>      > > I've attached a sample code that sends the required request (as
>>>>      the output
>>>>      > > is demonstrated in debug mode).
>>>>      > > Note that the code is jdk-7 compliant.
>>>>      > > I haven't configured cloud-init and haven't tested it end-to-end.
>>>>      > > Please try to test it on your environment and provide a feedback
>>>>      for it.
>>>>      > >
>>>>      > > Thanks,
>>>>      > > Moti
>>>>      > >
>>>>      > > > Something Like this but in Java:
>>>>      > > > <network_configuration>
>>>>      > > >          <nics>
>>>>      > > >            <nic>
>>>>      > > >              <name>eth0</name>
>>>>      > > >              <boot_protocol>STATIC</boot_protocol>
>>>>      > > >              <network>
>>>>      > > >                <ip address="192.168.2.11" netmask="255.255.0.0"
>>>>      > > >                gateway="192.168.2.1" />
>>>>      > > >              </network>
>>>>      > > >              <on_boot>true</on_boot>
>>>>      > > >            </nic>
>>>>      > > >            <nic>
>>>>      > > >              <name>eth1</name>
>>>>      > > >              <boot_protocol>DHCP</boot_protocol>
>>>>      > > >            </nic>
>>>>      > > >            <nic>
>>>>      > > >              <name>eth2</name>
>>>>      > > >              <boot_protocol>NONE</boot_protocol>
>>>>      > > >              <on_boot>true</on_boot>
>>>>      > > >            </nic>
>>>>      > > >          </nics>
>>>>      > > >          <dns>
>>>>      > > >            <servers>
>>>>      > > >              <host>
>>>>      > > >                <address>1.1.2.2</address>
>>>>      > > >              </host>
>>>>      > > >              <host>
>>>>      > > >                <address>1.2.3.4</address>
>>>>      > > >              </host>
>>>>      > > >            </servers>
>>>>      > > >            <search_domains>
>>>>      > > >              <host>
>>>>      > > >                <address>qa.lab</address>
>>>>      > > >              </host>
>>>>      > > >              <host>
>>>>      > > >                <address> google.com <http://google.com> </address>
>>>>      > > >              </host>
>>>>      > > >            </search_domains>
>>>>      > > >          </dns>
>>>>      > > >        </network_configuration>
>>>
>>
>>
> 


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