diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 4fa5d38..b6c282a 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -23,33 +23,77 @@ # # Environment Configuration # -# AMQP1_SERVICE - identifies the messaging backend to use. Should be -# one of 'qpid' for broker backend, 'qpid-dual' for hybrid router-broker, or -# 'qpid-hybrid' for keeping Rabbit for notifcations. -# @TODO(kgiusti) add qpid-dispatch, etc +# AMQP1_SERVICE - This plugin can deploy one of several different +# message bus configurations. This variable identifies the message +# bus configuration that will be used. Should be one of: +# 'qpid' - use the qpidd broker for both RPC and Notifications +# 'qpid-dual' - use qpidd for Notifications, qdrouterd for RPC +# 'qpid-hybrid' - use rabbitmq for Notifications, qdrouterd for RPC +# 'external' - use a pre-provisioned message bus. This prevents +# this plugin from creating the message bus. Instead it assumes +# the bus has already been set up and simply connects to it. +# AMQP1_RPC_TRANSPORT_URL - Transport URL to use for RPC service +# AMQP1_NOTIFY_TRANSPORT_URL - Transport URL to use for Notification +# service. +# +# If the above AMQP1_*_TRANSPORT_URL env vars are not defined, this +# plugin will construct these urls using the following env vars: +# # AMQP1_HOST - the host used to connect to the messaging service. -# Defaults to 127.0.0.1 -# AMQP1_{DEFAULT_PORT, NOTIFY_PORT} - the port used to connect to the messaging -# service. Defaults to 5672 and 5671. -# AMQP1_{USERNAME,PASSWORD} - for authentication with AMQP1_HOST +# Defaults to $SERVICE_HOST +# AMQP1_{DEFAULT_PORT, NOTIFY_PORT} - the port used to connect to the +# messaging service. AMQP1_NOTIFY_PORT defaults to 5672. +# AMQP_DEFAULT_PORT also defaults to 5672 for the 'qpid' +# configuration, otherwise 45672 to avoid port# clashes with the +# Notification port. +# AMQP1_{USERNAME,PASSWORD} - for authentication with AMQP1_HOST (optional) +# +# The RPC transport url will be defined as: +# "amqp://$AMQP1_USERNAME:$AMQP1_PASSWORD@$AMQP1_HOST:${AMQP1_DEFAULT_PORT}/" +# +# The notify transport url will be defined as: +# "amqp://$AMQP1_USERNAME:$AMQP1_PASSWORD@$AMQP1_HOST:${AMQP1_NOTIFY_PORT}/" # -# builds default transport url string -function _get_amqp1_default_transport_url { - if [ -z "$AMQP1_USERNAME" ]; then - echo "amqp://$AMQP1_HOST:${AMQP1_DEFAULT_PORT}/" +# parse URL, extracting host, port, username, password +function _parse_transport_url { + local uphp # user+password+host+port + local user # username + local passwd # password + local hostport # host+port + local host # hostname + local port # port # + + # extract [user:pass@]host:port + uphp=$(echo $1 | sed -e "s#^[^:]*://\([^/]*\).*#\1#") + # parse out username + password if present: + user="" + passwd="" + if [[ "$uphp" =~ .+@.+ ]]; then + local passhostport + user=$(echo $uphp | sed -e "s#^\([^:]*\).*#\1#") + passhostport=$(echo $uphp | sed -e "s#$user:##") + passwd=$(echo $passhostport | sed -e "s#^\([^@]*\).*#\1#") + hostport=$(echo $passhostport | sed -e "s#$passwd@##") else - echo "amqp://$AMQP1_USERNAME:$AMQP1_PASSWORD@$AMQP1_HOST:${AMQP1_DEFAULT_PORT}/" + hostport=$uphp fi + host=$(echo $hostport | cut -d: -f1) + port=$(echo $hostport | cut -d: -f2) + + # field 1 2 3 4 + echo "$host $port $user $passwd" } -# builds notify transport url string + +# default transport url string +function _get_amqp1_default_transport_url { + echo "$AMQP1_RPC_TRANSPORT_URL" +} + +# notify transport url string function _get_amqp1_notify_transport_url { - if [ -z "$AMQP1_USERNAME" ]; then - echo "amqp://$AMQP1_HOST:${AMQP1_NOTIFY_PORT}/" - else - echo "amqp://$AMQP1_USERNAME:$AMQP1_PASSWORD@$AMQP1_HOST:${AMQP1_NOTIFY_PORT}/" - fi + echo "$AMQP1_NOTIFY_TRANSPORT_URL" } # install packages necessary for support of the oslo.messaging AMQP @@ -81,6 +125,9 @@ function _remove_pyngus { # Set up the various configuration files used by the qpidd broker function _configure_qpid { + local url + url=$(_parse_transport_url $1) + # the location of the configuration files have changed since qpidd 0.14 local qpid_conf_file if [ -e /etc/qpid/qpidd.conf ]; then @@ -95,7 +142,8 @@ function _configure_qpid { sudo chmod o+r $qpid_conf_file # force the ACL file to a known location - local qpid_acl_file=/etc/qpid/qpidd.acl + local qpid_acl_file + qpid_acl_file=/etc/qpid/qpidd.acl if [ ! -e $qpid_acl_file ]; then sudo mkdir -p -m 755 `dirname $qpid_acl_file` sudo touch $qpid_acl_file @@ -103,12 +151,9 @@ function _configure_qpid { fi echo "acl-file=$qpid_acl_file" | sudo tee $qpid_conf_file - # map broker port for dual backend config - if [ "$AMQP1_SERVICE" == "qpid-dual" ]; then - echo "port=${AMQP1_NOTIFY_PORT}" | sudo tee --append $qpid_conf_file - fi - - if [ -z "$AMQP1_USERNAME" ]; then + local username + username=$(echo "$url" | cut -d' ' -f3) + if [ -z "$username" ]; then # no QPID user configured, so disable authentication # and access control echo "auth=no" | sudo tee --append $qpid_conf_file @@ -117,19 +162,22 @@ acl allow all all EOF else # Configure qpidd to use PLAIN authentication, and add - # AMQP1_USERNAME to the ACL: + # $username to the ACL: echo "auth=yes" | sudo tee --append $qpid_conf_file - if [ -z "$AMQP1_PASSWORD" ]; then - read_password AMQP1_PASSWORD "ENTER A PASSWORD FOR QPID USER $AMQP1_USERNAME" + local passwd + passwd=$(echo "$url" | cut -d' ' -f4) + if [ -z "$passwd" ]; then + read_password password "ENTER A PASSWORD FOR QPID USER $username" fi - # Create ACL to allow $AMQP1_USERNAME full access + # Create ACL to allow $username full access cat <