rut-prod-ops/scripts/get_host_ip.sh

34 lines
836 B
Bash
Raw Normal View History

#!/usr/bin/env bash
SERVERNAME=$1
export OS_CLOUD=sto4-rut
OLDIPV4=$(dig -t a +short $SERVERNAME)
OLDIPV6=$(dig -t aaaa +short $SERVERNAME)
# Pull the JSON for the server with the matching name
SERVER_JSON="$(openstack server list -f json \
| jq -r ".[] | select(.Name==\"$SERVERNAME\")")"
# Extract the public network list as a space-separated array
ADDRESSES="$(echo "$SERVER_JSON" \
| jq -r '.Networks.public[]')"
# Initialize empty variables
IPV4=""
IPV6=""
# Loop through each address in the 'public' list
# - If it contains a colon (:), assume it's IPv6
# - Otherwise, assume it's IPv4
for addr in $ADDRESSES; do
if [[ "$addr" == *:* ]]; then
IPV6="$addr"
else
IPV4="$addr"
fi
done
echo "SS IPv4: $IPV4" "DNS IPv4: $OLDIPV4"
echo "SS IPv6: $IPV6" "DNS IPv6: $OLDIPV6"