feat(datasource/aliyun): add IPv6 metaserver and DHCP strategy based on NIC metadata#6893
feat(datasource/aliyun): add IPv6 metaserver and DHCP strategy based on NIC metadata#6893challvy wants to merge 1 commit into
Conversation
…on NIC metadata - Add IPv6 metadata server address (http://[fd00:100::100:200]) as fallback endpoint in metadata_urls - Disable DHCPv4 when NIC metadata lacks 'private-ipv4s' field, indicating no IPv4 address is assigned to the interface - Enable DHCPv6 when 'ipv6s' field is present in NIC metadata - Remove dhcp4-overrides when DHCPv4 is disabled for the interface - Update unit tests to cover IPv6-only NIC, dual-stack NIC, and mixed multi-NIC scenarios Signed-off-by: Cang Yu <zhengcongwei.zcw@alibaba-inc.com>
There was a problem hiding this comment.
Pull request overview
Adds AliYun (Alibaba Cloud ECS) support for reaching IMDS over IPv6 and avoids DHCPv4 timeouts on IPv6-only ENIs by rendering DHCP settings based on NIC metadata.
Changes:
- Add the IPv6 IMDS endpoint (
http://[fd00:100::100:200]) toDataSourceAliYun.metadata_urlsso IMDS discovery can succeed on IPv6-only instances. - Update
convert_ecs_metadata_network_config()to disabledhcp4(and dropdhcp4-overrides) when a NIC lacksprivate-ipv4s, while still enablingdhcp6whenipv6sis present. - Add unit tests covering IPv4-only, dual-stack, and IPv6-only NIC scenarios.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
cloudinit/sources/DataSourceAliYun.py |
Adds IPv6 IMDS base URL to the datasource’s metadata URL candidates. |
cloudinit/sources/helpers/aliyun.py |
Makes DHCPv4/DHCPv6 configuration conditional on per-NIC metadata and hardens override cleanup. |
tests/unittests/sources/test_aliyun.py |
Extends unit test coverage for the updated DHCP rendering logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| nic_metadata = macs_metadata.get(mac) | ||
| if nic_metadata.get("ipv6s"): # Any IPv6 addresses configured | ||
| dev_config["dhcp6"] = True | ||
| if not nic_metadata.get("private-ipv4s"): # No IPv4 addresses | ||
| dev_config["dhcp4"] = False |
| def test_ipv6_only_nic_config(self): | ||
| """Test a NIC with only IPv6 (no private-ipv4s).""" | ||
| netcfg = convert_ecs_metadata_network_config( | ||
| { | ||
| "interfaces": { | ||
| "macs": { | ||
| "00:16:3e:14:59:58": { | ||
| "ipv6s": "[2408:xxxxxx]", | ||
| "network-interface-id": "eni-bp13i1xxxxx", | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| macs_to_nics={"00:16:3e:14:59:58": "eth0"}, | ||
| ) | ||
|
|
||
| # No private-ipv4s: dhcp4 disabled | ||
| assert netcfg["ethernets"]["eth0"]["dhcp4"] is False | ||
| # Has ipv6s: dhcp6 enabled | ||
| assert netcfg["ethernets"]["eth0"]["dhcp6"] is True | ||
|
|
||
|
|
|
@blackboxsw Hi, according to my latest tests, there is an issue with this change: in an IPv6 environment, because it waits for the DHCPv4 negotiation result (with a timeout of several minutes), the boot process gets stuck for several minutes. Please do not merge this yet. Let me do further testing and modify the code, and then we can consider merging it. |
|
@challvy thanks for this input. We'll await your findings, please keep us informed. I do wonder if that timeout you are seeing with dhcp4 is due to Aliyun's EphemeralIPNetwork call in get_data not providing an |
|
Additionally, in situations where IPv6 only is configured for an instance. I think we may need a bit of an overhaul within EphemeralIPNetwork to potentially run a dual-stack race to request both dhcp6 and dhcp4 addrs when both ipv4=true and ipv6=true and no connectivity_urls are accessible. That way, the EphemeralIPNetwork could proceed when either ipv6 or ipv4 connectivity is asserted to a known IMDS URL, thereby avoiding a wait on an unconfigured DHCP4 response for ipv6-only networks. |
|
@blackboxsw Thank you for your feedback; I still need some time on my side to design and validate it. |
Proposed Commit Message
Fixes #6892
Additional Context
The IPv6 metadata endpoint and IPv6-only ENIs are documented features
of Alibaba Cloud ECS. With these changes, cloud-init can correctly
fetch metadata and render network configuration on:
private-ipv4sonlyprivate-ipv4s+ipv6s(dual-stack)ipv6sonly (IPv6-only ENI)Backwards compatibility:
always contains
private-ipv4s, sodhcp4staystrue.metadata_urlsdoes not change behaviourwhen the IPv4 IMDS endpoint responds successfully.
Test Steps
Unit tests (covers all three NIC scenarios):
Expected: all tests pass, including the new
test_dhcp4_disabled_when_no_private_ipv4s,test_dhcp6_enabled_when_ipv6s_present, andtest_ipv6_only_nic_config.Live verification on an Alibaba Cloud ECS instance:
a. Launch a dual-stack ECS instance with both IPv4 and IPv6
addresses, boot with this cloud-init build, and confirm:
/run/cloud-init/instance-data.jsoncontains metadata fetchedfrom IMDS.
dhcp4: trueanddhcp6: truefor the dual-stack NIC.
b. Attach an IPv6-only secondary ENI (no
private-ipv4sinmetadata), reboot, and confirm:
dhcp4: falseanddhcp6: true.c. (Optional) Disable IPv4 IMDS on a test instance and confirm
cloud-init still reaches metadata via
http://[fd00:100::100:200].Merge type