Merge "os-net-config: add configure_safe_defaults"
This commit is contained in:
commit
93d18be0f9
@ -48,9 +48,58 @@ function ping_metadata_ip() {
|
||||
fi
|
||||
}
|
||||
|
||||
function configure_safe_defaults() {
|
||||
|
||||
[[ $? == 0 ]] && return 0
|
||||
|
||||
cat > /etc/os-net-config/dhcp_all_interfaces.yaml <<EOF_CAT
|
||||
# This file is an autogenerated safe defaults file for os-net-config
|
||||
# which runs DHCP on all discovered interfaces to ensure connectivity
|
||||
# back to the undercloud for updates
|
||||
network_config:
|
||||
EOF_CAT
|
||||
|
||||
for iface in $(ls /sys/class/net | grep -v ^lo$); do
|
||||
local mac_addr_type="$(cat /sys/class/net/${iface}/addr_assign_type)"
|
||||
if [ "$mac_addr_type" != "0" ]; then
|
||||
echo "Device has generated MAC, skipping."
|
||||
else
|
||||
ip link set dev $iface up &>/dev/null
|
||||
HAS_LINK="$(cat /sys/class/net/${iface}/carrier)"
|
||||
|
||||
TRIES=10
|
||||
while [ "$HAS_LINK" == "0" -a $TRIES -gt 0 ]; do
|
||||
HAS_LINK="$(cat /sys/class/net/${iface}/carrier)"
|
||||
if [ "$HAS_LINK" == "1" ]; then
|
||||
break
|
||||
else
|
||||
sleep 1
|
||||
fi
|
||||
TRIES=$(( TRIES - 1 ))
|
||||
done
|
||||
if [ "$HAS_LINK" == "1" ] ; then
|
||||
cat >> /etc/os-net-config/dhcp_all_interfaces.yaml <<EOF_CAT
|
||||
-
|
||||
type: interface
|
||||
name: $iface
|
||||
use_dhcp: true
|
||||
EOF_CAT
|
||||
fi
|
||||
fi
|
||||
done
|
||||
os-net-config -c /etc/os-net-config/dhcp_all_interfaces.yaml -v --detailed-exit-codes --cleanup
|
||||
RETVAL=$?
|
||||
if [[ $RETVAL == 2 ]]; then
|
||||
ping_metadata_ip
|
||||
elif [[ $RETVAL != 0 ]]; then
|
||||
echo "ERROR: configuration of safe defaults failed."
|
||||
fi
|
||||
}
|
||||
|
||||
NET_CONFIG=$(os-apply-config --key os_net_config --type raw --key-default '')
|
||||
|
||||
if [ -n "$NET_CONFIG" ]; then
|
||||
trap configure_safe_defaults EXIT
|
||||
os-net-config -c /etc/os-net-config/config.json -v --detailed-exit-codes
|
||||
RETVAL=$?
|
||||
if [[ $RETVAL == 2 ]]; then
|
||||
|
Loading…
Reference in New Issue
Block a user