From baa0f217bb891aaa65e7c1031f384397b522952f Mon Sep 17 00:00:00 2001 From: Adam Gandelman Date: Tue, 5 Jul 2011 15:24:11 -0700 Subject: [PATCH] Add hooks for shared-db and amqp joined + changed --- hooks/amqp-relation-changed | 1 + hooks/amqp-relation-joined | 1 + hooks/nova-cloud-controller-common | 9 ++++- hooks/nova-cloud-controller-relations | 48 +++++++++++++++++++++++---- hooks/shared-db-relation-changed | 1 + hooks/shared-db-relation-joined | 1 + metadata.yaml | 2 +- 7 files changed, 55 insertions(+), 8 deletions(-) create mode 120000 hooks/amqp-relation-changed create mode 120000 hooks/amqp-relation-joined create mode 120000 hooks/shared-db-relation-changed create mode 120000 hooks/shared-db-relation-joined diff --git a/hooks/amqp-relation-changed b/hooks/amqp-relation-changed new file mode 120000 index 00000000..ed780797 --- /dev/null +++ b/hooks/amqp-relation-changed @@ -0,0 +1 @@ +nova-cloud-controller-relations \ No newline at end of file diff --git a/hooks/amqp-relation-joined b/hooks/amqp-relation-joined new file mode 120000 index 00000000..ed780797 --- /dev/null +++ b/hooks/amqp-relation-joined @@ -0,0 +1 @@ +nova-cloud-controller-relations \ No newline at end of file diff --git a/hooks/nova-cloud-controller-common b/hooks/nova-cloud-controller-common index c1c06ddd..c43107e8 100755 --- a/hooks/nova-cloud-controller-common +++ b/hooks/nova-cloud-controller-common @@ -1,6 +1,13 @@ #!/bin/bash SERVICES="nova-api nova-network nova-objectstore nova-scheduler" NOVA_CONF="/etc/nova/nova.conf" +RABBIT_USER="nova-rabbit" + +DB_USER="nova" +NOVA_DB="nova" + +DEFAULT_ETH=$(ip route | grep default | awk '{ print $5 }') +IP=$(ifconfig $DEFAULT_ETH | grep 'inet addr' | awk '{ print $2 }' | cut -d: -f2) function set_or_update { # set or update a key=value config option in nova.conf @@ -24,7 +31,7 @@ function nova_ctl { CTL=$1 fi ACTION=$2 - if [[ -z $2 ]] || [[ -z $ACTION ]] ; then + if [[ -z $CTL ]] || [[ -z $ACTION ]] ; then ensemble-log "ERROR nova_ctl: Not enough arguments" exit 1 fi diff --git a/hooks/nova-cloud-controller-relations b/hooks/nova-cloud-controller-relations index 05328b59..e6d7be8f 100755 --- a/hooks/nova-cloud-controller-relations +++ b/hooks/nova-cloud-controller-relations @@ -20,24 +20,60 @@ function install_hook { } function amqp_joined { - # we request a username+password on the rabbit queue - # and store it in nova.conf. our response is its IP + # we request a username on the rabbit queue + # and store it in nova.conf. our response is its IP + PASSWD # but we configure that in _changed ensemble-log "amqp_joined: requesting credentials for $RABBIT_USER" + echo "amqp_joined: requesting credentials for $RABBIT_USER" relation-set username=$RABBIT_USER - relation-set password=$RABBIT_PASSWD } function amqp_changed { # server creates our credentials and tells us where - # to connect + # to connect. for now, using default vhost '/' RABBIT_HOST=`relation-get ip` + RABBIT_PASSWORD=`relation-get password` + if [[ -z $RABBIT_HOST ]] || [[ -z $RABBIT_PASSWORD ]] ; then + echo "amqp_changed: RABBIT_HOST not set. Peer not ready? Exit 0 and retry" + exit 0 + fi + echo "amqp_changed: Setting rabbit config in nova.conf: $RABBIT_HOST $RABBIT_USER $RABBIT_PASSWORD" + set_or_update rabbit_host $RABBIT_HOST + set_or_update rabbit_user $RABBIT_USER + set_or_update rabbit_password $RABBIT_PASSWORD + nova_ctl all restart +} + +function db_joined { + # tell mysql provider which database we want. it will create it and give us + # credentials + ensemble-log "db_joined: requesting database access to $NOVA_DB for $DB_USER@$IP" + relation-set database=$NOVA_DB + relation-set username=$DB_USER + relation-set hostname=`uname -n` + relation-set ip=$IP +} + +function db_changed { + DB_HOST=`relation-get db_host` + DB_PASSWORD=`relation-get password` + if [[ -z $DB_HOST ]] || [[ -z $DB_PASSWORD ]] ; then + echo "db_changed: DB_HOST || DB_PASSWORD not yet set. Exit 0 and retry" + exit 0 + fi + echo "db_changed: Configuring nova.conf for access to $NOVA_DB" + set_or_update sql_connection "mysql://$DB_USER:$DB_PASSWORD@$DB_HOST/$NOVA_DB" + nova_ctl all restart + sleep 1 + /usr/bin/nova-manage db sync } case $ARG0 in "start"|"stop") nova_ctl all $ARG0 ;; "install") install_hook ;; - "amqp-relation-joined") exit 0 ;; - "amqp-relation-changed") exit 0 ;; + "amqp-relation-joined") amqp_joined ;; + "amqp-relation-changed") amqp_changed ;; + "shared-db-relation-joined") db_joined ;; + "shared-db-relation-changed") db_changed ;; *) exit 0 ;; esac diff --git a/hooks/shared-db-relation-changed b/hooks/shared-db-relation-changed new file mode 120000 index 00000000..ed780797 --- /dev/null +++ b/hooks/shared-db-relation-changed @@ -0,0 +1 @@ +nova-cloud-controller-relations \ No newline at end of file diff --git a/hooks/shared-db-relation-joined b/hooks/shared-db-relation-joined new file mode 120000 index 00000000..ed780797 --- /dev/null +++ b/hooks/shared-db-relation-joined @@ -0,0 +1 @@ +nova-cloud-controller-relations \ No newline at end of file diff --git a/metadata.yaml b/metadata.yaml index b7f8abf4..9ed18d92 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -1,6 +1,6 @@ ensemble: formula name: nova-cloud-controller -revision: 12 +revision: 23 summary: "Openstack nova controller node." description: | Cloud controller node for Openstack nova. Contains nova-schedule,