mirror of
https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git
synced 2026-06-21 00:07:16 +03:00
nocloud: configure macifrename for v2 renames
This commit is contained in:
parent
13a2cc6968
commit
90e028231e
@ -67,14 +67,23 @@ set_network_config_v2() {
|
||||
"auto lo" \
|
||||
"iface lo inet loopback" \
|
||||
> "$ETC/network/interfaces"
|
||||
rm -f "$ETC/iftab"
|
||||
|
||||
local iface configured=
|
||||
local iface configured= target_name macaddress
|
||||
for iface in $ethernets; do
|
||||
target_name="$(get_network_config ethernets/$iface/set-name)"
|
||||
macaddress="$(get_network_config ethernets/$iface/match/macaddress)"
|
||||
[ -n "$target_name" ] || target_name="$iface"
|
||||
|
||||
if [ -n "$target_name" ] && [ -n "$macaddress" ]; then
|
||||
printf "%s %s\n" "$target_name" "$macaddress" >> "$ETC/iftab"
|
||||
fi
|
||||
|
||||
case "$(get_network_config ethernets/$iface/dhcp4)" in
|
||||
true|yes)
|
||||
printf "%s\n%s\n\t%s\n\n" \
|
||||
"auto $iface" \
|
||||
"iface $iface" \
|
||||
"auto $target_name" \
|
||||
"iface $target_name" \
|
||||
"use dhcp" >> "$ETC/network/interfaces"
|
||||
configured=1
|
||||
;;
|
||||
@ -89,6 +98,30 @@ set_network_config_v2() {
|
||||
return 0
|
||||
}
|
||||
|
||||
setup_macifrename() {
|
||||
[ -s "$ETC/iftab" ] || return 0
|
||||
|
||||
if ! [ -e "$ETC/init.d/macifrename" ]; then
|
||||
log -i -t "$phase" warning "$ACTION: macifrename service not installed; interface renames will not be applied"
|
||||
return 0
|
||||
fi
|
||||
|
||||
mkdir -p "$ETC/conf.d"
|
||||
if [ -f "$ETC/conf.d/macifrename" ]; then
|
||||
if grep -q '^MACIFRENAME_OPTS=' "$ETC/conf.d/macifrename"; then
|
||||
sed -i -e 's|^MACIFRENAME_OPTS=.*|MACIFRENAME_OPTS="/etc/iftab"|' \
|
||||
"$ETC/conf.d/macifrename"
|
||||
else
|
||||
printf '%s\n' 'MACIFRENAME_OPTS="/etc/iftab"' >> "$ETC/conf.d/macifrename"
|
||||
fi
|
||||
else
|
||||
printf '%s\n' 'MACIFRENAME_OPTS="/etc/iftab"' > "$ETC/conf.d/macifrename"
|
||||
fi
|
||||
|
||||
$MOCK rc-update add macifrename boot
|
||||
$MOCK rc-service macifrename start
|
||||
}
|
||||
|
||||
init__set_network_interfaces() {
|
||||
local interfaces="$(imds meta-data/network-interfaces)"
|
||||
mkdir -p "$ETC"/network
|
||||
@ -99,6 +132,7 @@ init__set_network_interfaces() {
|
||||
elif ! [ -f "$ETC"/network/interfaces ]; then
|
||||
init__set_default_interfaces
|
||||
fi
|
||||
setup_macifrename
|
||||
if ! grep -q dhcp "$ETC"/network/interfaces; then
|
||||
set_resolv_conf
|
||||
fi
|
||||
|
||||
@ -12,6 +12,8 @@ init_tests \
|
||||
set_ephemeral_network_cmdline \
|
||||
set_network_config_network_interfaces \
|
||||
set_network_config_v2_dhcp4 \
|
||||
set_network_config_v2_match_macaddress_set_name_dhcp4 \
|
||||
set_network_config_v2_configures_macifrename_service \
|
||||
set_network_config_auto \
|
||||
userdata_user_name \
|
||||
userdata_user_homedir \
|
||||
@ -121,6 +123,61 @@ set_network_config_v2_dhcp4_body() {
|
||||
cat etc/network/interfaces
|
||||
}
|
||||
|
||||
set_network_config_v2_match_macaddress_set_name_dhcp4_body() {
|
||||
fake_network_config_nocloud <<-EOF
|
||||
version: 2
|
||||
ethernets:
|
||||
net0:
|
||||
match:
|
||||
macaddress: 52:55:55:1d:2a:0b
|
||||
set-name: lima0
|
||||
dhcp4: true
|
||||
EOF
|
||||
|
||||
atf_check \
|
||||
-o match:"rc-update" \
|
||||
-e match:"set_network_interfaces: done" \
|
||||
tiny-cloud boot
|
||||
|
||||
atf_check \
|
||||
-o match:"auto lima0" \
|
||||
-o match:"iface lima0" \
|
||||
-o match:"use dhcp" \
|
||||
cat etc/network/interfaces
|
||||
|
||||
atf_check \
|
||||
-o match:"^lima0 52:55:55:1d:2a:0b$" \
|
||||
cat etc/iftab
|
||||
}
|
||||
|
||||
set_network_config_v2_configures_macifrename_service_body() {
|
||||
mkdir -p etc/conf.d etc/init.d
|
||||
cat > etc/conf.d/macifrename <<-EOF
|
||||
MACIFRENAME_OPTS="/etc/foo"
|
||||
EOF
|
||||
touch etc/init.d/macifrename
|
||||
|
||||
fake_network_config_nocloud <<-EOF
|
||||
version: 2
|
||||
ethernets:
|
||||
net0:
|
||||
match:
|
||||
macaddress: 52:55:55:1d:2a:0b
|
||||
set-name: lima0
|
||||
dhcp4: true
|
||||
EOF
|
||||
|
||||
atf_check \
|
||||
-o match:"rc-update add macifrename boot" \
|
||||
-o match:"rc-service macifrename start" \
|
||||
-e match:"set_network_interfaces: done" \
|
||||
tiny-cloud boot
|
||||
|
||||
atf_check \
|
||||
-o match:'^MACIFRENAME_OPTS="/etc/iftab"$' \
|
||||
cat etc/conf.d/macifrename
|
||||
}
|
||||
|
||||
set_network_config_auto_body() {
|
||||
fake_metadata_nocloud <<-EOF
|
||||
resolv_conf:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user