Skip to content

Skip adapter rename when set-name is not explicitly provided#190

Draft
maxpain wants to merge 1 commit intocloudbase:masterfrom
maxpain:fix/skip-rename-without-set-name
Draft

Skip adapter rename when set-name is not explicitly provided#190
maxpain wants to merge 1 commit intocloudbase:masterfrom
maxpain:fix/skip-rename-without-set-name

Conversation

@maxpain
Copy link
Copy Markdown

@maxpain maxpain commented Apr 5, 2026

Summary

When using network-config v2 with match.macaddress, cloudbase-init renames the network adapter to the ethernets dict key name. This causes failures on Windows:

  1. WMI race conditionMSFT_NetAdapter.rename() succeeds but the new name is not immediately queryable by subsequent WMI calls, causing "Network interface with name '...' not found" errors (Network interface renaming is not working on Win Server 2022 Core #101, WMI issue may break cloudbase-init adapter rename at VM node bootstrapping  #151)
  2. Rename hangsnetsh-based rename can hang for ~9 minutes on Windows Server 2022 (Windows Server 22 deployment stuck at renaming NIC #82)
  3. Name collisions — renaming fails with {Object Exists} when another adapter already has the target name

This PR aligns cloudbase-init behavior with cloud-init (Linux), where the ethernets dict key is an opaque identifier when match is present, and only set-name triggers an actual rename.

How it works

The v2 parser stores link.id = dict key and link.name = set-name (or dict key if not provided). When link.id == link.name (no set-name), the adapter found by MAC is used with its current Windows name. When link.id != link.name (set-name was explicitly provided), rename proceeds as before.

Example

# Before this fix: renames "Ethernet" to "vdpa0" (unreliable)
# After this fix: uses "Ethernet" directly, no rename
version: 2
ethernets:
  vdpa0:
    match:
      macaddress: "00:00:00:00:88:01"
    addresses:
      - 10.0.0.1/24

# Explicit rename still works with set-name:
  eth0:
    match:
      macaddress: "00:00:00:00:88:01"
    set-name: my-nic
    addresses:
      - 10.0.0.1/24

Testing

  • Added unit tests for both paths (no-rename and rename-with-set-name)
  • All 23 existing tests pass unchanged
  • Verified on Windows Server 2025 with vDPA (mlx5_vdpa) + Cloud-Hypervisor: network auto-configured on first boot from sysprepped image

@maxpain maxpain force-pushed the fix/skip-rename-without-set-name branch 2 times, most recently from a335e66 to abd0f44 Compare April 5, 2026 14:09
@maxpain maxpain marked this pull request as draft April 5, 2026 20:47
When using network-config v2 with match.macaddress, cloudbase-init
always renames the adapter to the ethernets dict key name. This
causes failures on Windows because:

1. The WMI rename call (MSFT_NetAdapter.rename) is unreliable during
   early boot — the new name is not immediately queryable, causing
   "Network interface not found" errors (cloudbase#101, cloudbase#151)
2. The rename can hang for minutes on some Windows versions (cloudbase#82)
3. Multiple adapters can cause name collisions

This aligns with cloud-init (Linux) behavior where the ethernets
dict key is just an opaque identifier when match is present, and
only set-name triggers an actual rename.

The fix checks link.id vs link.name: when they match (no set-name
was provided), the adapter is used with its current Windows name
instead of being renamed. When set-name is explicitly provided
(link.id != link.name), rename proceeds as before.

Signed-off-by: Max Makarov <maxpain@linux.com>
@maxpain maxpain force-pushed the fix/skip-rename-without-set-name branch from abd0f44 to b983b1d Compare April 5, 2026 20:52
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.

1 participant