Configure OpenNebula to use DHCP

dhcpopennebula

I'm trying to configure OpenNebula to use the DHCP server that already exists on my network. Yes, I already know that OpenNebula manages virtual mac addresses rather than IP addresses, but that doesn't tell me how to get this working. 😉

My guests and hosts are both CentOS, so I would imagine all that needs to be done is configure contextualization so that BOOTPROTO=dhcp is dumped into /etc/sysconfig/network-scripts/ifcfg-eth0.

  1. How do I configure contextualization so that this happens? Do I just modify my template in a certain way? If so, how is that done?
  2. Once I configure my template with these new contextualization settings, how should I configure my virtual network in ONE?

It seems like this should be easy to do, as this should appear to be simpler than managing a bunch of static IPs for vms, and you would think that this is a common use case. However, googleing so far has turned up very little.

Thanks!!

Edit:
My DHCP server successfully gives my vm an ip address if I set BOOTPROTO=dhcp and DHCP_HOSTNAME=foo manually and restart networking on my vm. Which is fine, I would like to be able to set the hostnames of the vms I spin up too.

Now it's just a matter of determining how to make ONE do these things automatically/via the web interface or CLI tools. Also ONE still lists the IP address of the original lease, rather than the IP that DHCP gave my VM. It would be nice to get that issue fixed too.

Best Answer

My Opennebula is version 4.8.0. I had similar needs, so here is what I did:

  1. I configured the DHCP server that already exists in our network to reserve an IP range for DHCP. The range was: 10.23.1.201 - 10.23.1.254. That's 54 dynamic IPs.
  2. I created a new Virtual Network, which I named "DHCP". On the tab "Addresses" I chose radio button "Ethernet". This way Opennebula will only give MAC addresses to the VMs using this network. I left "MAC Start" empty because it's optional anyway. I entered 54 in the "Size" field because my DHCP can provide this many dynamic IP addresses. So, Opennebula gives new VMs only a mac address and nothing more.

The guest OS has to be manually set up to use DHCP. I don't know how to do that automatically, but that's not a big issue.

Here is how I proceeded further to have a template that uses DHCP. I went on to install a new operating system, for example CentOS 6.5.

  1. I created a template using this new Virtual Network and two disks - an ISO image and an empty datablock image set to "persistent = yes".
  2. Then, I instantiate the template, the VM boots up from the ISO and when I install the VM, I leave the network configuration to "dynamic".
  3. When the installation finishes, my VM has an automatically assigned IP from the DHCP server just like if it was a real machine.
  4. I then stop and delete the VM.
  5. Set the datablock image back to "persistent = no".

Now every new VM that spawns from that template will be using the "DHCP" Virtual Network, will have a dynamic IP address and Opennebula will not display any IP address for such VMs.

I can't answer about the automatic setting of hostname, but I think it must be a matter of configuring the guest OS and the DHCP. On the other hand, DHCP must know what hostname to give to which MAC address and, since Opennebula will be generating those MAC addresses dynamically, I don't know how you can tell the DHCP server about them in advance.

Related Topic