Skip to content

feat(opennebula): support PCIx_* passthrough network interfaces#6816

Open
mcanevet wants to merge 1 commit intocanonical:mainfrom
mcanevet:feat/opennebula-pci-passthrough
Open

feat(opennebula): support PCIx_* passthrough network interfaces#6816
mcanevet wants to merge 1 commit intocanonical:mainfrom
mcanevet:feat/opennebula-pci-passthrough

Conversation

@mcanevet
Copy link
Copy Markdown
Contributor

Proposed Commit Message

feat(opennebula): support PCIx_* passthrough network interfaces

OpenNebula's context-linux package configures PCI passthrough NICs
using PCIx_ADDRESS / PCIx_IP / PCIx_MASK / PCIx_GATEWAY / PCIx_MTU /
PCIx_VLAN_ID variables. cloud-init ignored these entirely.

Add _get_pci_context_ifaces() to scan context keys for PCIx_ADDRESS
entries, and _pci_addr_to_dev() to resolve a PCI address to a system
device name via /sys/bus/pci/devices/<addr>/net/. Extend gen_conf() to
emit ethernets: entries for each PCI device, with optional VLAN support
matching the existing ETHx_VLAN_ID behaviour. Devices whose sysfs path
cannot be found are skipped with a warning.

Additional Context

Part of a series bringing cloud-init's OpenNebula datasource to feature
parity with the context-linux package from one-apps.

PCI passthrough NICs cannot be matched by MAC address (they have no
ETHx_MAC equivalent), so _pci_addr_to_dev() resolves via sysfs
instead. The _pci_sysfs_root class attribute is overridable in tests
to avoid touching the real filesystem.

Test Steps

In an OpenNebula VM with a PCI passthrough NIC at address 0000:00:06.0,
set:

PCI0_ADDRESS="0000:00:06.0"
PCI0_IP="10.5.0.1"
PCI0_MASK="255.255.255.0"
PCI0_GATEWAY="10.5.0.254"

After boot, verify ip addr show enp0s6 (or whatever the device is
named) shows 10.5.0.1/24.

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

@github-actions github-actions Bot added the documentation This Pull Request changes documentation label Mar 30, 2026
@mcanevet mcanevet force-pushed the feat/opennebula-pci-passthrough branch from 055f1e6 to 99f7bec Compare April 1, 2026 08:33
@github-actions
Copy link
Copy Markdown

Hello! Thank you for this proposed change to cloud-init. This pull request is now marked as stale as it has not seen any activity in 14 days. If no activity occurs within the next 7 days, this pull request will automatically close.

If you are waiting for code review and you are seeing this message, apologies! Please reply, tagging blackboxsw, and he will ensure that someone takes a look soon.

(If the pull request is closed and you would like to continue working on it, please do tag blackboxsw to reopen it.)

@github-actions github-actions Bot added the stale-pr Pull request is stale; will be auto-closed soon label Apr 16, 2026
@blackboxsw blackboxsw removed the stale-pr Pull request is stale; will be auto-closed soon label Apr 21, 2026
@mcanevet mcanevet force-pushed the feat/opennebula-pci-passthrough branch from 99f7bec to 67b1393 Compare April 22, 2026 06:48
@mcanevet
Copy link
Copy Markdown
Contributor Author

@blackboxsw rebased

OpenNebula's context-linux package configures PCI passthrough NICs
using PCIx_ADDRESS / PCIx_IP / PCIx_MASK / PCIx_GATEWAY / PCIx_MTU /
PCIx_VLAN_ID variables. cloud-init ignored these entirely.

Add _get_pci_context_ifaces() to scan context keys for PCIx_ADDRESS
entries, and _pci_addr_to_dev() to resolve a PCI address to a system
device name via /sys/bus/pci/devices/<addr>/net/. Extend gen_conf() to
emit ethernets: entries for each PCI device, with optional VLAN support
matching the existing ETHx_VLAN_ID behaviour. Devices whose sysfs path
cannot be found are skipped with a warning.
Copilot AI review requested due to automatic review settings May 5, 2026 14:34
@mcanevet mcanevet force-pushed the feat/opennebula-pci-passthrough branch from 67b1393 to 2d6cb65 Compare May 5, 2026 14:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the OpenNebula datasource’s network configuration generation to support PCI passthrough NICs configured via OpenNebula context variables (PCI<x>_*), resolving PCI addresses to interface names through sysfs and emitting corresponding netplan configuration.

Changes:

  • Add helpers to discover PCI<x>_ADDRESS context entries and map PCI addresses to netdev names via /sys/bus/pci/devices/<addr>/net/.
  • Extend OpenNebulaNetwork.gen_conf() to emit netplan entries for PCI passthrough NICs, including optional VLAN configuration.
  • Add unit tests and update OpenNebula datasource documentation to describe the new PCI context variables.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
cloudinit/sources/DataSourceOpenNebula.py Adds PCI context scanning + sysfs resolution and emits netplan config for PCI passthrough NICs (with VLAN support).
tests/unittests/sources/test_opennebula.py Adds unit tests covering PCI context parsing, sysfs resolution, and basic PCI static config emission.
doc/rtd/reference/datasources/opennebula.rst Documents supported PCI<x>_* context variables and behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

m = re.match(r"^(PCI\d+)_ADDRESS$", key)
if m:
seen.add(m.group(1))
return sorted(seen)
"""
sysfs = os.path.join(self._pci_sysfs_root, pci_address, "net")
try:
devs = os.listdir(sysfs)
pci_devconf["gateway4"] = gateway
mtu = self.get_field(pci_prefix, "mtu")
if mtu:
pci_devconf["mtu"] = mtu
Comment on lines +392 to +400
vlan_id: Optional[str] = self.get_field(pci_prefix, "vlan_id")
if vlan_id:
netconf["ethernets"][pci_dev] = {}
target_name = "%s.%s" % (pci_dev, vlan_id)
pci_devconf["id"] = int(vlan_id)
pci_devconf["link"] = pci_dev
netconf.setdefault("vlans", {})[target_name] = pci_devconf
else:
netconf["ethernets"][pci_dev] = pci_devconf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation This Pull Request changes documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants