#!/bin/bash # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # # Sets up the messaging backend service needed by the AMQP 1.0 # transport (amqp://) # # Environment Configuration # # 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. # A virtual host may be added at run time. # AMQP1_NOTIFY_TRANSPORT_URL - Transport URL to use for Notification # service. A virtual host may be added at run time. # # 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 $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}/" # # 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 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" } # default transport url string function _get_amqp1_default_transport_url { local virtual_host virtual_host=$1 echo "$AMQP1_RPC_TRANSPORT_URL/$virtual_host" } # notify transport url string function _get_amqp1_notify_transport_url { local virtual_host virtual_host=$1 if [ "$AMQP1_NOTIFY" == "rabbit" ]; then echo $(_get_rabbit_notification_url $virtual_host) else echo "$AMQP1_NOTIFY_TRANSPORT_URL/$virtual_host" fi } # override the default in devstack as it forces all non-rabbit # backends to fail... function _amqp1_add_vhost { if [ "$AMQP1_NOTIFY" == "rabbit" ]; then _rabbit_rpc_backend_add_vhost $@ fi # no configuration necessary for AMQP 1.0 backend return 0 } # install packages necessary for support of the oslo.messaging AMQP # 1.0 driver function _install_pyngus { # Install pyngus client API if is_fedora; then # TODO(kgiusti) due to a bug in the way pip installs wheels, # do not let pip install the proton python bindings as it will # put them in the wrong path: # https://github.com/pypa/pip/issues/2940 install_package python-qpid-proton elif is_ubuntu; then # ditto install_package python-qpid-proton fi pip_install_gr pyngus } # remove packages used by oslo.messaging AMQP 1.0 driver function _remove_pyngus { # TODO(kgiusti) no way to pip uninstall? # pip_install_gr 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 qpid_conf_file=/etc/qpid/qpidd.conf elif [ -e /etc/qpidd.conf ]; then qpid_conf_file=/etc/qpidd.conf else exit_distro_not_supported "qpidd.conf file not found!" fi # ensure that the qpidd service can read its config sudo chmod o+r $qpid_conf_file # force the ACL file to a known location 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 sudo chmod o+r $qpid_acl_file fi echo "acl-file=$qpid_acl_file" | sudo tee $qpid_conf_file 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 cat <