Skip to content

Instantly share code, notes, and snippets.

@therve
Forked from jistr/get-role-ports.sh
Last active July 12, 2019 15:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save therve/1da76e07647d303142a9cd6af1489522 to your computer and use it in GitHub Desktop.
Save therve/1da76e07647d303142a9cd6af1489522 to your computer and use it in GitHub Desktop.
Fetch port information from a TripleO overcloud Heat stack
#!/bin/bash
# This script will fetch IP addresses assigned to ports on servers belonging
# to a particular role in the overcloud Heat stack. It's not optimized for everyday
# use and takes a while to complete, as it makes many Heat queries. This does not include
# e.g. VIPs.
# Run this script for each role you are interested in. Example usage:
# $ source stackrc
# $ bash get-role-ports.sh overcloud Controller
STACK="$1"
ROLE="$2"
ROLE_ID=$(openstack stack resource show -c physical_resource_id -f value overcloud ${ROLE}IpListMap)
HOSTNAMES=$(openstack stack show -c parameters -f json $ROLE_ID | jq -r '.parameters.ServiceHostnameList' | python -c 'import sys; print " ".join([str(i) for i in eval(sys.stdin.read())])')
JSON_MAP=$(openstack stack resource show -f json -c attributes overcloud ${ROLE}IpListMap)
count=0
for HOST in $HOSTNAMES; do
echo $HOST
echo $JSON_MAP | jq -r --arg INDEX "$count" '.attributes.net_ip_map | to_entries | map(" \(.key) \(.value[$INDEX | tonumber])") | .[]'
((count++))
done
#!/bin/bash
# This script will fetch IP addresses assigned to ports on on the top-level of overcloud
# heat stack (e.g. VIPs). Example usage:
# $ source stackrc
# $ bash get-top-level-ports.sh overcloud
set -euo pipefail
STACK="$1"
PORT_RES_NAMES=$(openstack stack resource list -f json $STACK | jq -r 'map(select(.resource_type | test("Port$"))) | .[].resource_name' | sort)
for PORT_RES_NAME in $PORT_RES_NAMES; do
PORT_IP=$(openstack stack resource show -f json $STACK $PORT_RES_NAME | jq -r '.attributes.ip_address // .attributes.fixed_ips[0].ip_address')
echo "$PORT_RES_NAME $PORT_IP"
done
(undercloud) [stack@undercloud ~]$ ./get-top-level-ports.sh overcloud
ControlVirtualIP 192.168.24.9
InternalApiVirtualIP 172.16.2.10
PublicVirtualIP 172.20.0.13
RedisVirtualIP 172.16.2.12
StorageMgmtVirtualIP 172.16.3.6
StorageVirtualIP 172.16.1.12
(undercloud) [stack@undercloud ~]$ ./get-role-ports.sh overcloud Controller
overcloud-controller-0
ctlplane 192.168.24.67
external 172.21.0.8
internal_api 172.16.0.13
management 192.168.24.67
storage 172.18.0.11
storage_mgmt 172.19.0.5
tenant 172.17.0.12
overcloud-controller-1
ctlplane 192.168.24.69
external 172.21.0.10
internal_api 172.16.0.10
management 192.168.24.69
storage 172.18.0.8
storage_mgmt 172.19.0.7
tenant 172.17.0.17
overcloud-controller-2
ctlplane 192.168.24.65
external 172.21.0.13
internal_api 172.16.0.21
management 192.168.24.65
storage 172.18.0.20
storage_mgmt 172.19.0.9
tenant 172.17.0.16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment