How to use custom attributes of a host in network configuration?

Hi everyone,

I’m setting up OpenNebula 7.0.1 and have run into a challenge with network configuration.

The Problem: Each of my hypervisors has a different physical network interface name (e.g., eth0, enp1s0, eno1). To manage this, I’ve created a ‘Custom Attribute’ for each host, named PHY_DEV_FOR_ONEBRIDGE, which stores the specific physical device name for that host.

My Goal: I want to create a Virtual Network that dynamically uses this PHY_DEV_FOR_ONEBRIDGE attribute as its bridge name (e.g., for ONEBRIDGE), so that VMs deployed to different hosts correctly attach to the host’s specific physical interface.

What I’ve tried (and failed): When defining the Virtual Network (specifically, in the BRIDGE attribute within the Virtual Network template), I’ve attempted to use several variable syntaxes to reference this custom host attribute:

  • $HOST.PHY_DEV_FOR_ONEBRIDGE

  • $PHY_DEV_FOR_ONEBRIDGE

  • $TEMPLATE.PHY_DEV_FOR_ONEBRIDGE

In all these attempts, virtual machines attached to this network fail to start correctly, suggesting the bridge name isn’t being resolved or applied as expected.

My Question: What is the correct way to reference a host’s custom attribute (like PHY_DEV_FOR_ONEBRIDGE) within a Virtual Network definition so that the BRIDGE attribute dynamically resolves based on the target host? Or am I approaching this problem incorrectly entirely?

Any help or pointers to the right documentation would be greatly appreciated!

Hello,

To avoid this problem, my recommendation is to take it out of OpenNebula and let the OS solve it.

If the iproute2 version of all of your servers is recent enough (v5.4.0 released on 2019-11-25) you can set up an altname to any network interface on your server. If your distribution uses systemd you can add services that set up the same name to the required interfaces in different nodes. For instance, creating the file /etc/systemd/system/altnames-opennebula.service with the following contents would add an altname eth0 to the interface eno1np0 on your server.

[Unit]
 Description=Set altnames for OpenNebula

[Service]
 Type=simple
 ExecStart=ip link property add dev eno1np0 altname eth0

[Install]
 WantedBy=multi-user.target

Don’t forget to enable the service and start it in order to make it work

systemctl enable altnames-opennebula.service
systemctl start altnames-opennebula.service

You can create this file on every server changing the name of the interface (instead of eno1np0). If you want to change more than an interface name, do it changing the ExecStart line using bash

ExecStart=/bin/bash -c 'ip link property add dev iface0 altname alt0 && ip link property add dev iface1 altname alt1'

Some good things about this approach:

  • It doesn’t have overhead on OpenNebula (but changing the physical interface)
  • The name of the interface does not have to be eth0. A more relevant name can be set (i.e. one0)

Cheers!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.