From a45a0a0276f542ef5d624067e98dfa2de830fd84 Mon Sep 17 00:00:00 2001 From: Denis Egorenko Date: Tue, 1 Oct 2013 16:03:39 +0000 Subject: [PATCH] Added Savanna Project Added services Savanna, Savanna Dashboard, Savanna python client. Implements blueprint devstack-savanna-support Implements blueprint devstack-integration Change-Id: I8725f59a0cc9aef4817988470313136c56711cf1 --- exercises/savanna.sh | 43 +++++++++++++++++++ extras.d/70-savanna.sh | 31 ++++++++++++++ lib/savanna | 97 ++++++++++++++++++++++++++++++++++++++++++ lib/savanna-dashboard | 70 ++++++++++++++++++++++++++++++ 4 files changed, 241 insertions(+) create mode 100755 exercises/savanna.sh create mode 100644 extras.d/70-savanna.sh create mode 100644 lib/savanna create mode 100644 lib/savanna-dashboard diff --git a/exercises/savanna.sh b/exercises/savanna.sh new file mode 100755 index 0000000000..fc3f9760e5 --- /dev/null +++ b/exercises/savanna.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# **savanna.sh** + +# Sanity check that Savanna started if enabled + +echo "*********************************************************************" +echo "Begin DevStack Exercise: $0" +echo "*********************************************************************" + +# This script exits on an error so that errors don't compound and you see +# only the first error that occurred. +set -o errexit + +# Print the commands being run so that we can see the command that triggers +# an error. It is also useful for following allowing as the install occurs. +set -o xtrace + + +# Settings +# ======== + +# Keep track of the current directory +EXERCISE_DIR=$(cd $(dirname "$0") && pwd) +TOP_DIR=$(cd $EXERCISE_DIR/..; pwd) + +# Import common functions +source $TOP_DIR/functions + +# Import configuration +source $TOP_DIR/openrc + +# Import exercise configuration +source $TOP_DIR/exerciserc + +is_service_enabled savanna || exit 55 + +curl http://$SERVICE_HOST:8386/ 2>/dev/null | grep -q 'Auth' || die $LINENO "Savanna API not functioning!" + +set +o xtrace +echo "*********************************************************************" +echo "SUCCESS: End DevStack Exercise: $0" +echo "*********************************************************************" diff --git a/extras.d/70-savanna.sh b/extras.d/70-savanna.sh new file mode 100644 index 0000000000..f6881cc4f6 --- /dev/null +++ b/extras.d/70-savanna.sh @@ -0,0 +1,31 @@ +# savanna.sh - DevStack extras script to install Savanna + +if is_service_enabled savanna; then + if [[ "$1" == "source" ]]; then + # Initial source + source $TOP_DIR/lib/savanna + source $TOP_DIR/lib/savanna-dashboard + elif [[ "$1" == "stack" && "$2" == "install" ]]; then + echo_summary "Installing Savanna" + install_savanna + if is_service_enabled horizon; then + install_savanna_dashboard + fi + elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then + echo_summary "Configuring Savanna" + configure_savanna + if is_service_enabled horizon; then + configure_savanna_dashboard + fi + elif [[ "$1" == "stack" && "$2" == "extra" ]]; then + echo_summary "Initializing Savanna" + start_savanna + fi + + if [[ "$1" == "unstack" ]]; then + stop_savanna + if is_service_enabled horizon; then + cleanup_savanna_dashboard + fi + fi +fi diff --git a/lib/savanna b/lib/savanna new file mode 100644 index 0000000000..e9dbe72643 --- /dev/null +++ b/lib/savanna @@ -0,0 +1,97 @@ +# lib/savanna + +# Dependencies: +# ``functions`` file +# ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined +# ``ADMIN_{TENANT_NAME|PASSWORD}`` must be defined + +# ``stack.sh`` calls the entry points in this order: +# +# install_savanna +# configure_savanna +# start_savanna +# stop_savanna + +# Save trace setting +XTRACE=$(set +o | grep xtrace) +set +o xtrace + + +# Defaults +# -------- + +# Set up default repos +SAVANNA_REPO=${SAVANNA_REPO:-${GIT_BASE}/openstack/savanna.git} +SAVANNA_BRANCH=${SAVANNA_BRANCH:-master} + +# Set up default directories +SAVANNA_DIR=$DEST/savanna +SAVANNA_CONF_DIR=${SAVANNA_CONF_DIR:-/etc/savanna} +SAVANNA_CONF_FILE=savanna.conf +ADMIN_TENANT_NAME=${ADMIN_TENANT_NAME:-admin} +ADMIN_NAME=${ADMIN_NAME:-admin} +ADMIN_PASSWORD=${ADMIN_PASSWORD:-nova} +SAVANNA_DEBUG=${SAVANNA_DEBUG:-True} + +# Support entry points installation of console scripts +if [[ -d $SAVANNA_DIR/bin ]]; then + SAVANNA_BIN_DIR=$SAVANNA_DIR/bin +else + SAVANNA_BIN_DIR=$(get_python_exec_prefix) +fi + +# Functions +# --------- + +# configure_savanna() - Set config files, create data dirs, etc +function configure_savanna() { + + if [[ ! -d $SAVANNA_CONF_DIR ]]; then + sudo mkdir -p $SAVANNA_CONF_DIR + fi + sudo chown $STACK_USER $SAVANNA_CONF_DIR + + # Copy over savanna configuration file and configure common parameters. + cp $SAVANNA_DIR/etc/savanna/savanna.conf.sample $SAVANNA_CONF_DIR/$SAVANNA_CONF_FILE + + iniset $SAVANNA_CONF_DIR/$SAVANNA_CONF_FILE DEFAULT os_admin_password $ADMIN_PASSWORD + iniset $SAVANNA_CONF_DIR/$SAVANNA_CONF_FILE DEFAULT os_admin_username $ADMIN_NAME + iniset $SAVANNA_CONF_DIR/$SAVANNA_CONF_FILE DEFAULT os_admin_tenant_name $ADMIN_TENANT_NAME + iniset $SAVANNA_CONF_DIR/$SAVANNA_CONF_FILE DEFAULT debug $SAVANNA_DEBUG + + recreate_database savanna utf8 + iniset $SAVANNA_CONF_DIR/$SAVANNA_CONF_FILE database sql_connection `database_connection_url savanna` + inicomment $SAVANNA_CONF_DIR/$SAVANNA_CONF_FILE database connection + + if is_service_enabled neutron; then + iniset $SAVANNA_CONF_DIR/$SAVANNA_CONF_FILE DEFAULT use_neutron true + iniset $SAVANNA_CONF_DIR/$SAVANNA_CONF_FILE DEFAULT use_floating_ips true + fi + + iniset $SAVANNA_CONF_DIR/$SAVANNA_CONF_FILE DEFAULT use_syslog $SYSLOG +} + +# install_savanna() - Collect source and prepare +function install_savanna() { + git_clone $SAVANNA_REPO $SAVANNA_DIR $SAVANNA_BRANCH + setup_develop $SAVANNA_DIR +} + +# start_savanna() - Start running processes, including screen +function start_savanna() { + screen_it savanna "cd $SAVANNA_DIR && $SAVANNA_BIN_DIR/savanna-api --config-file $SAVANNA_CONF_DIR/$SAVANNA_CONF_FILE" +} + +# stop_savanna() - Stop running processes +function stop_savanna() { + # Kill the Savanna screen windows + screen -S $SCREEN_NAME -p savanna -X kill +} + + +# Restore xtrace +$XTRACE + +# Local variables: +# mode: shell-script +# End: diff --git a/lib/savanna-dashboard b/lib/savanna-dashboard new file mode 100644 index 0000000000..9562db4e1c --- /dev/null +++ b/lib/savanna-dashboard @@ -0,0 +1,70 @@ +# lib/savanna-dashboard + +# Dependencies: +# ``functions`` file +# ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined +# ``SERVICE_HOST + +# ``stack.sh`` calls the entry points in this order: +# +# install_savanna_dashboard +# configure_savanna_dashboard +# cleanup_savanna_dashboard + +# Save trace setting +XTRACE=$(set +o | grep xtrace) +set +o xtrace + +source $TOP_DIR/lib/horizon + +# Defaults +# -------- + +# Set up default repos +SAVANNA_DASHBOARD_REPO=${SAVANNA_DASHBOARD_REPO:-${GIT_BASE}/openstack/savanna-dashboard.git} +SAVANNA_DASHBOARD_BRANCH=${SAVANNA_DASHBOARD_BRANCH:-master} + +SAVANNA_PYTHONCLIENT_REPO=${SAVANNA_PYTHONCLIENT_REPO:-${GIT_BASE}/openstack/python-savannaclient.git} +SAVANNA_PYTHONCLIENT_BRANCH=${SAVANNA_PYTHONCLIENT_BRANCH:-master} + +# Set up default directories +SAVANNA_DASHBOARD_DIR=$DEST/savanna_dashboard +SAVANNA_PYTHONCLIENT_DIR=$DEST/python-savannaclient + +# Functions +# --------- + +function configure_savanna_dashboard() { + + echo -e "SAVANNA_URL = \"http://$SERVICE_HOST:8386/v1.1\"\nAUTO_ASSIGNMENT_ENABLED = False" >> $HORIZON_DIR/openstack_dashboard/local/local_settings.py + echo -e "HORIZON_CONFIG['dashboards'] += ('savanna',)\nINSTALLED_APPS += ('savannadashboard',)" >> $HORIZON_DIR/openstack_dashboard/settings.py + + if is_service_enabled neutron; then + echo -e "SAVANNA_USE_NEUTRON = True" >> $HORIZON_DIR/openstack_dashboard/local/local_settings.py + fi +} + +# install_savanna_dashboard() - Collect source and prepare +function install_savanna_dashboard() { + install_python_savannaclient + git_clone $SAVANNA_DASHBOARD_REPO $SAVANNA_DASHBOARD_DIR $SAVANNA_DASHBOARD_BRANCH + setup_develop $SAVANNA_DASHBOARD_DIR +} + +function install_python_savannaclient() { + git_clone $SAVANNA_PYTHONCLIENT_REPO $SAVANNA_PYTHONCLIENT_DIR $SAVANNA_PYTHONCLIENT_BRANCH + setup_develop $SAVANNA_PYTHONCLIENT_DIR +} + +# Cleanup file settings.py from Savanna +function cleanup_savanna_dashboard() { + sed -i '/savanna/d' $HORIZON_DIR/openstack_dashboard/settings.py +} + +# Restore xtrace +$XTRACE + +# Local variables: +# mode: shell-script +# End: +