mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-24 07:51:03 +02:00
oem-exoscale: make DHCP address retrieval more resilient
When retrievent the DHCP IP address (to get user data), two steps were used: the first one waited for one lease file to become present and the second one extracted and validated the server IP address. If for some reason the second step failed, an empty IP was provided (and notably, coreos-setup-environment.service never finishes correctly). To avoid that, we combine the two steps into a loop: for each available lease file, extract the IP and validate it. If it succeeds, return it. If not continue. If nothing was found, restart the same process after sleeping a bit.
This commit is contained in:
parent
e329cfbbd3
commit
a8ca51d73d
@ -2,22 +2,20 @@
|
||||
|
||||
get_dhcp_ip() {
|
||||
local leases_dir="/run/systemd/netif/leases"
|
||||
local found=0
|
||||
while true; do
|
||||
if [[ "$(find "${leases_dir}" -type f -size +1c)" ]]; then
|
||||
break
|
||||
fi
|
||||
sleep .5
|
||||
done
|
||||
|
||||
for leasefile in "${leases_dir}/"*; do
|
||||
for leasefile in $(find "${leases_dir}" -type f -size +1c); do
|
||||
dhcp_server_ip=$(cat $leasefile | awk -F= '/SERVER_ADDRESS/ { print $2 }')
|
||||
if [[ -n "${dhcp_server_ip}" ]]; then
|
||||
metadata_url="http://${dhcp_server_ip}/latest/meta-data/"
|
||||
curl --fail -s "${metadata_url}" >/dev/null
|
||||
if [[ $? -eq 0 ]]; then
|
||||
if curl --fail -s "${metadata_url}" >/dev/null; then
|
||||
echo $dhcp_server_ip
|
||||
found=1
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
[[ $found -eq 0 ]] || break
|
||||
sleep .5
|
||||
done
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user