|
| 1 | +{{- define "common_keystone_endpoints" }} |
| 2 | +#!/bin/bash |
| 3 | + |
| 4 | +# Copyright 2017 Pete Birley |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | + |
| 18 | +set -ex |
| 19 | + |
| 20 | +# Get Service ID |
| 21 | +OS_SERVICE_ID=$( openstack service list -f csv --quote none | \ |
| 22 | + grep ",${OS_SERVICE_NAME},${OS_SERVICE_TYPE}$" | \ |
| 23 | + sed -e "s/,${OS_SERVICE_NAME},${OS_SERVICE_TYPE}//g" ) |
| 24 | + |
| 25 | +# Get Endpoint ID if it exists |
| 26 | +OS_ENDPOINT_ID=$( openstack endpoint list -f csv --quote none | \ |
| 27 | + grep "^[a-z0-9]*,${OS_REGION_NAME},${OS_SERVICE_NAME},${OS_SERVICE_TYPE},True,${OS_SVC_ENDPOINT}," | \ |
| 28 | + awk -F ',' '{ print $1 }' ) |
| 29 | + |
| 30 | +# Making sure only a single endpoint exists for a service within a region |
| 31 | +if [ "$(echo $OS_ENDPOINT_ID | wc -w)" -gt "1" ]; then |
| 32 | + echo "More than one endpoint found, cleaning up" |
| 33 | + for ENDPOINT_ID in $OS_ENDPOINT_ID; do |
| 34 | + openstack endpoint delete ${ENDPOINT_ID} |
| 35 | + done |
| 36 | + unset OS_ENDPOINT_ID |
| 37 | +fi |
| 38 | + |
| 39 | +# Determine if Endpoint needs updated |
| 40 | +if [[ ${OS_ENDPOINT_ID} ]]; then |
| 41 | + OS_ENDPOINT_URL_CURRENT=$(openstack endpoint show ${OS_ENDPOINT_ID} --f value -c url) |
| 42 | + if [ "${OS_ENDPOINT_URL_CURRENT}" == "${OS_SERVICE_ENDPOINT}" ]; then |
| 43 | + echo "Endpoints Match: no action required" |
| 44 | + OS_ENDPOINT_UPDATE="False" |
| 45 | + else |
| 46 | + echo "Endpoints Dont Match: removing existing entries" |
| 47 | + openstack endpoint delete ${OS_ENDPOINT_ID} |
| 48 | + OS_ENDPOINT_UPDATE="True" |
| 49 | + fi |
| 50 | +else |
| 51 | + OS_ENDPOINT_UPDATE="True" |
| 52 | +fi |
| 53 | + |
| 54 | +# Update Endpoint if required |
| 55 | +if [[ "${OS_ENDPOINT_UPDATE}" == "True" ]]; then |
| 56 | + OS_ENDPOINT_ID=$( openstack endpoint create -f value -c id \ |
| 57 | + --region="${OS_REGION_NAME}" \ |
| 58 | + "${OS_SERVICE_ID}" \ |
| 59 | + ${OS_SVC_ENDPOINT} \ |
| 60 | + "${OS_SERVICE_ENDPOINT}" ) |
| 61 | +fi |
| 62 | + |
| 63 | +# Display the Endpoint |
| 64 | +openstack endpoint show ${OS_ENDPOINT_ID} |
| 65 | +{{- end }} |
0 commit comments