Add options to support varied stack names

This change adds the ability to generate an inventory file and
ssh config when using stack names other than "overcloud".

The script still defaults to "overcloud" if the options are
not specified.

Also now sets the variable $tripleo_ip_address to "localhost"
if the localhost option is specified. Prior to this change,
specifying -l would leave the variable empty which would fail
the first if statement and only give you the script usage.

Change-Id: Ia7fc1bc552dcf7a8ece1ad5b79153e0d87a39537
This commit is contained in:
Matt Wisch 2017-08-01 14:04:22 -04:00
parent 2dd7fe17d1
commit 4c34cea819

View File

@ -4,20 +4,35 @@
function usage function usage
{ {
echo "Usage: generate_tripleo_hostfile.sh [-t <tripleo_ip_address> [-l | --localhost]] | [-h | --help]" echo "Usage: generate_tripleo_hostfile.sh"
echo " [-t | --tripleo_ip_address <tripleo_ip_address> [-l | --localhost]]"
echo " [-o | --overcloud_stack_name <overcloud_stack_name>]"
echo " [-c | --ceph_stack_name <ceph_stack_name>]"
echo " [-h | --help]"
echo "Generates ssh config file to use with an TripleO undercloud host as a jumpbox and creates ansible inventory file." echo "Generates ssh config file to use with an TripleO undercloud host as a jumpbox and creates ansible inventory file."
} }
uncomment_localhost=false uncomment_localhost=false
tripleo_ip_address= tripleo_ip_address=
overcloud_name="overcloud"
ceph_stack_name=$overcloud_name
while [ "$1" != "" ]; do while [ "$1" != "" ]; do
case $1 in case $1 in
-l | --localhost ) uncomment_localhost=true -l | --localhost ) uncomment_localhost=true
tripleo_ip_address="localhost"
;; ;;
-t | --tripleo_ip_address ) -t | --tripleo_ip_address )
shift shift
tripleo_ip_address=$1 tripleo_ip_address=$1
;; ;;
-o | --overcloud_stack_name )
shift
overcloud_name=$1
;;
-c | --ceph_stack_name )
shift
ceph_stack_name=$1
;;
-h | --help ) usage -h | --help ) usage
exit exit
;; ;;
@ -44,14 +59,14 @@ if [[ "${tripleo_ip_address}" == "localhost" ]]; then
fi fi
# Check if there are any clouds built. # Check if there are any clouds built.
clouds=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack stack list | grep -i -E 'overcloud'") clouds=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack stack list | grep -i -E '$overcloud_name'")
if [ ${#clouds} -gt 0 ]; then if [ ${#clouds} -gt 0 ]; then
nodes=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack server list 2>/dev/null | grep -i -E 'active|running'") nodes=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack server list 2>/dev/null | grep -i -E 'active|running'")
if [ ${#nodes} -lt 1 ]; then if [ ${#nodes} -lt 1 ]; then
echo "ERROR: nova list failed to execute properly, please check the openstack-nova-api on the undercloud." echo "ERROR: nova list failed to execute properly, please check the openstack-nova-api on the undercloud."
exit 1 exit 1
fi fi
controller_id=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack stack resource show overcloud Controller > >(grep physical_resource_id) 2>/dev/null" | awk '{print $4}') controller_id=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack stack resource show $overcloud_name Controller > >(grep physical_resource_id) 2>/dev/null" | awk '{print $4}')
if [ ${#controller_id} -lt 3 ]; then if [ ${#controller_id} -lt 3 ]; then
echo "Error: Controller ID is not reporting correctly. Please see check the openstack-heat-api on the undercloud." echo "Error: Controller ID is not reporting correctly. Please see check the openstack-heat-api on the undercloud."
exit 1 exit 1
@ -62,7 +77,7 @@ if [ ${#clouds} -gt 0 ]; then
exit 1 exit 1
fi fi
blockstorage_id=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack stack resource show overcloud BlockStorage > >(grep physical_resource_id) 2>/dev/null" | awk '{print $4}') blockstorage_id=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack stack resource show $overcloud_name BlockStorage > >(grep physical_resource_id) 2>/dev/null" | awk '{print $4}')
if [ ${#blockstorage_id} -lt 3 ]; then if [ ${#blockstorage_id} -lt 3 ]; then
echo "Info: No BlockStorage resources." echo "Info: No BlockStorage resources."
else else
@ -71,7 +86,7 @@ if [ ${#clouds} -gt 0 ]; then
echo "Info: No BlockStorage resources." echo "Info: No BlockStorage resources."
fi fi
fi fi
objectstorage_id=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack stack resource show overcloud ObjectStorage > >(grep physical_resource_id) 2>/dev/null" | awk '{print $4}') objectstorage_id=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack stack resource show $overcloud_name ObjectStorage > >(grep physical_resource_id) 2>/dev/null" | awk '{print $4}')
if [ ${#objectstorage_id} -lt 3 ]; then if [ ${#objectstorage_id} -lt 3 ]; then
echo "Info: No ObjectStorage resources." echo "Info: No ObjectStorage resources."
else else
@ -80,7 +95,7 @@ if [ ${#clouds} -gt 0 ]; then
echo "Info: No ObjectStorage resources." echo "Info: No ObjectStorage resources."
fi fi
fi fi
cephstorage_id=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack stack resource show overcloud CephStorage > >(grep physical_resource_id) 2>/dev/null" | awk '{print $4}') cephstorage_id=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack stack resource show $ceph_stack_name CephStorage > >(grep physical_resource_id) 2>/dev/null" | awk '{print $4}')
if [ ${#cephstorage_id} -lt 3 ]; then if [ ${#cephstorage_id} -lt 3 ]; then
echo "Info: No CephStorage resources." echo "Info: No CephStorage resources."
else else
@ -89,7 +104,7 @@ if [ ${#clouds} -gt 0 ]; then
echo "Info: No CephStorage resources." echo "Info: No CephStorage resources."
fi fi
fi fi
compute_id=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack stack resource show overcloud Compute > >(grep physical_resource_id) 2>/dev/null" | awk '{print $4}') compute_id=$(ssh -tt -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" stack@${tripleo_ip_address} ". ~/stackrc; openstack stack resource show $overcloud_name Compute > >(grep physical_resource_id) 2>/dev/null" | awk '{print $4}')
if [ ${#compute_id} -lt 3 ]; then if [ ${#compute_id} -lt 3 ]; then
echo "Info: No compute resources" echo "Info: No compute resources"
else else