#!/usr/bin/python """Get hostnames for RHUI 3 servers in AWS """ from __future__ import print_function import socket import subprocess import sys if subprocess.call("which aws &> /dev/null", shell=True): sys.stderr.write("The aws client is not available. Please install package awscli.\n") sys.exit(1) if subprocess.call("aws configure get aws_access_key_id &> /dev/null", shell=True): sys.stderr.write("The aws client is not configured. Please run `aws configure'.\n") sys.exit(1) CMD = "aws ec2 describe-regions --all-regions --query 'Regions[].{Name:RegionName}' --output text" CMD_OUT = subprocess.check_output(CMD, shell=True) REGIONS = CMD_OUT.decode().splitlines() REGIONS.sort() HOST_TEMPLATE = "rhui3.%s.aws.ce.redhat.com" LEGEND = "REGION_ID\tIP address of %s" % HOST_TEMPLATE print(LEGEND % "REGION_ID") for region in REGIONS: print("%s\t%s" % (region, socket.gethostbyname(HOST_TEMPLATE % region)))