new hooks: identity-service-relation-{joined, changed} to support relations with a Keystone service

This commit is contained in:
Adam Gandelman 2011-12-08 18:13:59 -08:00
parent fea3b472cf
commit 00e71b1bf1
4 changed files with 67 additions and 2 deletions

View File

@ -1,6 +1,8 @@
#!/bin/bash
SERVICES="glance-api glance-registry"
PACKAGES="glance python-mysqldb python-swift python-keystone"
GLANCE_REGISTRY_CONF=$(config-get registry-config)
GLANCE_API_CONF=$(config-get api-config)
@ -47,6 +49,27 @@ function glance_ctl {
done
}
function update_pipeline {
# updates pipeline middleware definitions in api-paste.ini
local pipeline="$1"
local new="$2"
local config="$3"
case $config in
"api") local api_conf=$GLANCE_API_CONF ;;
"registry") local api_conf=$GLANCE_REGISTRY_CONF ;;
*) juju-log "ERROR: update_pipeline: invalid config=$config" && exit 1 ;;
esac
local tag="\[pipeline:$pipeline\]"
if ! grep -q "$tag" $api_conf ; then
juju-log "ERROR: update_pipeline: pipeline not found: $pipeline"
return 1
fi
juju-log "Updating pipeline:$pipeline in $api_conf"
sed -i "/$tag/, +1 s/\(pipeline = \).*/\1$new/g" $api_conf
}
function set_or_update {
# This handles configuration of both api and registry server
# until LP #806241 is resolved. Until then, $3 is either
@ -56,6 +79,8 @@ function set_or_update {
VALUE=$2
[[ $3 == "api" ]] && CONF=$GLANCE_API_CONF
[[ $3 == "registry" ]] && CONF=$GLANCE_REGISTRY_CONF
[[ -z $CONF ]] && juju-log "ERROR: set_or_update: No config file specified" &&
exit 1
[[ -z $KEY ]] && exit 1
[[ -z $VALUE ]] && exit 1
cat $CONF | grep "$KEY = $VALUE" >/dev/null \

View File

@ -16,7 +16,7 @@ function install_hook {
add_ppa
apt-get update || exit 1
apt-get -y install glance python-mysqldb python-swift || exit 1
apt-get -y install $PACKAGES || exit 1
glance_ctl all stop
@ -77,6 +77,42 @@ function object-store_changed {
glance_ctl glance-api restart
}
function keystone_joined {
# advertise our API endpoint to keystone
url="http://$(unit-get private-address):9292/v1.1/"
relation-set service="glance" \
region="RegionOne" public_url=$url admin_url=$url internal_url=$url
}
function keystone_changed {
# we hopefully get a token in return. configure middleware accordingly
token=$(relation-get admin_token)
service_port=$(relation-get service_port)
auth_port=$(relation-get auth_port)
[[ -z "$token" ]] || [[ -z "$service_port" ]] || [[ -z "$auth_port" ]] &&
juju-log "keystone_changed: Peer not ready" && exit 0
[[ "$token" == "-1" ]] &&
juju-log "keystone_changed: admin token error" && exit 1
juju-log "keystone_changed: Acquired admin. token"
keystone_host=`dig +short +search $(relation-get private-address)`
# update the pipeline settings in both configs
update_pipeline "glance-api" \
"versionnegotiation authtoken auth-context apiv1app" "api"
update_pipeline "glance-registry" \
"authtoken auth-context registryapp" "registry"
for i in api registry ; do
set_or_update "service_host" "$keystone_host" $i
set_or_update "service_port" "$service_port" $i
set_or_update "auth_host" "$keystone_host" $i
set_or_update "auth_port" "$auth_port" $i
set_or_update "auth_uri" "http://$keystone_host:$service_port/" $i
set_or_update "admin_token" "$token" $i
done
glance_ctl all restart
}
case $ARG0 in
"start"|"stop") glance_ctl all $ARG0 ;;
"install") install_hook ;;
@ -86,5 +122,7 @@ case $ARG0 in
"image-service-relation-changed") exit 0 ;;
"object-store-relation-joined") exit 0 ;;
"object-store-relation-changed") object-store_changed ;;
"identity-service-relation-joined") keystone_joined ;;
"identity-service-relation-changed") keystone_changed ;;
esac

View File

@ -14,3 +14,5 @@ requires:
interface: mysql-shared
object-store:
interface: swift
identity-service:
interface: keystone

View File

@ -1 +1 @@
31
45