You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2019/07/11 15:23:33 UTC
[trafficcontrol] branch master updated: CIAB: Dynamically detect
server netmask (#3264)
This is an automated email from the ASF dual-hosted git repository.
dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 594839f CIAB: Dynamically detect server netmask (#3264)
594839f is described below
commit 594839f596b1b3a88839e4fb68a56cfbce926478
Author: Shihta Kuan <Sh...@users.noreply.github.com>
AuthorDate: Thu Jul 11 23:23:28 2019 +0800
CIAB: Dynamically detect server netmask (#3264)
Since CIAB change to use Dynamic DNS, the netmask will also change.
Therefore, it should be dynamically detected.
---
.../cdn-in-a-box/traffic_ops/set-to-ips-from-dns.sh | 19 ++++++++++++++++---
.../traffic_ops_data/servers/010-dns_server.json | 1 -
.../traffic_ops_data/servers/020-db_server.json | 1 -
.../traffic_ops_data/servers/030-enroller_server.json | 1 -
4 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/set-to-ips-from-dns.sh b/infrastructure/cdn-in-a-box/traffic_ops/set-to-ips-from-dns.sh
index cdf86cd..1df6a8f 100755
--- a/infrastructure/cdn-in-a-box/traffic_ops/set-to-ips-from-dns.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/set-to-ips-from-dns.sh
@@ -22,7 +22,7 @@ base_data_dir="/traffic_ops_data"
servers_dir="${base_data_dir}/servers"
profiles_dir="${base_data_dir}/profiles"
-service_names='db trafficops trafficops-perl trafficportal trafficmonitor trafficvault trafficrouter edge mid origin enroller socksproxy client vnc dns'
+service_names='db trafficops trafficops-perl trafficportal trafficmonitor trafficvault trafficrouter enroller dns'
service_domain='infra.ciab.test'
@@ -38,11 +38,22 @@ done
service_ips="${gateway_ip}"
service_ip6s="${gateway_ip6}"
+INTERFACE=$(ip link | awk '/\<UP\>/ && !/LOOPBACK/ {sub(/@.*/, "", $2); print $2}')
+NETMASK=$(route | awk -v INTERFACE=$INTERFACE '$8 ~ INTERFACE && $1 !~ "default" {print $3}')
+DIG_IP_RETRY=10
for service_name in $service_names; do
service_fqdn="${service_name}.${service_domain}"
- service_ip="$(dig +short ${service_fqdn} A)"
+ for (( i=1; i<=DIG_IP_RETRY; i++ )); do
+ service_ip="$(dig +short ${service_fqdn} A)"
+ if [ -z "${service_ip}" ]; then
+ printf "service \"${service_fqdn}\" not found in dns, count=$i, waiting ...\n"
+ sleep 3
+ else
+ break
+ fi
+ done
#
# TODO add a way to determine if a service wasn't built in the Compose,
@@ -54,6 +65,7 @@ for service_name in $service_names; do
if [ -z "${service_ip}" ]; then
# TODO sleep and try again? Up to n times?
printf "setting ips from dns: service \"${service_fqdn}\" not found in dns, skipping!\n"
+ continue
fi
service_ip6="$(dig +short $service_name AAAA)"
@@ -65,12 +77,13 @@ for service_name in $service_names; do
# not all services have server files
printf "setting ips from dns: checking file for dir '${servers_dir}' service '${service_name}'\n"
- service_file="$(ls ${servers_dir}/*${service_name}* 2>/dev/null)"
+ service_file="$(ls ${servers_dir}/*-${service_name}* 2>/dev/null)"
printf "setting ips from dns: trying service file '${service_file}'\n"
if [ -n "${service_file}" ]; then
printf "setting ips from dns: service file '${service_file}' exists, adding IPs\n"
cat "${service_file}" | jq '. + {"ipAddress":"'"${service_ip}"'"}' > "${service_file}.tmp" && mv "${service_file}.tmp" "${service_file}"
cat "${service_file}" | jq '. + {"ipGateway":"'"${gateway_ip}"'"}' > "${service_file}.tmp" && mv "${service_file}.tmp" "${service_file}"
+ cat "${service_file}" | jq '. + {"ipNetmask":"'"${NETMASK}"'"}' > "${service_file}.tmp" && mv "${service_file}.tmp" "${service_file}"
if [ -n "${service_ip6}" ]; then
cat "${service_file}" | jq '. + {"ip6Address":"'"${service_ip6}"'"}' > "${service_file}.tmp" && mv "${service_file}.tmp" "${service_file}"
fi
diff --git a/infrastructure/cdn-in-a-box/traffic_ops_data/servers/010-dns_server.json b/infrastructure/cdn-in-a-box/traffic_ops_data/servers/010-dns_server.json
index 9058fd3..ff24cce 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops_data/servers/010-dns_server.json
+++ b/infrastructure/cdn-in-a-box/traffic_ops_data/servers/010-dns_server.json
@@ -3,7 +3,6 @@
"domainName": "infra.ciab.test",
"cachegroup": "CDN_in_a_Box_Edge",
"interfaceName": "eth0",
- "ipNetmask": "255.255.255.0",
"interfaceMtu": 1500,
"type": "BIND",
"physLocation": "Apachecon North America 2018",
diff --git a/infrastructure/cdn-in-a-box/traffic_ops_data/servers/020-db_server.json b/infrastructure/cdn-in-a-box/traffic_ops_data/servers/020-db_server.json
index 05b3502..39fa73d 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops_data/servers/020-db_server.json
+++ b/infrastructure/cdn-in-a-box/traffic_ops_data/servers/020-db_server.json
@@ -3,7 +3,6 @@
"domainName": "infra.ciab.test",
"cachegroup": "CDN_in_a_Box_Edge",
"interfaceName": "eth0",
- "ipNetmask": "255.255.255.0",
"interfaceMtu": 1500,
"type": "TRAFFIC_OPS_DB",
"physLocation": "Apachecon North America 2018",
diff --git a/infrastructure/cdn-in-a-box/traffic_ops_data/servers/030-enroller_server.json b/infrastructure/cdn-in-a-box/traffic_ops_data/servers/030-enroller_server.json
index d4618c9..4070e90 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops_data/servers/030-enroller_server.json
+++ b/infrastructure/cdn-in-a-box/traffic_ops_data/servers/030-enroller_server.json
@@ -3,7 +3,6 @@
"domainName": "infra.ciab.test",
"cachegroup": "CDN_in_a_Box_Edge",
"interfaceName": "eth0",
- "ipNetmask": "255.255.255.0",
"interfaceMtu": 1500,
"type": "ENROLLER",
"physLocation": "Apachecon North America 2018",