|
|
|
|
@ -237,7 +237,7 @@ def build_seed_iso(
|
|
|
|
|
mac: str,
|
|
|
|
|
validated_network: dict[str, Any],
|
|
|
|
|
*,
|
|
|
|
|
networkd_fallback: bool = False,
|
|
|
|
|
debian12_network_fix: bool = False,
|
|
|
|
|
) -> bytes:
|
|
|
|
|
"""Build a CIDATA ISO with user-data, meta-data, and network-config."""
|
|
|
|
|
try:
|
|
|
|
|
@ -254,8 +254,8 @@ def build_seed_iso(
|
|
|
|
|
raise ValueError("虚拟机 MAC 地址不能是组播或全零地址")
|
|
|
|
|
if not isinstance(validated_network, dict):
|
|
|
|
|
raise ValueError("网络配置无效")
|
|
|
|
|
if not isinstance(networkd_fallback, bool):
|
|
|
|
|
raise ValueError("网络后端选项无效")
|
|
|
|
|
if not isinstance(debian12_network_fix, bool):
|
|
|
|
|
raise ValueError("Debian 12 网络修复选项无效")
|
|
|
|
|
network = validate_cloud_network(
|
|
|
|
|
validated_network.get("public_ip_cidr"),
|
|
|
|
|
validated_network.get("gateway"),
|
|
|
|
|
@ -295,65 +295,30 @@ def build_seed_iso(
|
|
|
|
|
"disable_root": False,
|
|
|
|
|
"write_files": write_files,
|
|
|
|
|
}
|
|
|
|
|
if networkd_fallback:
|
|
|
|
|
# Debian 12's cloud-init/Netplan combination renders the correct
|
|
|
|
|
# static configuration during init-local, but its default NoCloud
|
|
|
|
|
# ``net`` mode can then wait for that still-inactive network before
|
|
|
|
|
# user-data is consumed. The persistent networkd file below is
|
|
|
|
|
# written during init-local (see metadata ``dsmode`` below). bootcmd
|
|
|
|
|
# queues a non-blocking networkd start for after init-local exits, so
|
|
|
|
|
# normal network-pre ordering (including firewall setup) is preserved.
|
|
|
|
|
# The 05 prefix makes the MAC-matched fallback deterministic if
|
|
|
|
|
# Netplan also emits a 10-netplan file.
|
|
|
|
|
#
|
|
|
|
|
# This product currently provisions IPv4 only. systemd-networkd can
|
|
|
|
|
# otherwise start DHCPv6 in response to a router advertisement even
|
|
|
|
|
# when DHCP=no. That makes a cleaned Debian 12 image with no
|
|
|
|
|
# /etc/machine-id fail the whole link while trying to derive a DHCPv6
|
|
|
|
|
# client identifier, before its static IPv4 address is applied.
|
|
|
|
|
networkd_lines = [
|
|
|
|
|
"# Generated by Virt Cloud for Debian 12 first-boot networking.",
|
|
|
|
|
"[Match]",
|
|
|
|
|
f"MACAddress={normalized_mac}",
|
|
|
|
|
"",
|
|
|
|
|
"[Network]",
|
|
|
|
|
"DHCP=no",
|
|
|
|
|
"IPv6AcceptRA=no",
|
|
|
|
|
f"Address={network['public_ip_cidr']}",
|
|
|
|
|
]
|
|
|
|
|
networkd_lines.extend(
|
|
|
|
|
f"DNS={server}" for server in network["dns_servers"]
|
|
|
|
|
)
|
|
|
|
|
networkd_lines.extend([
|
|
|
|
|
"",
|
|
|
|
|
"[Route]",
|
|
|
|
|
"Destination=0.0.0.0/0",
|
|
|
|
|
f"Gateway={network['gateway']}",
|
|
|
|
|
"",
|
|
|
|
|
])
|
|
|
|
|
write_files.append({
|
|
|
|
|
"path": "/etc/systemd/network/05-virt-cloud-public.network",
|
|
|
|
|
"content": "\n".join(networkd_lines),
|
|
|
|
|
"permissions": "0644",
|
|
|
|
|
})
|
|
|
|
|
if debian12_network_fix:
|
|
|
|
|
# NoCloud normally consumes user-data in its network stage. Debian 12
|
|
|
|
|
# can wait for a still-disabled systemd-networkd before reaching that
|
|
|
|
|
# stage, so consume this local seed during init-local instead. The
|
|
|
|
|
# network itself remains entirely in the standard network-config file;
|
|
|
|
|
# bootcmd only prepares the renderer and starts its backend.
|
|
|
|
|
queue_networkd = "\n".join([
|
|
|
|
|
# cloud-init clean --machine-id can leave a custom Debian image
|
|
|
|
|
# without this file. The systemd helper initializes a valid ID
|
|
|
|
|
# from the guest's system sources and is a no-op when one already
|
|
|
|
|
# exists.
|
|
|
|
|
"systemd-machine-id-setup",
|
|
|
|
|
# cloud-init 22.4 on Debian 12 can write the Netplan YAML during
|
|
|
|
|
# init-local without generating networkd's runtime configuration.
|
|
|
|
|
"netplan generate",
|
|
|
|
|
"systemctl unmask systemd-networkd.service",
|
|
|
|
|
"systemctl enable systemd-networkd.service",
|
|
|
|
|
"systemctl start --no-block systemd-networkd.service",
|
|
|
|
|
])
|
|
|
|
|
user_data["bootcmd"] = [
|
|
|
|
|
[
|
|
|
|
|
"cloud-init-per", "instance", "virt-cloud-debian12-networkd",
|
|
|
|
|
"/bin/sh", "-ec", queue_networkd,
|
|
|
|
|
],
|
|
|
|
|
["/bin/sh", "-ec", queue_networkd],
|
|
|
|
|
]
|
|
|
|
|
metadata = {"instance-id": instance_id, "local-hostname": hostname}
|
|
|
|
|
if networkd_fallback:
|
|
|
|
|
if debian12_network_fix:
|
|
|
|
|
# Consume bootcmd in cloud-init-local, before systemd waits for
|
|
|
|
|
# network-online. This stays scoped to the Debian 12 compatibility
|
|
|
|
|
# path because remote user-data cannot be fetched in local mode.
|
|
|
|
|
@ -377,7 +342,12 @@ def build_seed_iso(
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
if networkd_fallback:
|
|
|
|
|
if debian12_network_fix:
|
|
|
|
|
# dhcp6=false does not disable DHCPv6 started in response to a router
|
|
|
|
|
# advertisement. This product currently provisions IPv4 only, so
|
|
|
|
|
# express that intent through Netplan instead of writing a second,
|
|
|
|
|
# provider-specific .network file.
|
|
|
|
|
network_config["ethernets"]["public0"]["accept-ra"] = False
|
|
|
|
|
network_config["renderer"] = "networkd"
|
|
|
|
|
|
|
|
|
|
files = (
|
|
|
|
|
|