Skip to content

Added: support for multiple network interfaces in openstack datasource#6877

Open
mklejn-ovh wants to merge 1 commit into
canonical:mainfrom
mklejn-ovh:main
Open

Added: support for multiple network interfaces in openstack datasource#6877
mklejn-ovh wants to merge 1 commit into
canonical:mainfrom
mklejn-ovh:main

Conversation

@mklejn-ovh
Copy link
Copy Markdown

@mklejn-ovh mklejn-ovh commented May 12, 2026

Proposed Commit Message

fix(openstack): Support mixed dhcp and no-dhcp interfaces

DS OpenstackLocal was only using fallback_interface for it's metadata service detection
which may fail when multiple interfaces, including ones without dhcp, are provided.
Behaviour fixed via iterating over all interfaces until we hit one that has dhcp enabled,
or we fail to find one and explicitly explain that no interface was able to get dhcp lease.

Fixes GH-6786

Additional Context

Right here: GH-6786

Test Steps

Right here: GH-6786

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

Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

Basic approach looks good here thanks @mklejn-ovh. I realize that enumerating and walking through multiple interfaces with DHCP requests may lead to delays on BIG systems with multiple NICs if the primary NIC doesn't have DHCP on the attached network.

I think this approach for NIC discovery is ok as you mentioned that NIC attach ordering to VMs is what matters here. Since cloud-init generally prefers that a platform have its primary NIC connected to the platform with access to the instance metadata service (and DHCP), any configuration which diverges from that expectation will either hit 'no IMDS connectivity' issues as you are trying to fix here, or slight delays trying to process non-primary NICs first before finding the right one.

Let's also add a small doc update about multi-NIC discovery in doc/rtd/reference/datasources/openstack.rst.

Comment on lines +166 to +167
NoDHCPLeaseError,
sources.InvalidMetaDataException,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This approach aligns with what we have currently in GCE datasource with two things missing:

I think we want to distinguish NoDHCPLeaseError condition by logging "Unable to obtain a DHCP lease for "

NoDHCPLeaseError,
sources.InvalidMetaDataException,
) as e:
util.logexc(LOG, str(e))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Generally there is not a lot of value in logging the related traceback via util.logexc if we can valid it. Our common logging pattern gives is the module cloud-init is logging from, so the additional traceback info is nothing more than a lot of noise in our already busy logs. Since you are touching this area. Maybe we make an effort to LOG.debug("OpenStack metadata error: %s") vs "Unable to obtain DHCP lease on %s" etc.

util.logexc(LOG, str(e))
if not results:
LOG.warning(
"All interfaces failed to get dhcp lease"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"All interfaces failed to get dhcp lease"
"All interfaces failed to get DHCP lease. "

if not results:
LOG.warning(
"All interfaces failed to get dhcp lease"
"Metadata service will NOT be called"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"Metadata service will NOT be called"
" OpenStack metadata service will NOT be called"

def get_interface_list(self):
ifaces = []
for iface in net.find_candidate_nics():
if "dummy" in iface:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if we want to promote this logic into net.find_candidate_nics directly. I see Vultr also attempts to ignore this iface name and I think it's generally irrelevant as a candidate.

return True

def _crawl_metadata(self):
def _crawl_metadata(self, iface=None):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since you are touching functions, please add type hints to function params and expected return values to aid in mypy verification.

return mstr

def wait_for_metadata_service(self):
def wait_for_metadata_service(self, iface):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add typing hints for function returns and params to aid our mypy CI validation.

@blackboxsw blackboxsw self-assigned this Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants