Use system's configured DNS servers

This patch takes the system's effective DNS servers and updates
common-addresses.yaml to use these servers in the genesis process.
It first attempts to query the DNS servers via nmcli, which is typically
installed on desktop systems and is robust against the use of caching
stub resolvers. If nmcli is not installed (typically on server systems),
it falls back to reading DNS servers from /etc/resolv.conf.

Change-Id: I881e0f87a1699080171ae18f6461097bdee5c242
Story: 2002639
Task: 22295
This commit is contained in:
Frank A. Zdarsky 2018-06-21 20:08:20 +00:00
parent 81a0cab5af
commit a1c06e606d
1 changed files with 22 additions and 0 deletions

View File

@ -133,6 +133,28 @@ export NODE_NET_IFACE=$HOST_IFACE
export TARGET_SITE="demo"
set +x
# Changes DNS servers in common-addresses.yaml to the system's DNS servers
get_dns_servers ()
{
if hash nmcli 2>/dev/null; then
nmcli dev show | awk '/IP4.DNS/ {print $2}' | xargs
else
cat /etc/resolv.conf | awk '/nameserver/ {print $2}' | xargs
fi
}
if grep -q "10.96.0.10" "/etc/resolv.conf"; then
echo "Not changing DNS servers, /etc/resolv.conf already updated."
else
DNS_CONFIG_FILE="../../deployment_files/site/$TARGET_SITE/networks/common-addresses.yaml"
declare -a DNS_SERVERS=($(get_dns_servers))
NS1=${DNS_SERVERS[0]:-8.8.8.8}
NS2=${DNS_SERVERS[1]:-$NS1}
echo "Using DNS servers $NS1 and $NS2."
sed -i "s/8.8.8.8/$NS1/" $DNS_CONFIG_FILE
sed -i "s/8.8.4.4/$NS2/" $DNS_CONFIG_FILE
fi
echo ""
echo "Starting Airship deployment..."
sleep 1