mirror of
https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git
synced 2026-06-21 00:07:16 +03:00
nocloud: add minimal network-config v2 support
This commit is contained in:
parent
5c3bd02e27
commit
13a2cc6968
@ -4,6 +4,12 @@
|
||||
|
||||
INIT_ACTIONS_BOOT="$(replace_word set_default_interfaces set_network_interfaces $INIT_ACTIONS_BOOT)"
|
||||
|
||||
get_network_config() {
|
||||
IFS="/"
|
||||
yx -f "$TINY_CLOUD_VAR/network-config" $1 2>/dev/null
|
||||
unset IFS
|
||||
}
|
||||
|
||||
set_resolv_conf() {
|
||||
# resolv.conf
|
||||
local nameservers="$(imds meta-data/resolv_conf/nameservers)"
|
||||
@ -43,11 +49,53 @@ want_ephemeral_network() {
|
||||
return 1
|
||||
}
|
||||
|
||||
set_network_config_v2() {
|
||||
[ -s "$TINY_CLOUD_VAR/network-config" ] || return 1
|
||||
local version="$(get_network_config version)"
|
||||
if [ "$version" != "2" ]; then
|
||||
log -i -t "$phase" warning "$ACTION: unsupported NoCloud network-config version: ${version:-unknown}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local ethernets="$(get_network_config ethernets)"
|
||||
if [ -z "$ethernets" ]; then
|
||||
log -i -t "$phase" warning "$ACTION: NoCloud network-config v2 has no supported ethernets entries"
|
||||
return 1
|
||||
fi
|
||||
|
||||
printf "%s\n%s\n\n" \
|
||||
"auto lo" \
|
||||
"iface lo inet loopback" \
|
||||
> "$ETC/network/interfaces"
|
||||
|
||||
local iface configured=
|
||||
for iface in $ethernets; do
|
||||
case "$(get_network_config ethernets/$iface/dhcp4)" in
|
||||
true|yes)
|
||||
printf "%s\n%s\n\t%s\n\n" \
|
||||
"auto $iface" \
|
||||
"iface $iface" \
|
||||
"use dhcp" >> "$ETC/network/interfaces"
|
||||
configured=1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$configured" ]; then
|
||||
log -i -t "$phase" warning "$ACTION: NoCloud network-config v2 has no supported ethernets entries"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
init__set_network_interfaces() {
|
||||
local interfaces="$(imds meta-data/network-interfaces)"
|
||||
mkdir -p "$ETC"/network
|
||||
if [ -n "$interfaces" ]; then
|
||||
printf "%s\n" "$interfaces" > "$ETC"/network/interfaces
|
||||
elif set_network_config_v2; then
|
||||
:
|
||||
elif ! [ -f "$ETC"/network/interfaces ]; then
|
||||
init__set_default_interfaces
|
||||
fi
|
||||
|
||||
@ -36,7 +36,7 @@ fake_umount() {
|
||||
while ! [ -d "\$1" ]; do
|
||||
shift
|
||||
done
|
||||
rm -f "\$1"/meta-data "\$1"/user-data
|
||||
rm -f "\$1"/meta-data "\$1"/user-data "\$1"/network-config
|
||||
EOF
|
||||
}
|
||||
|
||||
@ -64,6 +64,10 @@ fake_userdata_nocloud() {
|
||||
fake_data_nocloud user-data
|
||||
}
|
||||
|
||||
fake_network_config_nocloud() {
|
||||
fake_data_nocloud network-config
|
||||
}
|
||||
|
||||
fake_metadata_aws() {
|
||||
cat > "169.254.169.254.yaml"
|
||||
export WGET_STRIP_PREFIX="/latest/meta-data"
|
||||
|
||||
@ -11,6 +11,7 @@ export CLOUD=nocloud
|
||||
init_tests \
|
||||
set_ephemeral_network_cmdline \
|
||||
set_network_config_network_interfaces \
|
||||
set_network_config_v2_dhcp4 \
|
||||
set_network_config_auto \
|
||||
userdata_user_name \
|
||||
userdata_user_homedir \
|
||||
@ -100,6 +101,26 @@ set_network_config_network_interfaces_body() {
|
||||
cat etc/resolv.conf
|
||||
}
|
||||
|
||||
set_network_config_v2_dhcp4_body() {
|
||||
fake_network_config_nocloud <<-EOF
|
||||
version: 2
|
||||
ethernets:
|
||||
eth1:
|
||||
dhcp4: true
|
||||
EOF
|
||||
|
||||
atf_check \
|
||||
-o match:"rc-update" \
|
||||
-e match:"set_network_interfaces: done" \
|
||||
tiny-cloud boot
|
||||
|
||||
atf_check \
|
||||
-o match:"auto eth1" \
|
||||
-o match:"iface eth1" \
|
||||
-o match:"use dhcp" \
|
||||
cat etc/network/interfaces
|
||||
}
|
||||
|
||||
set_network_config_auto_body() {
|
||||
fake_metadata_nocloud <<-EOF
|
||||
resolv_conf:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user