Set VM IPs using DHCP

Hi everyone,

I have a simple cloud environment with one front-end and one host, using the Xen hypervisor.

Both the front-end and the host are connected in a LAN network that uses DHCP. The IPs are successfully assigned to the instantiated VMs.

The problem is that I don’t know how to configure OpenNebula to use this dynamically assigned IPs and list it to the user through Sunstone or CLI, so there is no way that the user can get the VM IP address and connect to it.

If I create a vnet, I need to list the range of IPs to be assigned to the VMs. OpenNebula will state that an IP inside this range is being used by each VM, when in fact the real VM IP address is a DHCP-assigned one.

Is there any way to configure OpenNebula to use DHCP IP address and list it to the user?

Thanks!

If there is an easier way than the following, I’m keen to learn about it.

We started by creating images that had the context scripts modified to make sure the VM’s hostname was set to the actual VM name before DHCP was started. That way the VM’s name in Sunstone would match what was in DHCP and if you are using dnsmasq/isc-dhcp+unbound or Windows Active Directory for dhcp+DNS you could reach the host via its hostname. The challenge with that approach was twofold–sometimes with systemd it’s hard to make sure that the hostname is set properly by the context scripts before DHCP is run. Second, some DNS resolvers cache NXDOMAINs (I think they are not supposed to, but they do it anyway), so if you tried to ssh or ping too early before the entry was registered in DNS you could not successfully look it up until the caching resolver expired the NXDOMAIN entry.

The second thing I tried was to use the stock context scripts, but have a post-vm-init script that reconfigured the dhcp client to request the same IP address that ONE had calculated. We have to support many distributions in our ONE cluster, and I could not get all of them to behave the same way. Some (like FreeBSD) would end up allocating a second address to the network adapter, which worked, but probably would generate much confusion when our engineers realized that the DNS entries didn’t match the IP for the VM in Sunstone.

My current approach is leveraging the new IPAM support in OpenNebula 5.2. Since we are using isc-dhcp and our local DNS server is configured to pick up entries from its leases table, I turned on isc-dhcp’s OMAPI support, and I’m in the process of writing scripts with the pypureomapi library. ONE will still pick an IP address from its pool, but it will then ask dhcp directly (via OMAPI, not via a dhcp client) to create a lease for that IP when the VM is created. When the VM is destroyed, the associated IPAM script will tell dhcp to release the address.

This support is not done yet, but when it is I will publish the link to the repo on Github.

NXDOMAIN can indeed be cached. It is however possible to set a different TTL for them than the default TTL of the positive replies. See RFC 2308.

Hello, I wrote simple nodejs script which connect to opennebula xml-rpc api and generate dhcp reservations for dnsmasq server and also have ability to generate shorewall dnat rules.