blob: 4c8dcf453968d4b8e0812fdccb492ff7979a52c2 [file] [log] [blame]
Jesse Andrewsba23cc72011-09-11 03:22:13 -07001#!/usr/bin/env bash
2
Jesse Andrews0e7e8972011-10-02 16:36:54 -04003# **stack.sh** is an opinionated openstack developer installation.
4
Tres Henryca85b792011-10-28 14:00:21 -07005# This script installs and configures *nova*, *glance*, *horizon* and *keystone*
Jesse Andrewsba23cc72011-09-11 03:22:13 -07006
Vishvananda Ishaya9b353672011-10-20 10:07:10 -07007# This script allows you to specify configuration options of what git
Jesse Andrews5372f432011-10-03 01:08:24 -04008# repositories to use, enabled services, network configuration and various
9# passwords. If you are crafty you can run the script on multiple nodes using
10# shared settings for common resources (mysql, rabbitmq) and build a multi-node
11# developer install.
Jesse Andrews782b9912011-10-02 16:53:21 -040012
Jesse Andrews38df1222011-11-20 09:55:44 -080013# To keep this script simple we assume you are running on an **Ubuntu 11.10
14# Oneiric** machine. It should work in a VM or physical server. Additionally
15# we put the list of *apt* and *pip* dependencies and other configuration files
16# in this repo. So start by grabbing this script and the dependencies.
Jesse Andrews24859062011-09-15 21:28:23 -070017
Jesse Andrews0e7e8972011-10-02 16:36:54 -040018# Learn more and get the most recent version at http://devstack.org
Jesse Andrews6edd17f2011-09-15 22:19:42 -070019
20# Sanity Check
21# ============
22
Jesse Andrews38df1222011-11-20 09:55:44 -080023# Warn users who aren't on oneiric, but allow them to override check and attempt
Jesse Andrews6edd17f2011-09-15 22:19:42 -070024# installation with ``FORCE=yes ./stack``
Chmouel Boudjnahadfc0292011-11-14 14:24:30 +010025DISTRO=$(lsb_release -c -s)
26
Jesse Andrews38df1222011-11-20 09:55:44 -080027if [[ ! ${DISTRO} =~ (oneiric) ]]; then
28 echo "WARNING: this script has only been tested on oneiric"
Jesse Andrews6edd17f2011-09-15 22:19:42 -070029 if [[ "$FORCE" != "yes" ]]; then
30 echo "If you wish to run this script anyway run with FORCE=yes"
31 exit 1
32 fi
33fi
34
Jesse Andrews51fb22e2011-10-19 09:24:17 -070035# Keep track of the current devstack directory.
36TOP_DIR=$(cd $(dirname "$0") && pwd)
37
Dean Troyer6563a3c2012-01-31 12:11:56 -060038# Import common functions
39. $TOP_DIR/functions
40
root40a37002011-09-20 18:06:14 +000041# stack.sh keeps the list of **apt** and **pip** dependencies in external
Jesse Andrews4d282182011-09-16 11:27:43 -070042# files, along with config templates and other useful files. You can find these
root40a37002011-09-20 18:06:14 +000043# in the ``files`` directory (next to this script). We will reference this
Jesse Andrewsbf3868d2011-09-16 11:31:16 -070044# directory using the ``FILES`` variable in this script.
Jesse Andrews51fb22e2011-10-19 09:24:17 -070045FILES=$TOP_DIR/files
Jesse Andrewsbf3868d2011-09-16 11:31:16 -070046if [ ! -d $FILES ]; then
47 echo "ERROR: missing devstack/files - did you grab more than just stack.sh?"
Jesse Andrews6edd17f2011-09-15 22:19:42 -070048 exit 1
49fi
50
Anthony Young6015c822011-10-12 07:17:11 +000051
Scott Moserf9da5082011-10-07 21:28:00 -040052
53# Settings
54# ========
55
56# This script is customizable through setting environment variables. If you
57# want to override a setting you can either::
58#
Anthony Young7a549f42011-10-12 07:13:13 +000059# export MYSQL_PASSWORD=anothersecret
Scott Moserf9da5082011-10-07 21:28:00 -040060# ./stack.sh
61#
Anthony Young7a549f42011-10-12 07:13:13 +000062# You can also pass options on a single line ``MYSQL_PASSWORD=simple ./stack.sh``
Scott Moserf9da5082011-10-07 21:28:00 -040063#
64# Additionally, you can put any local variables into a ``localrc`` file, like::
65#
Anthony Young7a549f42011-10-12 07:13:13 +000066# MYSQL_PASSWORD=anothersecret
Scott Moserf9da5082011-10-07 21:28:00 -040067# MYSQL_USER=hellaroot
68#
69# We try to have sensible defaults, so you should be able to run ``./stack.sh``
70# in most cases.
71#
Dean Troyerc727aa82012-01-13 12:13:59 -060072# We support HTTP and HTTPS proxy servers via the usual environment variables
73# http_proxy and https_proxy. They can be set in localrc if necessary or
74# on the command line::
75#
76# http_proxy=http://proxy.example.com:3128/ ./stack.sh
77#
Jesse Andrews38df1222011-11-20 09:55:44 -080078# We source our settings from ``stackrc``. This file is distributed with devstack
79# and contains locations for what repositories to use. If you want to use other
80# repositories and branches, you can add your own settings with another file called
81# ``localrc``
Scott Moserf9da5082011-10-07 21:28:00 -040082#
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070083# If ``localrc`` exists, then ``stackrc`` will load those settings. This is
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +010084# useful for changing a branch or repository to test other versions. Also you
Anthony Young7a549f42011-10-12 07:13:13 +000085# can store your other settings like **MYSQL_PASSWORD** or **ADMIN_PASSWORD** instead
Chmouel Boudjnah8da56562012-03-09 14:21:40 +000086# of letting devstack generate random ones for you. You can customize
87# which services to install as well in your localrc.
Scott Moserf9da5082011-10-07 21:28:00 -040088source ./stackrc
89
Jesse Andrews6edd17f2011-09-15 22:19:42 -070090# Destination path for installation ``DEST``
Anthony Younge8fed482011-09-26 19:50:43 -070091DEST=${DEST:-/opt/stack}
Jesse Andrewsba23cc72011-09-11 03:22:13 -070092
Anthony Young55458452011-12-17 00:21:49 +000093# Check to see if we are already running a stack.sh
Chmouel Boudjnah44b57362012-02-07 18:13:44 +010094if type -p screen >/dev/null && screen -ls | egrep -q "[0-9].stack"; then
Anthony Young55458452011-12-17 00:21:49 +000095 echo "You are already running a stack.sh session."
96 echo "To rejoin this session type 'screen -x stack'."
97 echo "To destroy this session, kill the running screen."
98 exit 1
99fi
Todd Willey0a161452011-10-28 02:34:19 -0400100
Tres Henryca85b792011-10-28 14:00:21 -0700101# OpenStack is designed to be run as a regular user (Horizon will fail to run
Dean Troyer9122e7b2011-10-17 14:07:11 -0500102# as root, since apache refused to startup serve content from root user). If
103# stack.sh is run as root, it automatically creates a stack user with
104# sudo privileges and runs as that user.
105
106if [[ $EUID -eq 0 ]]; then
James E. Blair92e81992011-10-11 09:26:29 -0500107 ROOTSLEEP=${ROOTSLEEP:-10}
Dean Troyer9122e7b2011-10-17 14:07:11 -0500108 echo "You are running this script as root."
James E. Blair92e81992011-10-11 09:26:29 -0500109 echo "In $ROOTSLEEP seconds, we will create a user 'stack' and run as that user"
110 sleep $ROOTSLEEP
Dean Troyer9122e7b2011-10-17 14:07:11 -0500111
112 # since this script runs as a normal user, we need to give that user
113 # ability to run sudo
Jesse Andrewsc7f72ad2011-11-06 08:00:28 -0800114 dpkg -l sudo || apt_get update && apt_get install sudo
Dean Troyer9122e7b2011-10-17 14:07:11 -0500115
116 if ! getent passwd stack >/dev/null; then
117 echo "Creating a user called stack"
118 useradd -U -G sudo -s /bin/bash -d $DEST -m stack
119 fi
120
121 echo "Giving stack user passwordless sudo priviledges"
Jesse Andrews38df1222011-11-20 09:55:44 -0800122 # some uec images sudoers does not have a '#includedir'. add one.
Dean Troyer9122e7b2011-10-17 14:07:11 -0500123 grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers ||
124 echo "#includedir /etc/sudoers.d" >> /etc/sudoers
125 ( umask 226 && echo "stack ALL=(ALL) NOPASSWD:ALL" \
126 > /etc/sudoers.d/50_stack_sh )
127
128 echo "Copying files to stack user"
129 STACK_DIR="$DEST/${PWD##*/}"
Dean Troyer0c3db252011-12-15 12:00:31 -0600130 cp -r -f -T "$PWD" "$STACK_DIR"
Jesse Andrews5f4ae102011-11-06 07:47:09 -0800131 chown -R stack "$STACK_DIR"
Dean Troyer9122e7b2011-10-17 14:07:11 -0500132 if [[ "$SHELL_AFTER_RUN" != "no" ]]; then
133 exec su -c "set -e; cd $STACK_DIR; bash stack.sh; bash" stack
134 else
135 exec su -c "set -e; cd $STACK_DIR; bash stack.sh" stack
136 fi
137 exit 1
Jesse Andrews509992f2011-10-27 11:18:09 -0700138else
Dean Troyere0d677c2012-03-07 14:11:33 -0600139 # We're not root, make sure sudo is available
140 dpkg -l sudo
141 die_if_error "Sudo is required. Re-run stack.sh as root ONE TIME ONLY to set up sudo."
142
143 # UEC images /etc/sudoers does not have a '#includedir'. add one.
Jesse Andrews84a399b2011-10-27 11:20:38 -0700144 sudo grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers ||
145 echo "#includedir /etc/sudoers.d" | sudo tee -a /etc/sudoers
Dean Troyere0d677c2012-03-07 14:11:33 -0600146
147 # Set up devstack sudoers
Todd Willey0a161452011-10-28 02:34:19 -0400148 TEMPFILE=`mktemp`
Dean Troyere0d677c2012-03-07 14:11:33 -0600149 echo "`whoami` ALL=(root) NOPASSWD:ALL" >$TEMPFILE
Todd Willey0a161452011-10-28 02:34:19 -0400150 chmod 0440 $TEMPFILE
151 sudo chown root:root $TEMPFILE
Dean Troyere0d677c2012-03-07 14:11:33 -0600152 sudo mv $TEMPFILE /etc/sudoers.d/50_stack_sh
153
154 # Set up the rootwrap sudoers
155 TEMPFILE=`mktemp`
156 echo "$USER ALL=(root) NOPASSWD: /usr/local/bin/nova-rootwrap" >$TEMPFILE
157 chmod 0440 $TEMPFILE
158 sudo chown root:root $TEMPFILE
159 sudo mv $TEMPFILE /etc/sudoers.d/nova-rootwrap
160
161 # Remove old file
162 sudo rm -f /etc/sudoers.d/stack_sh_nova
Dean Troyer9122e7b2011-10-17 14:07:11 -0500163fi
164
Dean Troyer25dab662011-12-16 22:40:46 -0600165# Set True to configure stack.sh to run cleanly without Internet access.
166# stack.sh must have been previously run with Internet access to install
167# prerequisites and initialize $DEST.
168OFFLINE=`trueorfalse False $OFFLINE`
169
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700170# Set the destination directories for openstack projects
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700171NOVA_DIR=$DEST/nova
Tres Henryca85b792011-10-28 14:00:21 -0700172HORIZON_DIR=$DEST/horizon
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700173GLANCE_DIR=$DEST/glance
174KEYSTONE_DIR=$DEST/keystone
175NOVACLIENT_DIR=$DEST/python-novaclient
Anthony Young52e631d2011-12-27 22:22:14 -0800176KEYSTONECLIENT_DIR=$DEST/python-keystoneclient
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700177NOVNC_DIR=$DEST/noVNC
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +0100178SWIFT_DIR=$DEST/swift
Brad Hall1bfa3d52011-10-27 18:18:20 -0700179QUANTUM_DIR=$DEST/quantum
Dave Lapsley5a09c922012-01-25 17:22:15 -0500180QUANTUM_CLIENT_DIR=$DEST/python-quantumclient
Jason Kölker64a90662012-01-23 11:17:27 -0600181MELANGE_DIR=$DEST/melange
182MELANGECLIENT_DIR=$DEST/python-melangeclient
Brad Hall1bfa3d52011-10-27 18:18:20 -0700183
184# Default Quantum Plugin
185Q_PLUGIN=${Q_PLUGIN:-openvswitch}
Brad Hallf1f3a8f2011-12-12 23:04:58 +0000186# Default Quantum Port
187Q_PORT=${Q_PORT:-9696}
188# Default Quantum Host
189Q_HOST=${Q_HOST:-localhost}
Anthony Younga8416442011-09-13 20:07:44 -0700190
Jason Kölker64a90662012-01-23 11:17:27 -0600191# Default Melange Port
192M_PORT=${M_PORT:-9898}
193# Default Melange Host
194M_HOST=${M_HOST:-localhost}
195# Melange MAC Address Range
Aaron Lee690e1e32012-03-08 09:57:30 -0800196M_MAC_RANGE=${M_MAC_RANGE:-FE-EE-DD-00-00-00/24}
Jason Kölker64a90662012-01-23 11:17:27 -0600197
Jesse Andrewsd02b7b72011-11-14 08:59:05 -0800198# Name of the lvm volume group to use/create for iscsi volumes
199VOLUME_GROUP=${VOLUME_GROUP:-nova-volumes}
Dean Troyer2229a6e2011-12-01 17:02:07 -0600200VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
Anthony Young55458452011-12-17 00:21:49 +0000201INSTANCE_NAME_PREFIX=${INSTANCE_NAME_PREFIX:-instance-}
Jesse Andrewsd02b7b72011-11-14 08:59:05 -0800202
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700203# Nova hypervisor configuration. We default to libvirt whth **kvm** but will
204# drop back to **qemu** if we are unable to load the kvm module. Stack.sh can
205# also install an **LXC** based system.
206VIRT_DRIVER=${VIRT_DRIVER:-libvirt}
Jesse Andrews782b9912011-10-02 16:53:21 -0400207LIBVIRT_TYPE=${LIBVIRT_TYPE:-kvm}
208
Vishvananda Ishaya51aa4012012-03-06 12:45:19 -0800209# Nova supports pluggable schedulers. ``FilterScheduler`` should work in most
210# cases.
211SCHEDULER=${SCHEDULER:-nova.scheduler.filter_scheduler.FilterScheduler}
Jesse Andrews782b9912011-10-02 16:53:21 -0400212
rootb1153412012-01-19 13:28:21 -0800213HOST_IP_IFACE=${HOST_IP_IFACE:-eth0}
Anthony Young7c259ce2011-11-07 13:18:28 -0600214# Use the eth0 IP unless an explicit is set by ``HOST_IP`` environment variable
rootb1153412012-01-19 13:28:21 -0800215if [ -z "$HOST_IP" -o "$HOST_IP" == "dhcp" ]; then
216 HOST_IP=`LC_ALL=C /sbin/ifconfig ${HOST_IP_IFACE} | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
Anthony Younga3475e52011-11-07 13:24:00 -0600217 if [ "$HOST_IP" = "" ]; then
Anthony Young857035d2011-11-07 14:02:13 -0600218 echo "Could not determine host ip address."
rootb1153412012-01-19 13:28:21 -0800219 echo "Either localrc specified dhcp on ${HOST_IP_IFACE} or defaulted to eth0"
Anthony Young7c259ce2011-11-07 13:18:28 -0600220 exit 1
221 fi
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700222fi
223
Anthony Young1097c7c2011-12-27 23:22:14 -0800224# Allow the use of an alternate hostname (such as localhost/127.0.0.1) for service endpoints.
225SERVICE_HOST=${SERVICE_HOST:-$HOST_IP}
226
Dean Troyerff603ef2011-11-22 17:48:10 -0600227# Configure services to syslog instead of writing to individual log files
228SYSLOG=`trueorfalse False $SYSLOG`
229SYSLOG_HOST=${SYSLOG_HOST:-$HOST_IP}
230SYSLOG_PORT=${SYSLOG_PORT:-516}
231
Dean Troyer2bbcd682011-11-05 16:19:03 -0500232# Service startup timeout
233SERVICE_TIMEOUT=${SERVICE_TIMEOUT:-60}
234
Anthony Young7a549f42011-10-12 07:13:13 +0000235# Generic helper to configure passwords
236function read_password {
237 set +o xtrace
238 var=$1; msg=$2
239 pw=${!var}
240
Anthony Youngb4db2252011-10-12 14:08:08 -0700241 localrc=$TOP_DIR/localrc
Anthony Young6015c822011-10-12 07:17:11 +0000242
Anthony Young7a549f42011-10-12 07:13:13 +0000243 # If the password is not defined yet, proceed to prompt user for a password.
244 if [ ! $pw ]; then
245 # If there is no localrc file, create one
Anthony Youngb4db2252011-10-12 14:08:08 -0700246 if [ ! -e $localrc ]; then
247 touch $localrc
Anthony Young7a549f42011-10-12 07:13:13 +0000248 fi
249
Vishvananda Ishaya9b353672011-10-20 10:07:10 -0700250 # Presumably if we got this far it can only be that our localrc is missing
Anthony Young7a549f42011-10-12 07:13:13 +0000251 # the required password. Prompt user for a password and write to localrc.
Anthony Youngb4db2252011-10-12 14:08:08 -0700252 echo ''
253 echo '################################################################################'
254 echo $msg
255 echo '################################################################################'
Dean Troyer4e6a2b72011-12-29 17:27:45 -0600256 echo "This value will be written to your localrc file so you don't have to enter it "
257 echo "again. Use only alphanumeric characters."
Anthony Youngb4db2252011-10-12 14:08:08 -0700258 echo "If you leave this blank, a random default value will be used."
Dean Troyer4e6a2b72011-12-29 17:27:45 -0600259 pw=" "
260 while true; do
261 echo "Enter a password now:"
262 read -e $var
263 pw=${!var}
264 [[ "$pw" = "`echo $pw | tr -cd [:alnum:]`" ]] && break
265 echo "Invalid chars in password. Try again:"
266 done
Anthony Youngb4db2252011-10-12 14:08:08 -0700267 if [ ! $pw ]; then
268 pw=`openssl rand -hex 10`
Anthony Young7a549f42011-10-12 07:13:13 +0000269 fi
Anthony Youngb4db2252011-10-12 14:08:08 -0700270 eval "$var=$pw"
271 echo "$var=$pw" >> $localrc
Anthony Young7a549f42011-10-12 07:13:13 +0000272 fi
273 set -o xtrace
274}
275
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000276# This function will check if the service(s) specified in argument is
277# enabled by the user in ENABLED_SERVICES.
278#
279# If there is multiple services specified as argument it will act as a
280# boolean OR or if any of the services specified on the command line
281# return true.
282#
283# There is a special cases for some 'catch-all' services :
284# nova would catch if any service enabled start by n-
285# glance would catch if any service enabled start by g-
286# quantum would catch if any service enabled start by q-
287function is_service_enabled() {
288 services=$@
289 for service in ${services}; do
290 [[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0
291 [[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0
292 [[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && return 0
293 [[ ${service} == "quantum" && ${ENABLED_SERVICES} =~ "q-" ]] && return 0
294 done
295 return 1
296}
Anthony Young7a549f42011-10-12 07:13:13 +0000297
Jesse Andrews782b9912011-10-02 16:53:21 -0400298# Nova Network Configuration
299# --------------------------
300
Vishvananda Ishaya9b353672011-10-20 10:07:10 -0700301# FIXME: more documentation about why these are important flags. Also
Jesse Andrews5372f432011-10-03 01:08:24 -0400302# we should make sure we use the same variable names as the flag names.
303
John Garbutt8e2cffd2012-03-02 16:22:07 +0000304if [ "$VIRT_DRIVER" = 'xenserver' ]; then
305 PUBLIC_INTERFACE_DEFAULT=eth3
306 # allow build_domU.sh to specify the flat network bridge via kernel args
307 FLAT_NETWORK_BRIDGE_DEFAULT=$(grep -o 'flat_network_bridge=[^.]*' /proc/cmdline | cut -d= -f 2)
308 GUEST_INTERFACE_DEFAULT=eth1
309else
310 PUBLIC_INTERFACE_DEFAULT=br100
311 FLAT_NETWORK_BRIDGE_DEFAULT=br100
312 GUEST_INTERFACE_DEFAULT=eth0
313fi
314
315PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-$PUBLIC_INTERFACE_DEFAULT}
Anthony Young00596bb2011-12-16 20:23:07 +0000316PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-br100}
Jesse Andrewsb5197e42011-09-26 12:48:31 -0700317FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
318FIXED_NETWORK_SIZE=${FIXED_NETWORK_SIZE:-256}
Anthony Young0e74ecb2011-10-27 13:21:52 -0700319FLOATING_RANGE=${FLOATING_RANGE:-172.24.4.224/28}
Jesse Andrewsa72f7ad2011-09-25 13:41:22 -0700320NET_MAN=${NET_MAN:-FlatDHCPManager}
Anthony Young1097c7c2011-12-27 23:22:14 -0800321EC2_DMZ_HOST=${EC2_DMZ_HOST:-$SERVICE_HOST}
John Garbutt8e2cffd2012-03-02 16:22:07 +0000322FLAT_NETWORK_BRIDGE=${FLAT_NETWORK_BRIDGE:-$FLAT_NETWORK_BRIDGE_DEFAULT}
323VLAN_INTERFACE=${VLAN_INTERFACE:-$GUEST_INTERFACE_DEFAULT}
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400324
Dean Troyer696ad332012-01-10 15:34:34 -0600325# Test floating pool and range are used for testing. They are defined
326# here until the admin APIs can replace nova-manage
327TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test}
328TEST_FLOATING_RANGE=${TEST_FLOATING_RANGE:-192.168.253.0/29}
329
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400330# Multi-host is a mode where each compute node runs its own network node. This
331# allows network operations and routing for a VM to occur on the server that is
332# running the VM - removing a SPOF and bandwidth bottleneck.
Vishvananda Ishaya5f039322011-11-05 16:12:20 -0700333MULTI_HOST=${MULTI_HOST:-False}
Jesse Andrews30f68e92011-09-13 00:59:54 -0700334
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700335# If you are using FlatDHCP on multiple hosts, set the ``FLAT_INTERFACE``
336# variable but make sure that the interface doesn't already have an
337# ip or you risk breaking things.
Jesse Andrews5372f432011-10-03 01:08:24 -0400338#
Vishvananda Ishaya9b353672011-10-20 10:07:10 -0700339# **DHCP Warning**: If your flat interface device uses DHCP, there will be a
340# hiccup while the network is moved from the flat interface to the flat network
341# bridge. This will happen when you launch your first instance. Upon launch
342# you will lose all connectivity to the node, and the vm launch will probably
Jesse Andrews5372f432011-10-03 01:08:24 -0400343# fail.
Vishvananda Ishaya9b353672011-10-20 10:07:10 -0700344#
345# If you are running on a single node and don't need to access the VMs from
Jesse Andrews5372f432011-10-03 01:08:24 -0400346# devices other than that node, you can set the flat interface to the same
Vishvananda Ishaya9b353672011-10-20 10:07:10 -0700347# value as ``FLAT_NETWORK_BRIDGE``. This will stop the network hiccup from
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +0100348# occurring.
John Garbutt8e2cffd2012-03-02 16:22:07 +0000349FLAT_INTERFACE=${FLAT_INTERFACE:-$GUEST_INTERFACE_DEFAULT}
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700350
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400351## FIXME(ja): should/can we check that FLAT_INTERFACE is sane?
352
Brad Hall1bfa3d52011-10-27 18:18:20 -0700353# Using Quantum networking:
354#
Brad Hallf1f3a8f2011-12-12 23:04:58 +0000355# Make sure that quantum is enabled in ENABLED_SERVICES. If it is the network
356# manager will be set to the QuantumManager. If you want to run Quantum on
357# this host, make sure that q-svc is also in ENABLED_SERVICES.
Brad Hall1bfa3d52011-10-27 18:18:20 -0700358#
359# If you're planning to use the Quantum openvswitch plugin, set Q_PLUGIN to
360# "openvswitch" and make sure the q-agt service is enabled in
361# ENABLED_SERVICES.
362#
363# With Quantum networking the NET_MAN variable is ignored.
364
Jason Kölker64a90662012-01-23 11:17:27 -0600365# Using Melange IPAM:
366#
367# Make sure that quantum and melange are enabled in ENABLED_SERVICES.
368# If they are then the melange IPAM lib will be set in the QuantumManager.
369# Adding m-svc to ENABLED_SERVICES will start the melange service on this
370# host.
371
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700372
Jesse Andrews782b9912011-10-02 16:53:21 -0400373# MySQL & RabbitMQ
374# ----------------
375
Tres Henryca85b792011-10-28 14:00:21 -0700376# We configure Nova, Horizon, Glance and Keystone to use MySQL as their
Jesse Andrews782b9912011-10-02 16:53:21 -0400377# database server. While they share a single server, each has their own
378# database and tables.
379
Vishvananda Ishaya9b353672011-10-20 10:07:10 -0700380# By default this script will install and configure MySQL. If you want to
Jesse Andrews782b9912011-10-02 16:53:21 -0400381# use an existing server, you can pass in the user/password/host parameters.
Anthony Young7a549f42011-10-12 07:13:13 +0000382# You will need to send the same ``MYSQL_PASSWORD`` to every host if you are doing
Jesse Andrews782b9912011-10-02 16:53:21 -0400383# a multi-node devstack installation.
Jesse Andrewsa50a3462011-10-19 15:38:10 -0700384MYSQL_HOST=${MYSQL_HOST:-localhost}
Anthony Young320412b2011-09-14 02:39:10 -0700385MYSQL_USER=${MYSQL_USER:-root}
Anthony Young7a549f42011-10-12 07:13:13 +0000386read_password MYSQL_PASSWORD "ENTER A PASSWORD TO USE FOR MYSQL."
Jesse Andrews782b9912011-10-02 16:53:21 -0400387
Anthony Younga8416442011-09-13 20:07:44 -0700388# don't specify /db in this string, so we can use it for multiple services
Anthony Young7a549f42011-10-12 07:13:13 +0000389BASE_SQL_CONN=${BASE_SQL_CONN:-mysql://$MYSQL_USER:$MYSQL_PASSWORD@$MYSQL_HOST}
Anthony Younga8416442011-09-13 20:07:44 -0700390
391# Rabbit connection info
392RABBIT_HOST=${RABBIT_HOST:-localhost}
Anthony Young7a549f42011-10-12 07:13:13 +0000393read_password RABBIT_PASSWORD "ENTER A PASSWORD TO USE FOR RABBIT."
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700394
Anthony Young377aae62011-09-14 09:55:31 -0700395# Glance connection info. Note the port must be specified.
Anthony Young1097c7c2011-12-27 23:22:14 -0800396GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$SERVICE_HOST:9292}
Anthony Young377aae62011-09-14 09:55:31 -0700397
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +0100398# SWIFT
399# -----
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +0100400# TODO: implement glance support
401# TODO: add logging to different location.
Chmouel Boudjnahb93478f2011-11-02 16:49:56 +0100402
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +0100403# By default the location of swift drives and objects is located inside
Chmouel Boudjnah38750152011-11-03 09:17:06 +0100404# the swift source directory. SWIFT_DATA_LOCATION variable allow you to redefine
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +0100405# this.
Chmouel Boudjnah38750152011-11-03 09:17:06 +0100406SWIFT_DATA_LOCATION=${SWIFT_DATA_LOCATION:-${SWIFT_DIR}/data}
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +0100407
Chmouel Boudjnah3a648262011-11-03 10:43:46 +0100408# We are going to have the configuration files inside the source
409# directory, change SWIFT_CONFIG_LOCATION if you want to adjust that.
410SWIFT_CONFIG_LOCATION=${SWIFT_CONFIG_LOCATION:-${SWIFT_DIR}/config}
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +0100411
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +0100412# devstack will create a loop-back disk formatted as XFS to store the
413# swift data. By default the disk size is 1 gigabyte. The variable
414# SWIFT_LOOPBACK_DISK_SIZE specified in bytes allow you to change
415# that.
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +0100416SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-1000000}
Anthony Young7a549f42011-10-12 07:13:13 +0000417
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +0100418# The ring uses a configurable number of bits from a path’s MD5 hash as
419# a partition index that designates a device. The number of bits kept
420# from the hash is known as the partition power, and 2 to the partition
421# power indicates the partition count. Partitioning the full MD5 hash
422# ring allows other parts of the cluster to work in batches of items at
423# once which ends up either more efficient or at least less complex than
424# working with each item separately or the entire cluster all at once.
425# By default we define 9 for the partition count (which mean 512).
Chmouel Boudjnaha2118982011-11-01 15:36:00 +0100426SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
427
Chmouel Boudjnaha95efab2012-02-16 10:35:26 +0000428# This variable allows you to configure how many replicas you want to be
429# configured for your Swift cluster. By default the three replicas would need a
430# bit of IO and Memory on a VM you may want to lower that to 1 if you want to do
431# only some quick testing.
432SWIFT_REPLICAS=${SWIFT_REPLICAS:-3}
433
Chmouel Boudjnahb2857e42011-11-03 16:19:14 +0100434# We only ask for Swift Hash if we have enabled swift service.
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000435if is_service_enabled swift; then
Chmouel Boudjnahb2857e42011-11-03 16:19:14 +0100436 # SWIFT_HASH is a random unique string for a swift cluster that
437 # can never change.
438 read_password SWIFT_HASH "ENTER A RANDOM SWIFT HASH."
439fi
Vishvananda Ishaya5f039322011-11-05 16:12:20 -0700440
Jesse Andrews782b9912011-10-02 16:53:21 -0400441# Keystone
442# --------
443
Jesse Andrewsb96871e2011-10-02 09:02:46 -0700444# Service Token - Openstack components need to have an admin token
445# to validate user tokens.
Anthony Young7a549f42011-10-12 07:13:13 +0000446read_password SERVICE_TOKEN "ENTER A SERVICE_TOKEN TO USE FOR THE SERVICE ADMIN TOKEN."
Dean Troyerb3288382012-02-28 16:41:10 -0600447# Services authenticate to Identity with servicename/SERVICE_PASSWORD
448read_password SERVICE_PASSWORD "ENTER A SERVICE_PASSWORD TO USE FOR THE SERVICE AUTHENTICATION."
Tres Henryca85b792011-10-28 14:00:21 -0700449# Horizon currently truncates usernames and passwords at 20 characters
450read_password ADMIN_PASSWORD "ENTER A PASSWORD TO USE FOR HORIZON AND KEYSTONE (20 CHARS OR LESS)."
Jesse Andrewsb96871e2011-10-02 09:02:46 -0700451
Dean Troyerb3288382012-02-28 16:41:10 -0600452# Set the tenant for service accounts in Keystone
453SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service}
454
Dean Troyer6577b462012-01-16 22:27:20 -0600455# Set Keystone interface configuration
Dean Troyerb3288382012-02-28 16:41:10 -0600456KEYSTONE_API_PORT=${KEYSTONE_API_PORT:-5000}
Dean Troyer6577b462012-01-16 22:27:20 -0600457KEYSTONE_AUTH_HOST=${KEYSTONE_AUTH_HOST:-$SERVICE_HOST}
458KEYSTONE_AUTH_PORT=${KEYSTONE_AUTH_PORT:-35357}
459KEYSTONE_AUTH_PROTOCOL=${KEYSTONE_AUTH_PROTOCOL:-http}
460KEYSTONE_SERVICE_HOST=${KEYSTONE_SERVICE_HOST:-$SERVICE_HOST}
461KEYSTONE_SERVICE_PORT=${KEYSTONE_SERVICE_PORT:-5000}
462KEYSTONE_SERVICE_PROTOCOL=${KEYSTONE_SERVICE_PROTOCOL:-http}
463
Dean Troyer9bb84f02012-01-24 11:45:52 -0600464# Horizon
465# -------
466
467# Allow overriding the default Apache user and group, default both to
468# current user.
469APACHE_USER=${APACHE_USER:-$USER}
470APACHE_GROUP=${APACHE_GROUP:-$APACHE_USER}
471
Dean Troyer471de7a2011-12-27 11:45:55 -0600472# Log files
473# ---------
474
475# Set up logging for stack.sh
476# Set LOGFILE to turn on logging
477# We append '.xxxxxxxx' to the given name to maintain history
478# where xxxxxxxx is a representation of the date the file was created
Chmouel Boudjnahd966ed22012-03-05 12:42:48 +0000479if [[ -n "$LOGFILE" || -n "$SCREEN_LOGDIR" ]]; then
480 LOGDAYS=${LOGDAYS:-7}
481 TIMESTAMP_FORMAT=${TIMESTAMP_FORMAT:-"%F-%H%M%S"}
482 CURRENT_LOG_TIME=$(date "+$TIMESTAMP_FORMAT")
483fi
484
Dean Troyer471de7a2011-12-27 11:45:55 -0600485if [[ -n "$LOGFILE" ]]; then
486 # First clean up old log files. Use the user-specified LOGFILE
487 # as the template to search for, appending '.*' to match the date
488 # we added on earlier runs.
Dean Troyer471de7a2011-12-27 11:45:55 -0600489 LOGDIR=$(dirname "$LOGFILE")
490 LOGNAME=$(basename "$LOGFILE")
Chmouel Boudjnahfff6fec2012-03-09 15:37:56 +0000491 mkdir -p $LOGDIR
Dean Troyer471de7a2011-12-27 11:45:55 -0600492 find $LOGDIR -maxdepth 1 -name $LOGNAME.\* -mtime +$LOGDAYS -exec rm {} \;
493
Chmouel Boudjnahd966ed22012-03-05 12:42:48 +0000494 LOGFILE=$LOGFILE.${CURRENT_LOG_TIME}
Dean Troyer471de7a2011-12-27 11:45:55 -0600495 # Redirect stdout/stderr to tee to write the log file
496 exec 1> >( tee "${LOGFILE}" ) 2>&1
497 echo "stack.sh log $LOGFILE"
498 # Specified logfile name always links to the most recent log
499 ln -sf $LOGFILE $LOGDIR/$LOGNAME
500fi
501
Chmouel Boudjnahd966ed22012-03-05 12:42:48 +0000502# Set up logging of screen windows
503# Set SCREEN_LOGDIR to turn on logging of screen windows to the
504# directory specified in SCREEN_LOGDIR, we will log to the the file
505# screen-$SERVICE_NAME-$TIMESTAMP.log in that dir and have a link
506# screen-$SERVICE_NAME.log to the latest log file.
507# Logs are kept for as long specified in LOGDAYS.
508if [[ -n "$SCREEN_LOGDIR" ]]; then
509
510 # We make sure the directory is created.
511 if [[ -d "$SCREEN_LOGDIR" ]]; then
512 # We cleanup the old logs
513 find $SCREEN_LOGDIR -maxdepth 1 -name screen-\*.log -mtime +$LOGDAYS -exec rm {} \;
514 else
515 mkdir -p $SCREEN_LOGDIR
516 fi
517fi
518
Scott Moserf9da5082011-10-07 21:28:00 -0400519# So that errors don't compound we exit on any errors so you see only the
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +0100520# first error that occurred.
Scott Moserf9da5082011-10-07 21:28:00 -0400521trap failed ERR
522failed() {
523 local r=$?
524 set +o xtrace
525 [ -n "$LOGFILE" ] && echo "${0##*/} failed: full log in $LOGFILE"
526 exit $r
527}
528
529# Print the commands being run so that we can see the command that triggers
530# an error. It is also useful for following along as the install occurs.
531set -o xtrace
532
Jesse Andrewsfe95e0f2011-10-19 14:30:37 -0700533# create the destination directory and ensure it is writable by the user
Scott Moserf9da5082011-10-07 21:28:00 -0400534sudo mkdir -p $DEST
Jesse Andrewsfe95e0f2011-10-19 14:30:37 -0700535if [ ! -w $DEST ]; then
536 sudo chown `whoami` $DEST
537fi
Jesse Andrews53ed3872011-10-02 14:28:17 -0400538
Jesse Andrews30f68e92011-09-13 00:59:54 -0700539# Install Packages
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700540# ================
Jesse Andrews30f68e92011-09-13 00:59:54 -0700541#
542# Openstack uses a fair number of other projects.
543
Chmouel Boudjnah0277d5b2011-11-14 15:20:39 +0100544# - We are going to install packages only for the services needed.
545# - We are parsing the packages files and detecting metadatas.
Anthony Younga6353c62011-11-16 00:43:34 -0600546# - If there is a NOPRIME as comment mean we are not doing the install
547# just yet.
Dean Troyer0c3db252011-12-15 12:00:31 -0600548# - If we have the meta-keyword dist:DISTRO or
549# dist:DISTRO1,DISTRO2 it will be installed only for those
Chmouel Boudjnah0277d5b2011-11-14 15:20:39 +0100550# distros (case insensitive).
551function get_packages() {
Dean Troyerd0b21e22012-03-07 14:52:25 -0600552 local package_dir=$1
553 local file_to_parse
Chmouel Boudjnah0277d5b2011-11-14 15:20:39 +0100554 local service
Jesse Andrews38df1222011-11-20 09:55:44 -0800555
Dean Troyerd0b21e22012-03-07 14:52:25 -0600556 if [[ -z "$package_dir" ]]; then
557 echo "No package directory supplied"
558 return 1
559 fi
560 for service in general ${ENABLED_SERVICES//,/ }; do # Allow individual services to specify dependencies
561 if [[ -e ${package_dir}/${service} ]]; then
Anthony Youngef4e5362011-12-01 13:44:51 -0800562 file_to_parse="${file_to_parse} $service"
563 fi
Chmouel Boudjnah0277d5b2011-11-14 15:20:39 +0100564 if [[ $service == n-* ]]; then
Chmouel Boudjnahf990ded2011-11-14 15:26:13 +0100565 if [[ ! $file_to_parse =~ nova ]]; then
Chmouel Boudjnah0277d5b2011-11-14 15:20:39 +0100566 file_to_parse="${file_to_parse} nova"
567 fi
Chmouel Boudjnahf990ded2011-11-14 15:26:13 +0100568 elif [[ $service == g-* ]]; then
569 if [[ ! $file_to_parse =~ glance ]]; then
Chmouel Boudjnah0277d5b2011-11-14 15:20:39 +0100570 file_to_parse="${file_to_parse} glance"
571 fi
Chmouel Boudjnahf990ded2011-11-14 15:26:13 +0100572 elif [[ $service == key* ]]; then
573 if [[ ! $file_to_parse =~ keystone ]]; then
Chmouel Boudjnah0277d5b2011-11-14 15:20:39 +0100574 file_to_parse="${file_to_parse} keystone"
575 fi
Chmouel Boudjnah0277d5b2011-11-14 15:20:39 +0100576 fi
577 done
578
Chmouel Boudjnahf990ded2011-11-14 15:26:13 +0100579 for file in ${file_to_parse}; do
Dean Troyerd0b21e22012-03-07 14:52:25 -0600580 local fname=${package_dir}/${file}
Chmouel Boudjnah0277d5b2011-11-14 15:20:39 +0100581 local OIFS line package distros distro
Dean Troyerd0b21e22012-03-07 14:52:25 -0600582 [[ -e $fname ]] || continue
Chmouel Boudjnah0277d5b2011-11-14 15:20:39 +0100583
584 OIFS=$IFS
585 IFS=$'\n'
Chmouel Boudjnah2d1a8b32011-11-14 22:16:11 +0100586 for line in $(<${fname}); do
Anthony Younga6353c62011-11-16 00:43:34 -0600587 if [[ $line =~ "NOPRIME" ]]; then
588 continue
589 fi
590
Chmouel Boudjnahf990ded2011-11-14 15:26:13 +0100591 if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then # We are using BASH regexp matching feature.
Chmouel Boudjnah0277d5b2011-11-14 15:20:39 +0100592 package=${BASH_REMATCH[1]}
593 distros=${BASH_REMATCH[2]}
Chmouel Boudjnahf990ded2011-11-14 15:26:13 +0100594 for distro in ${distros//,/ }; do #In bash ${VAR,,} will lowecase VAR
Chmouel Boudjnah0277d5b2011-11-14 15:20:39 +0100595 [[ ${distro,,} == ${DISTRO,,} ]] && echo $package
596 done
597 continue
598 fi
599
600 echo ${line%#*}
601 done
602 IFS=$OIFS
603 done
604}
Jesse Andrews2caf8fd2011-09-12 16:15:11 -0700605
Jesse Andrews75a37652011-09-12 17:09:08 -0700606# install apt requirements
Scott Moseree1b4952011-10-20 13:09:11 -0400607apt_get update
Dean Troyerd0b21e22012-03-07 14:52:25 -0600608apt_get install $(get_packages $FILES/apts)
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700609
Jesse Andrews75a37652011-09-12 17:09:08 -0700610# install python requirements
Dean Troyerd0b21e22012-03-07 14:52:25 -0600611pip_install $(get_packages $FILES/pips | sort -u)
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700612
Jesse Andrews75a37652011-09-12 17:09:08 -0700613# compute service
Anthony Young2f140202011-09-26 13:02:40 -0700614git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH
Tres Henryca85b792011-10-28 14:00:21 -0700615# python client library to nova that horizon (and others) use
Andy Smith84c05992012-02-03 21:40:32 -0800616git_clone $KEYSTONECLIENT_REPO $KEYSTONECLIENT_DIR $KEYSTONECLIENT_BRANCH
Anthony Young2f140202011-09-26 13:02:40 -0700617git_clone $NOVACLIENT_REPO $NOVACLIENT_DIR $NOVACLIENT_BRANCH
Jesse Andrews38df1222011-11-20 09:55:44 -0800618
619# glance, swift middleware and nova api needs keystone middleware
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000620if is_service_enabled key g-api n-api swift; then
Jesse Andrews38df1222011-11-20 09:55:44 -0800621 # unified auth system (manages accounts/tokens)
622 git_clone $KEYSTONE_REPO $KEYSTONE_DIR $KEYSTONE_BRANCH
623fi
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000624if is_service_enabled swift; then
James E. Blaire7ce24f2011-11-10 13:05:13 -0800625 # storage service
626 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
James E. Blaire7ce24f2011-11-10 13:05:13 -0800627fi
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000628if is_service_enabled g-api n-api; then
James E. Blaire7ce24f2011-11-10 13:05:13 -0800629 # image catalog service
630 git_clone $GLANCE_REPO $GLANCE_DIR $GLANCE_BRANCH
631fi
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000632if is_service_enabled n-novnc; then
James E. Blaire7ce24f2011-11-10 13:05:13 -0800633 # a websockets/html5 or flash powered VNC console for vm instances
634 git_clone $NOVNC_REPO $NOVNC_DIR $NOVNC_BRANCH
635fi
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000636if is_service_enabled horizon; then
James E. Blaire7ce24f2011-11-10 13:05:13 -0800637 # django powered web control panel for openstack
638 git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG
639fi
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000640if is_service_enabled q-svc; then
James E. Blaire7ce24f2011-11-10 13:05:13 -0800641 # quantum
642 git_clone $QUANTUM_REPO $QUANTUM_DIR $QUANTUM_BRANCH
Deepak Garg1e98bdc2012-02-22 12:15:26 +0530643fi
644if is_service_enabled q-svc horizon; then
Dave Lapsley5a09c922012-01-25 17:22:15 -0500645 git_clone $QUANTUM_CLIENT_REPO $QUANTUM_CLIENT_DIR $QUANTUM_CLIENT_BRANCH
James E. Blaire7ce24f2011-11-10 13:05:13 -0800646fi
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700647
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000648if is_service_enabled m-svc; then
Jason Kölker64a90662012-01-23 11:17:27 -0600649 # melange
650 git_clone $MELANGE_REPO $MELANGE_DIR $MELANGE_BRANCH
651fi
652
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000653if is_service_enabled melange; then
Jason Kölker64a90662012-01-23 11:17:27 -0600654 git_clone $MELANGECLIENT_REPO $MELANGECLIENT_DIR $MELANGECLIENT_BRANCH
655fi
656
Jesse Andrews30f68e92011-09-13 00:59:54 -0700657# Initialization
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700658# ==============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700659
Jesse Andrewsd1879c52011-09-16 16:28:13 -0700660
Jesse Andrews75a37652011-09-12 17:09:08 -0700661# setup our checkouts so they are installed into python path
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700662# allowing ``import nova`` or ``import glance.client``
Vishvananda Ishayad2813762012-02-06 21:21:52 +0000663cd $KEYSTONECLIENT_DIR; sudo python setup.py develop
664cd $NOVACLIENT_DIR; sudo python setup.py develop
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000665if is_service_enabled key g-api n-api swift; then
James E. Blaire7ce24f2011-11-10 13:05:13 -0800666 cd $KEYSTONE_DIR; sudo python setup.py develop
667fi
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000668if is_service_enabled swift; then
James E. Blaire7ce24f2011-11-10 13:05:13 -0800669 cd $SWIFT_DIR; sudo python setup.py develop
James E. Blaire7ce24f2011-11-10 13:05:13 -0800670fi
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000671if is_service_enabled g-api n-api; then
James E. Blaire7ce24f2011-11-10 13:05:13 -0800672 cd $GLANCE_DIR; sudo python setup.py develop
673fi
Jesse Andrewsaa8bb242011-10-16 12:24:11 -0700674cd $NOVA_DIR; sudo python setup.py develop
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000675if is_service_enabled horizon; then
Gabriel Hurleyf1a11ad2012-02-29 01:36:53 -0800676 cd $HORIZON_DIR; sudo python setup.py develop
James E. Blaire7ce24f2011-11-10 13:05:13 -0800677fi
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000678if is_service_enabled q-svc; then
James E. Blaire7ce24f2011-11-10 13:05:13 -0800679 cd $QUANTUM_DIR; sudo python setup.py develop
680fi
Deepak Garg1e98bdc2012-02-22 12:15:26 +0530681if is_service_enabled q-svc horizon; then
682 cd $QUANTUM_CLIENT_DIR; sudo python setup.py develop
683fi
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000684if is_service_enabled m-svc; then
Jason Kölker64a90662012-01-23 11:17:27 -0600685 cd $MELANGE_DIR; sudo python setup.py develop
686fi
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000687if is_service_enabled melange; then
Jason Kölker64a90662012-01-23 11:17:27 -0600688 cd $MELANGECLIENT_DIR; sudo python setup.py develop
689fi
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700690
Dean Troyerff603ef2011-11-22 17:48:10 -0600691# Syslog
692# ---------
693
694if [[ $SYSLOG != "False" ]]; then
695 apt_get install -y rsyslog-relp
696 if [[ "$SYSLOG_HOST" = "$HOST_IP" ]]; then
697 # Configure the master host to receive
698 cat <<EOF >/tmp/90-stack-m.conf
699\$ModLoad imrelp
700\$InputRELPServerRun $SYSLOG_PORT
701EOF
702 sudo mv /tmp/90-stack-m.conf /etc/rsyslog.d
703 else
704 # Set rsyslog to send to remote host
705 cat <<EOF >/tmp/90-stack-s.conf
706*.* :omrelp:$SYSLOG_HOST:$SYSLOG_PORT
707EOF
708 sudo mv /tmp/90-stack-s.conf /etc/rsyslog.d
709 fi
710 sudo /usr/sbin/service rsyslog restart
711fi
712
Anthony Younga09ae2f2011-09-15 23:11:29 -0700713# Rabbit
714# ---------
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400715
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000716if is_service_enabled rabbit; then
Anthony Younga09ae2f2011-09-15 23:11:29 -0700717 # Install and start rabbitmq-server
Scott Moser199d76e2011-10-20 12:41:40 -0400718 # the temp file is necessary due to LP: #878600
719 tfile=$(mktemp)
Scott Moseree1b4952011-10-20 13:09:11 -0400720 apt_get install rabbitmq-server > "$tfile" 2>&1
Scott Moser199d76e2011-10-20 12:41:40 -0400721 cat "$tfile"
722 rm -f "$tfile"
Jesse Andrews53ed3872011-10-02 14:28:17 -0400723 # change the rabbit password since the default is "guest"
724 sudo rabbitmqctl change_password guest $RABBIT_PASSWORD
Anthony Younga09ae2f2011-09-15 23:11:29 -0700725fi
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700726
Jesse Andrews24859062011-09-15 21:28:23 -0700727# Mysql
728# ---------
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400729
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000730if is_service_enabled mysql; then
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400731
732 # Seed configuration with mysql password so that apt-get install doesn't
733 # prompt us for a password upon install.
734 cat <<MYSQL_PRESEED | sudo debconf-set-selections
Anthony Young7a549f42011-10-12 07:13:13 +0000735mysql-server-5.1 mysql-server/root_password password $MYSQL_PASSWORD
736mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASSWORD
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400737mysql-server-5.1 mysql-server/start_on_boot boolean true
738MYSQL_PRESEED
739
Jesse Andrews2e536a32011-10-13 11:40:16 -0700740 # while ``.my.cnf`` is not needed for openstack to function, it is useful
741 # as it allows you to access the mysql databases via ``mysql nova`` instead
742 # of having to specify the username/password each time.
Chmouel Boudjnahd5d5b682011-10-13 18:45:42 +0100743 if [[ ! -e $HOME/.my.cnf ]]; then
744 cat <<EOF >$HOME/.my.cnf
745[client]
746user=$MYSQL_USER
Anthony Youngcf145b72011-10-13 15:07:36 -0700747password=$MYSQL_PASSWORD
Chmouel Boudjnahd5d5b682011-10-13 18:45:42 +0100748host=$MYSQL_HOST
749EOF
750 chmod 0600 $HOME/.my.cnf
751 fi
752
Anthony Younga09ae2f2011-09-15 23:11:29 -0700753 # Install and start mysql-server
Scott Moseree1b4952011-10-20 13:09:11 -0400754 apt_get install mysql-server
Jesse Andrews24859062011-09-15 21:28:23 -0700755 # Update the DB to give user ‘$MYSQL_USER’@’%’ full control of the all databases:
James E. Blair92e81992011-10-11 09:26:29 -0500756 sudo mysql -uroot -p$MYSQL_PASSWORD -h127.0.0.1 -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' identified by '$MYSQL_PASSWORD';"
Jesse Andrews24859062011-09-15 21:28:23 -0700757
758 # Edit /etc/mysql/my.cnf to change ‘bind-address’ from localhost (127.0.0.1) to any (0.0.0.0) and restart the mysql service:
759 sudo sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
760 sudo service mysql restart
761fi
762
763
Tres Henryca85b792011-10-28 14:00:21 -0700764# Horizon
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700765# ---------
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400766
Tres Henryca85b792011-10-28 14:00:21 -0700767# Setup the django horizon application to serve via apache/wsgi
Jesse Andrews75a37652011-09-12 17:09:08 -0700768
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000769if is_service_enabled horizon; then
Jesse Andrews24859062011-09-15 21:28:23 -0700770
Jesse Andrews38df1222011-11-20 09:55:44 -0800771 # Install apache2, which is NOPRIME'd
772 apt_get install apache2 libapache2-mod-wsgi
773
Dave Lapsley5a09c922012-01-25 17:22:15 -0500774 # Link to quantum client directory.
Gabriel Hurleyf1a11ad2012-02-29 01:36:53 -0800775 rm -fr ${HORIZON_DIR}/openstack_dashboard/quantum
776 ln -s ${QUANTUM_CLIENT_DIR}/quantum ${HORIZON_DIR}/openstack_dashboard/quantum
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400777
Anthony Younga575d502012-01-26 12:59:26 -0800778 # Remove stale session database.
Gabriel Hurleyf1a11ad2012-02-29 01:36:53 -0800779 rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400780
Tres Henryca85b792011-10-28 14:00:21 -0700781 # ``local_settings.py`` is used to override horizon default settings.
Gabriel Hurleyf1a11ad2012-02-29 01:36:53 -0800782 local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
Jesse Andrews9c7c9082011-11-23 10:10:53 -0800783 cp $FILES/horizon_settings.py $local_settings
784
785 # Enable quantum in dashboard, if requested
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000786 if is_service_enabled quantum; then
Jesse Andrews9c7c9082011-11-23 10:10:53 -0800787 sudo sed -e "s,QUANTUM_ENABLED = False,QUANTUM_ENABLED = True,g" -i $local_settings
788 fi
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700789
Tres Henryca85b792011-10-28 14:00:21 -0700790 # Initialize the horizon database (it stores sessions and notices shown to
Jesse Andrews51fb22e2011-10-19 09:24:17 -0700791 # users). The user system is external (keystone).
Gabriel Hurleyf1a11ad2012-02-29 01:36:53 -0800792 cd $HORIZON_DIR
Vishvananda Ishaya19b2f9b2012-01-05 22:21:08 +0000793 python manage.py syncdb
Jesse Andrews75a37652011-09-12 17:09:08 -0700794
Anthony Young70dc5e02011-09-15 16:52:43 -0700795 # create an empty directory that apache uses as docroot
Tres Henryca85b792011-10-28 14:00:21 -0700796 sudo mkdir -p $HORIZON_DIR/.blackhole
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700797
Tres Henryca85b792011-10-28 14:00:21 -0700798 ## Configure apache's 000-default to run horizon
Jesse Andrewsbf3868d2011-09-16 11:31:16 -0700799 sudo cp $FILES/000-default.template /etc/apache2/sites-enabled/000-default
Dean Troyer9bb84f02012-01-24 11:45:52 -0600800 sudo sed -e "
801 s,%USER%,$APACHE_USER,g;
802 s,%GROUP%,$APACHE_GROUP,g;
803 s,%HORIZON_DIR%,$HORIZON_DIR,g;
804 " -i /etc/apache2/sites-enabled/000-default
Jesse Andrewsc96b0242011-10-28 10:34:26 -0700805 sudo service apache2 restart
Anthony Young70dc5e02011-09-15 16:52:43 -0700806fi
Jesse Andrews75a37652011-09-12 17:09:08 -0700807
Anthony Young3859f732011-09-14 02:33:43 -0700808
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700809# Glance
810# ------
811
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000812if is_service_enabled g-reg; then
Anthony Youngc8357622011-09-20 10:38:06 -0700813 GLANCE_IMAGE_DIR=$DEST/glance/images
Anthony Younga531b772011-09-20 09:59:54 -0700814 # Delete existing images
815 rm -rf $GLANCE_IMAGE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700816
Anthony Younga531b772011-09-20 09:59:54 -0700817 # Use local glance directories
818 mkdir -p $GLANCE_IMAGE_DIR
819
Anthony Young70dc5e02011-09-15 16:52:43 -0700820 # (re)create glance database
Anthony Young7a549f42011-10-12 07:13:13 +0000821 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS glance;'
822 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE glance;'
Jesse Andrews51fb22e2011-10-19 09:24:17 -0700823
Dean Troyer6577b462012-01-16 22:27:20 -0600824 function glance_config {
825 sudo sed -e "
Dean Troyerb3288382012-02-28 16:41:10 -0600826 s,%KEYSTONE_API_PORT%,$KEYSTONE_API_PORT,g;
Dean Troyer6577b462012-01-16 22:27:20 -0600827 s,%KEYSTONE_AUTH_HOST%,$KEYSTONE_AUTH_HOST,g;
828 s,%KEYSTONE_AUTH_PORT%,$KEYSTONE_AUTH_PORT,g;
829 s,%KEYSTONE_AUTH_PROTOCOL%,$KEYSTONE_AUTH_PROTOCOL,g;
830 s,%KEYSTONE_SERVICE_HOST%,$KEYSTONE_SERVICE_HOST,g;
831 s,%KEYSTONE_SERVICE_PORT%,$KEYSTONE_SERVICE_PORT,g;
832 s,%KEYSTONE_SERVICE_PROTOCOL%,$KEYSTONE_SERVICE_PROTOCOL,g;
833 s,%SQL_CONN%,$BASE_SQL_CONN/glance,g;
Dean Troyerb3288382012-02-28 16:41:10 -0600834 s,%SERVICE_TENANT_NAME%,$SERVICE_TENANT_NAME,g;
835 s,%SERVICE_USERNAME%,glance,g;
836 s,%SERVICE_PASSWORD%,$SERVICE_PASSWORD,g;
Dean Troyer6577b462012-01-16 22:27:20 -0600837 s,%SERVICE_TOKEN%,$SERVICE_TOKEN,g;
838 s,%DEST%,$DEST,g;
839 s,%SYSLOG%,$SYSLOG,g;
840 " -i $1
841 }
842
Jesse Andrews51fb22e2011-10-19 09:24:17 -0700843 # Copy over our glance configurations and update them
Dean Troyer6577b462012-01-16 22:27:20 -0600844 GLANCE_REGISTRY_CONF=$GLANCE_DIR/etc/glance-registry.conf
845 cp $FILES/glance-registry.conf $GLANCE_REGISTRY_CONF
846 glance_config $GLANCE_REGISTRY_CONF
847
848 if [[ -e $FILES/glance-registry-paste.ini ]]; then
849 GLANCE_REGISTRY_PASTE_INI=$GLANCE_DIR/etc/glance-registry-paste.ini
850 cp $FILES/glance-registry-paste.ini $GLANCE_REGISTRY_PASTE_INI
851 glance_config $GLANCE_REGISTRY_PASTE_INI
Dean Troyer6577b462012-01-16 22:27:20 -0600852 fi
Anthony Youngf12d3ab2011-09-20 00:33:51 -0700853
854 GLANCE_API_CONF=$GLANCE_DIR/etc/glance-api.conf
855 cp $FILES/glance-api.conf $GLANCE_API_CONF
Dean Troyer6577b462012-01-16 22:27:20 -0600856 glance_config $GLANCE_API_CONF
857
858 if [[ -e $FILES/glance-api-paste.ini ]]; then
859 GLANCE_API_PASTE_INI=$GLANCE_DIR/etc/glance-api-paste.ini
860 cp $FILES/glance-api-paste.ini $GLANCE_API_PASTE_INI
861 glance_config $GLANCE_API_PASTE_INI
Dean Troyer6577b462012-01-16 22:27:20 -0600862 fi
Anthony Young70dc5e02011-09-15 16:52:43 -0700863fi
Jesse Andrews75a37652011-09-12 17:09:08 -0700864
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700865# Nova
866# ----
Dean Troyerbd13b702012-02-13 11:22:36 -0600867
868# Put config files in /etc/nova for everyone to find
Dean Troyerced65172012-03-02 16:36:16 -0600869NOVA_CONF_DIR=/etc/nova
870if [[ ! -d $NOVA_CONF_DIR ]]; then
871 sudo mkdir -p $NOVA_CONF_DIR
Dean Troyerbd13b702012-02-13 11:22:36 -0600872fi
Dean Troyerced65172012-03-02 16:36:16 -0600873sudo chown `whoami` $NOVA_CONF_DIR
Dean Troyerbd13b702012-02-13 11:22:36 -0600874
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000875if is_service_enabled n-api; then
Vishvananda Ishaya9812ffb2011-11-06 11:18:26 -0800876 # We are going to use a sample http middleware configuration based on the
877 # one from the keystone project to launch nova. This paste config adds
Vishvananda Ishayaea4a53d2012-01-11 11:34:13 -0800878 # the configuration required for nova to validate keystone tokens.
879
Vishvananda Ishaya7a103dd2012-02-23 23:35:43 +0000880 # Remove legacy paste config
881 rm -f $NOVA_DIR/bin/nova-api-paste.ini
882
Vishvananda Ishayaea4a53d2012-01-11 11:34:13 -0800883 # First we add a some extra data to the default paste config from nova
Dean Troyerced65172012-03-02 16:36:16 -0600884 cp $NOVA_DIR/etc/nova/api-paste.ini $NOVA_CONF_DIR
Vishvananda Ishayaea4a53d2012-01-11 11:34:13 -0800885
886 # Then we add our own service token to the configuration
Dean Troyerb3288382012-02-28 16:41:10 -0600887 sed -e "
888 /^admin_token/i admin_tenant_name = $SERVICE_TENANT_NAME
889 /admin_tenant_name/s/^.*$/admin_tenant_name = $SERVICE_TENANT_NAME/;
890 /admin_user/s/^.*$/admin_user = nova/;
891 /admin_password/s/^.*$/admin_password = $SERVICE_PASSWORD/;
892 s,%SERVICE_TENANT_NAME%,$SERVICE_TENANT_NAME,g;
893 s,%SERVICE_TOKEN%,$SERVICE_TOKEN,g;
Dean Troyerced65172012-03-02 16:36:16 -0600894 " -i $NOVA_CONF_DIR/api-paste.ini
Vishvananda Ishayaea4a53d2012-01-11 11:34:13 -0800895
896 # Finally, we change the pipelines in nova to use keystone
897 function replace_pipeline() {
Dean Troyerced65172012-03-02 16:36:16 -0600898 sed "/\[pipeline:$1\]/,/\[/s/^pipeline = .*/pipeline = $2/" -i $NOVA_CONF_DIR/api-paste.ini
Vishvananda Ishayaea4a53d2012-01-11 11:34:13 -0800899 }
Vishvananda Ishayacb5dd672012-01-23 17:36:42 -0800900 replace_pipeline "ec2cloud" "ec2faultwrap logrequest totoken authtoken keystonecontext cloudrequest authorizer validator ec2executor"
Vishvananda Ishayaea4a53d2012-01-11 11:34:13 -0800901 replace_pipeline "ec2admin" "ec2faultwrap logrequest totoken authtoken keystonecontext adminrequest authorizer ec2executor"
John Garbutt890061c2012-02-24 14:39:17 +0000902 # allow people to turn off rate limiting for testing, like when using tempest, by setting OSAPI_RATE_LIMIT=" "
903 OSAPI_RATE_LIMIT=${OSAPI_RATE_LIMIT:-"ratelimit"}
904 replace_pipeline "openstack_compute_api_v2" "faultwrap authtoken keystonecontext $OSAPI_RATE_LIMIT osapi_compute_app_v2"
905 replace_pipeline "openstack_volume_api_v1" "faultwrap authtoken keystonecontext $OSAPI_RATE_LIMIT osapi_volume_app_v1"
Jesse Andrewsf70569e2011-10-24 21:56:25 -0700906fi
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700907
Anthony Young55458452011-12-17 00:21:49 +0000908# Helper to clean iptables rules
909function clean_iptables() {
910 # Delete rules
911 sudo iptables -S -v | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-A" | sed "s/-A/-D/g" | awk '{print "sudo iptables",$0}' | bash
912 # Delete nat rules
913 sudo iptables -S -v -t nat | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-A" | sed "s/-A/-D/g" | awk '{print "sudo iptables -t nat",$0}' | bash
914 # Delete chains
915 sudo iptables -S -v | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-N" | sed "s/-N/-X/g" | awk '{print "sudo iptables",$0}' | bash
916 # Delete nat chains
917 sudo iptables -S -v -t nat | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-N" | sed "s/-N/-X/g" | awk '{print "sudo iptables -t nat",$0}' | bash
918}
919
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000920if is_service_enabled n-cpu; then
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700921
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400922 # Virtualization Configuration
923 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Scott Moser6b549fd2011-12-08 16:22:27 -0500924 apt_get install libvirt-bin
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400925
Dean Troyer0b31e862012-03-07 16:47:56 -0600926 # Force IP forwarding on, just on case
927 sudo sysctl -w net.ipv4.ip_forward=1
928
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400929 # attempt to load modules: network block device - used to manage qcow images
Anthony Young70dc5e02011-09-15 16:52:43 -0700930 sudo modprobe nbd || true
Jesse Andrewsc6d30422011-10-02 13:11:28 -0400931
Vishvananda Ishaya9b353672011-10-20 10:07:10 -0700932 # Check for kvm (hardware based virtualization). If unable to initialize
933 # kvm, we drop back to the slower emulation mode (qemu). Note: many systems
Jesse Andrews51fb22e2011-10-19 09:24:17 -0700934 # come with hardware virtualization disabled in BIOS.
Jesse Andrews2abbdd42011-10-03 22:48:30 -0400935 if [[ "$LIBVIRT_TYPE" == "kvm" ]]; then
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400936 sudo modprobe kvm || true
Jesse Andrewsc6d30422011-10-02 13:11:28 -0400937 if [ ! -e /dev/kvm ]; then
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400938 echo "WARNING: Switching to QEMU"
Jesse Andrewsc6d30422011-10-02 13:11:28 -0400939 LIBVIRT_TYPE=qemu
940 fi
Jesse Andrewsd1879c52011-09-16 16:28:13 -0700941 fi
Jesse Andrewsc6d30422011-10-02 13:11:28 -0400942
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400943 # Install and configure **LXC** if specified. LXC is another approach to
944 # splitting a system into many smaller parts. LXC uses cgroups and chroot
945 # to simulate multiple systems.
Jesse Andrews2abbdd42011-10-03 22:48:30 -0400946 if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
Scott Moser3f5e1892011-12-08 16:21:52 -0500947 if [[ "$DISTRO" > natty ]]; then
948 apt_get install cgroup-lite
949 else
950 cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0"
951 sudo mkdir -p /cgroup
952 if ! grep -q cgroup /etc/fstab; then
953 echo "$cgline" | sudo tee -a /etc/fstab
954 fi
955 if ! mount -n | grep -q cgroup; then
956 sudo mount /cgroup
957 fi
Jesse Andrewse4304232011-10-07 10:34:32 -0400958 fi
Jesse Andrewsc6d30422011-10-02 13:11:28 -0400959 fi
960
Jesse Andrews51fb22e2011-10-19 09:24:17 -0700961 # The user that nova runs as needs to be member of libvirtd group otherwise
962 # nova-compute will be unable to use libvirt.
Anthony Young70dc5e02011-09-15 16:52:43 -0700963 sudo usermod -a -G libvirtd `whoami`
Vishvananda Ishaya9b353672011-10-20 10:07:10 -0700964 # libvirt detects various settings on startup, as we potentially changed
Jesse Andrews51fb22e2011-10-19 09:24:17 -0700965 # the system configuration (modules, filesystems), we need to restart
966 # libvirt to detect those changes.
Anthony Young70dc5e02011-09-15 16:52:43 -0700967 sudo /etc/init.d/libvirt-bin restart
968
Jesse Andrewscbe98d52011-10-02 17:47:32 -0400969
970 # Instance Storage
971 # ~~~~~~~~~~~~~~~~
972
973 # Nova stores each instance in its own directory.
Anthony Young70dc5e02011-09-15 16:52:43 -0700974 mkdir -p $NOVA_DIR/instances
975
Jesse Andrews51fb22e2011-10-19 09:24:17 -0700976 # You can specify a different disk to be mounted and used for backing the
Vishvananda Ishaya9b353672011-10-20 10:07:10 -0700977 # virtual machines. If there is a partition labeled nova-instances we
Jesse Andrews51fb22e2011-10-19 09:24:17 -0700978 # mount it (ext filesystems can be labeled via e2label).
Anthony Young70dc5e02011-09-15 16:52:43 -0700979 if [ -L /dev/disk/by-label/nova-instances ]; then
Jesse Andrews38df1222011-11-20 09:55:44 -0800980 if ! mount -n | grep -q $NOVA_DIR/instances; then
Jesse Andrews51fb22e2011-10-19 09:24:17 -0700981 sudo mount -L nova-instances $NOVA_DIR/instances
982 sudo chown -R `whoami` $NOVA_DIR/instances
983 fi
Anthony Young70dc5e02011-09-15 16:52:43 -0700984 fi
985
Anthony Young55458452011-12-17 00:21:49 +0000986 # Clean iptables from previous runs
987 clean_iptables
988
989 # Destroy old instances
Anthony Young33d50292012-01-04 09:32:48 -0800990 instances=`virsh list --all | grep $INSTANCE_NAME_PREFIX | sed "s/.*\($INSTANCE_NAME_PREFIX[0-9a-fA-F]*\).*/\1/g"`
Anthony Youngedef2442012-01-20 12:45:32 -0800991 if [ ! "$instances" = "" ]; then
Anthony Young33d50292012-01-04 09:32:48 -0800992 echo $instances | xargs -n1 virsh destroy || true
993 echo $instances | xargs -n1 virsh undefine || true
Anthony Young55458452011-12-17 00:21:49 +0000994 fi
995
Anthony Young4f830e12012-02-11 00:17:31 -0800996 # Logout and delete iscsi sessions
997 sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d " " -f2 | xargs sudo iscsiadm --mode node --logout || true
998 sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d " " -f2 | sudo iscsiadm --mode node --op delete || true
999
Jesse Andrewscbe98d52011-10-02 17:47:32 -04001000 # Clean out the instances directory.
Jesse Andrews461bfdc2011-10-09 17:50:38 -07001001 sudo rm -rf $NOVA_DIR/instances/*
Jesse Andrewsdfcd2002011-09-13 13:17:22 -07001002fi
1003
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001004if is_service_enabled n-net; then
Anthony Young55458452011-12-17 00:21:49 +00001005 # Delete traces of nova networks from prior runs
Anthony Young09fde812011-09-20 02:23:54 -07001006 sudo killall dnsmasq || true
Anthony Young55458452011-12-17 00:21:49 +00001007 clean_iptables
Anthony Young70dc5e02011-09-15 16:52:43 -07001008 rm -rf $NOVA_DIR/networks
1009 mkdir -p $NOVA_DIR/networks
Dean Troyer0b31e862012-03-07 16:47:56 -06001010
1011 # Force IP forwarding on, just on case
1012 sudo sysctl -w net.ipv4.ip_forward=1
Anthony Young70dc5e02011-09-15 16:52:43 -07001013fi
Jesse Andrews75a37652011-09-12 17:09:08 -07001014
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +01001015# Storage Service
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001016if is_service_enabled swift; then
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +01001017 # We first do a bit of setup by creating the directories and
1018 # changing the permissions so we can run it as our user.
1019
Chmouel Boudjnah067163d2011-11-02 14:25:06 +01001020 USER_GROUP=$(id -g)
Chmouel Boudjnah38750152011-11-03 09:17:06 +01001021 sudo mkdir -p ${SWIFT_DATA_LOCATION}/drives
Chmouel Boudjnah769eb1c2011-11-22 13:04:40 +01001022 sudo chown -R $USER:${USER_GROUP} ${SWIFT_DATA_LOCATION}
Vishvananda Ishaya5f039322011-11-05 16:12:20 -07001023
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +01001024 # We then create a loopback disk and format it to XFS.
Chmouel Boudjnah769eb1c2011-11-22 13:04:40 +01001025 # TODO: Reset disks on new pass.
Chmouel Boudjnahf990ded2011-11-14 15:26:13 +01001026 if [[ ! -e ${SWIFT_DATA_LOCATION}/drives/images/swift.img ]]; then
Chmouel Boudjnah38750152011-11-03 09:17:06 +01001027 mkdir -p ${SWIFT_DATA_LOCATION}/drives/images
1028 sudo touch ${SWIFT_DATA_LOCATION}/drives/images/swift.img
1029 sudo chown $USER: ${SWIFT_DATA_LOCATION}/drives/images/swift.img
Vishvananda Ishaya5f039322011-11-05 16:12:20 -07001030
Chmouel Boudjnah38750152011-11-03 09:17:06 +01001031 dd if=/dev/zero of=${SWIFT_DATA_LOCATION}/drives/images/swift.img \
Chmouel Boudjnahb93478f2011-11-02 16:49:56 +01001032 bs=1024 count=0 seek=${SWIFT_LOOPBACK_DISK_SIZE}
Chmouel Boudjnah38750152011-11-03 09:17:06 +01001033 mkfs.xfs -f -i size=1024 ${SWIFT_DATA_LOCATION}/drives/images/swift.img
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +01001034 fi
1035
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +01001036 # After the drive being created we mount the disk with a few mount
1037 # options to make it most efficient as possible for swift.
Chmouel Boudjnah38750152011-11-03 09:17:06 +01001038 mkdir -p ${SWIFT_DATA_LOCATION}/drives/sdb1
Chmouel Boudjnahf990ded2011-11-14 15:26:13 +01001039 if ! egrep -q ${SWIFT_DATA_LOCATION}/drives/sdb1 /proc/mounts; then
Chmouel Boudjnahb93478f2011-11-02 16:49:56 +01001040 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
Chmouel Boudjnah38750152011-11-03 09:17:06 +01001041 ${SWIFT_DATA_LOCATION}/drives/images/swift.img ${SWIFT_DATA_LOCATION}/drives/sdb1
Chmouel Boudjnaha03f0052011-11-01 13:08:29 +00001042 fi
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +01001043
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +01001044 # We then create link to that mounted location so swift would know
1045 # where to go.
Chmouel Boudjnaha95efab2012-02-16 10:35:26 +00001046 for x in $(seq ${SWIFT_REPLICAS}); do
1047 sudo ln -sf ${SWIFT_DATA_LOCATION}/drives/sdb1/$x ${SWIFT_DATA_LOCATION}/$x; done
Vishvananda Ishaya5f039322011-11-05 16:12:20 -07001048
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +01001049 # We now have to emulate a few different servers into one we
Vishvananda Ishaya5f039322011-11-05 16:12:20 -07001050 # create all the directories needed for swift
Chmouel Boudjnaha95efab2012-02-16 10:35:26 +00001051 for x in $(seq ${SWIFT_REPLICAS}); do
1052 drive=${SWIFT_DATA_LOCATION}/drives/sdb1/${x}
1053 node=${SWIFT_DATA_LOCATION}/${x}/node
1054 node_device=${node}/sdb1
1055 [[ -d $node ]] && continue
1056 [[ -d $drive ]] && continue
1057 sudo install -o ${USER} -g $USER_GROUP -d $drive
1058 sudo install -o ${USER} -g $USER_GROUP -d $node_device
1059 sudo chown -R $USER: ${node}
Chmouel Boudjnahe1d2bcb2011-11-01 17:32:11 +01001060 done
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +01001061
Chmouel Boudjnaha95efab2012-02-16 10:35:26 +00001062 sudo mkdir -p ${SWIFT_CONFIG_LOCATION}/{object,container,account}-server /var/run/swift
1063 sudo chown -R $USER: ${SWIFT_CONFIG_LOCATION} /var/run/swift
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +01001064
Chmouel Boudjnah3a648262011-11-03 10:43:46 +01001065 # swift-init has a bug using /etc/swift until bug #885595 is fixed
1066 # we have to create a link
Chmouel Boudjnah2f2160e2011-11-10 23:46:08 +01001067 sudo ln -sf ${SWIFT_CONFIG_LOCATION} /etc/swift
Vishvananda Ishaya5f039322011-11-05 16:12:20 -07001068
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +01001069 # Swift use rsync to syncronize between all the different
1070 # partitions (which make more sense when you have a multi-node
1071 # setup) we configure it with our version of rsync.
Chmouel Boudjnah38750152011-11-03 09:17:06 +01001072 sed -e "s/%GROUP%/${USER_GROUP}/;s/%USER%/$USER/;s,%SWIFT_DATA_LOCATION%,$SWIFT_DATA_LOCATION," $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
Chmouel Boudjnahe1d2bcb2011-11-01 17:32:11 +01001073 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
Chmouel Boudjnah45c51132011-11-01 19:32:23 +01001074
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +01001075 # By default Swift will be installed with the tempauth middleware
1076 # which has some default username and password if you have
1077 # configured keystone it will checkout the directory.
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001078 if is_service_enabled key; then
Chmouel Boudjnah8534bcb2012-02-25 08:04:48 +00001079 swift_auth_server="s3token tokenauth keystone"
Chmouel Boudjnah45c51132011-11-01 19:32:23 +01001080 else
1081 swift_auth_server=tempauth
1082 fi
1083
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +01001084 # We do the install of the proxy-server and swift configuration
1085 # replacing a few directives to match our configuration.
Dean Troyerb3288382012-02-28 16:41:10 -06001086 sed -e "
1087 s,%SWIFT_CONFIG_LOCATION%,${SWIFT_CONFIG_LOCATION},g;
1088 s,%USER%,$USER,g;
1089 s,%SERVICE_TENANT_NAME%,$SERVICE_TENANT_NAME,g;
1090 s,%SERVICE_USERNAME%,swift,g;
1091 s,%SERVICE_PASSWORD%,$SERVICE_PASSWORD,g;
1092 s,%SERVICE_TOKEN%,${SERVICE_TOKEN},g;
1093 s,%KEYSTONE_SERVICE_PORT%,${KEYSTONE_SERVICE_PORT},g;
1094 s,%KEYSTONE_SERVICE_HOST%,${KEYSTONE_SERVICE_HOST},g;
1095 s,%KEYSTONE_API_PORT%,${KEYSTONE_API_PORT},g;
1096 s,%KEYSTONE_AUTH_HOST%,${KEYSTONE_AUTH_HOST},g;
1097 s,%KEYSTONE_AUTH_PORT%,${KEYSTONE_AUTH_PORT},g;
1098 s,%KEYSTONE_AUTH_PROTOCOL%,${KEYSTONE_AUTH_PROTOCOL},g;
1099 s/%AUTH_SERVER%/${swift_auth_server}/g;
1100 " $FILES/swift/proxy-server.conf | \
Chmouel Boudjnah8534bcb2012-02-25 08:04:48 +00001101 sudo tee ${SWIFT_CONFIG_LOCATION}/proxy-server.conf
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +01001102
Chmouel Boudjnah3a648262011-11-03 10:43:46 +01001103 sed -e "s/%SWIFT_HASH%/$SWIFT_HASH/" $FILES/swift/swift.conf > ${SWIFT_CONFIG_LOCATION}/swift.conf
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +01001104
1105 # We need to generate a object/account/proxy configuration
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +01001106 # emulating 4 nodes on different ports we have a little function
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +01001107 # that help us doing that.
1108 function generate_swift_configuration() {
1109 local server_type=$1
1110 local bind_port=$2
1111 local log_facility=$3
Chmouel Boudjnah45c51132011-11-01 19:32:23 +01001112 local node_number
Vishvananda Ishaya5f039322011-11-05 16:12:20 -07001113
Chmouel Boudjnaha95efab2012-02-16 10:35:26 +00001114 for node_number in $(seq ${SWIFT_REPLICAS}); do
Chmouel Boudjnah38750152011-11-03 09:17:06 +01001115 node_path=${SWIFT_DATA_LOCATION}/${node_number}
Chmouel Boudjnah3a648262011-11-03 10:43:46 +01001116 sed -e "s,%SWIFT_CONFIG_LOCATION%,${SWIFT_CONFIG_LOCATION},;s,%USER%,$USER,;s,%NODE_PATH%,${node_path},;s,%BIND_PORT%,${bind_port},;s,%LOG_FACILITY%,${log_facility}," \
1117 $FILES/swift/${server_type}-server.conf > ${SWIFT_CONFIG_LOCATION}/${server_type}-server/${node_number}.conf
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +01001118 bind_port=$(( ${bind_port} + 10 ))
1119 log_facility=$(( ${log_facility} + 1 ))
1120 done
1121 }
1122 generate_swift_configuration object 6010 2
1123 generate_swift_configuration container 6011 2
1124 generate_swift_configuration account 6012 2
Chmouel Boudjnaha03f0052011-11-01 13:08:29 +00001125
Chmouel Boudjnah769eb1c2011-11-22 13:04:40 +01001126
1127 # We have some specific configuration for swift for rsyslog. See
1128 # the file /etc/rsyslog.d/10-swift.conf for more info.
1129 swift_log_dir=${SWIFT_DATA_LOCATION}/logs
1130 rm -rf ${swift_log_dir}
1131 mkdir -p ${swift_log_dir}/hourly
1132 sudo chown -R syslog:adm ${swift_log_dir}
1133 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
1134 tee /etc/rsyslog.d/10-swift.conf
1135 sudo restart rsyslog
Vishvananda Ishayaea4a53d2012-01-11 11:34:13 -08001136
Chmouel Boudjnaha95efab2012-02-16 10:35:26 +00001137 # This is where we create three different rings for swift with
1138 # different object servers binding on different ports.
1139 pushd ${SWIFT_CONFIG_LOCATION} >/dev/null && {
1140
1141 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
1142
1143 port_number=6010
1144 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
1145 for x in $(seq ${SWIFT_REPLICAS}); do
1146 swift-ring-builder object.builder add z${x}-127.0.0.1:${port_number}/sdb1 1
1147 port_number=$[port_number + 10]
1148 done
1149 swift-ring-builder object.builder rebalance
1150
1151 port_number=6011
1152 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
1153 for x in $(seq ${SWIFT_REPLICAS}); do
1154 swift-ring-builder container.builder add z${x}-127.0.0.1:${port_number}/sdb1 1
1155 port_number=$[port_number + 10]
1156 done
1157 swift-ring-builder container.builder rebalance
1158
1159 port_number=6012
1160 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
1161 for x in $(seq ${SWIFT_REPLICAS}); do
1162 swift-ring-builder account.builder add z${x}-127.0.0.1:${port_number}/sdb1 1
1163 port_number=$[port_number + 10]
1164 done
1165 swift-ring-builder account.builder rebalance
1166
1167 } && popd >/dev/null
1168
Chmouel Boudjnaha2118982011-11-01 15:36:00 +01001169 sudo chmod +x /usr/local/bin/swift-*
1170
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +01001171 # We then can start rsync.
Chmouel Boudjnahe1d2bcb2011-11-01 17:32:11 +01001172 sudo /etc/init.d/rsync restart || :
Vishvananda Ishaya5f039322011-11-05 16:12:20 -07001173
Chmouel Boudjnaha95efab2012-02-16 10:35:26 +00001174 # TODO: Bring some services in foreground.
1175 # Launch all services.
1176 swift-init all start
Chmouel Boudjnahd5651bb2011-11-01 16:22:08 +01001177
Chmouel Boudjnaha95efab2012-02-16 10:35:26 +00001178 unset s swift_hash swift_auth_server
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +01001179fi
1180
Anthony Youngacff87a2011-10-20 10:12:58 -07001181# Volume Service
1182# --------------
1183
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001184if is_service_enabled n-vol; then
Anthony Youngacff87a2011-10-20 10:12:58 -07001185 #
1186 # Configure a default volume group called 'nova-volumes' for the nova-volume
1187 # service if it does not yet exist. If you don't wish to use a file backed
1188 # volume group, create your own volume group called 'nova-volumes' before
1189 # invoking stack.sh.
1190 #
1191 # By default, the backing file is 2G in size, and is stored in /opt/stack.
Jesse Andrews38df1222011-11-20 09:55:44 -08001192
Vishvananda Ishaya524aa542012-01-14 01:08:34 +00001193 # install the package
1194 apt_get install tgt
Jesse Andrews38df1222011-11-20 09:55:44 -08001195
Dean Troyer2229a6e2011-12-01 17:02:07 -06001196 if ! sudo vgs $VOLUME_GROUP; then
Todd Willeyb244ef32011-11-03 18:19:21 -04001197 VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DEST/nova-volumes-backing-file}
Anthony Youngb22263a2011-10-20 10:26:30 -07001198 VOLUME_BACKING_FILE_SIZE=${VOLUME_BACKING_FILE_SIZE:-2052M}
Dean Troyer2229a6e2011-12-01 17:02:07 -06001199 # Only create if the file doesn't already exists
1200 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
Anthony Youngacff87a2011-10-20 10:12:58 -07001201 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
Dean Troyer2229a6e2011-12-01 17:02:07 -06001202 # Only create if the loopback device doesn't contain $VOLUME_GROUP
1203 if ! sudo vgs $VOLUME_GROUP; then sudo vgcreate $VOLUME_GROUP $DEV; fi
1204 fi
1205
1206 if sudo vgs $VOLUME_GROUP; then
Anthony Young63252162012-02-08 00:54:20 +00001207 # Remove nova iscsi targets
1208 sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
Dean Troyer2229a6e2011-12-01 17:02:07 -06001209 # Clean out existing volumes
1210 for lv in `sudo lvs --noheadings -o lv_name $VOLUME_GROUP`; do
1211 # VOLUME_NAME_PREFIX prefixes the LVs we want
1212 if [[ "${lv#$VOLUME_NAME_PREFIX}" != "$lv" ]]; then
Dean Troyer2229a6e2011-12-01 17:02:07 -06001213 sudo lvremove -f $VOLUME_GROUP/$lv
1214 fi
1215 done
Anthony Youngacff87a2011-10-20 10:12:58 -07001216 fi
1217
Vishvananda Ishaya524aa542012-01-14 01:08:34 +00001218 # tgt in oneiric doesn't restart properly if tgtd isn't running
1219 # do it in two steps
1220 sudo stop tgt || true
1221 sudo start tgt
Anthony Youngacff87a2011-10-20 10:12:58 -07001222fi
1223
Dean Troyerced65172012-03-02 16:36:16 -06001224NOVA_CONF=nova.conf
1225function add_nova_opt {
1226 echo "$1" >> $NOVA_CONF_DIR/$NOVA_CONF
Jesse Andrewsd1879c52011-09-16 16:28:13 -07001227}
1228
Vishvananda Ishaya7a103dd2012-02-23 23:35:43 +00001229# remove legacy nova.conf
1230rm -f $NOVA_DIR/bin/nova.conf
1231
Jesse Andrewsd1879c52011-09-16 16:28:13 -07001232# (re)create nova.conf
Dean Troyerced65172012-03-02 16:36:16 -06001233rm -f $NOVA_CONF_DIR/$NOVA_CONF
1234add_nova_opt "[DEFAULT]"
1235add_nova_opt "verbose=True"
Vishvananda Ishaya50aef3b2012-03-05 23:12:04 -08001236add_nova_opt "auth_strategy=keystone"
Dean Troyerced65172012-03-02 16:36:16 -06001237add_nova_opt "allow_resize_to_same_host=True"
Dean Troyere0d677c2012-03-07 14:11:33 -06001238add_nova_opt "root_helper=sudo /usr/local/bin/nova-rootwrap"
Vishvananda Ishaya51aa4012012-03-06 12:45:19 -08001239add_nova_opt "compute_scheduler_driver=$SCHEDULER"
Dean Troyerced65172012-03-02 16:36:16 -06001240add_nova_opt "dhcpbridge_flagfile=$NOVA_CONF_DIR/$NOVA_CONF"
1241add_nova_opt "fixed_range=$FIXED_RANGE"
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001242if is_service_enabled n-obj; then
Dean Troyerced65172012-03-02 16:36:16 -06001243 add_nova_opt "s3_host=$SERVICE_HOST"
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +00001244fi
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001245if is_service_enabled quantum; then
Dean Troyerced65172012-03-02 16:36:16 -06001246 add_nova_opt "network_manager=nova.network.quantum.manager.QuantumManager"
1247 add_nova_opt "quantum_connection_host=$Q_HOST"
1248 add_nova_opt "quantum_connection_port=$Q_PORT"
Jason Kölker64a90662012-01-23 11:17:27 -06001249
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001250 if is_service_enabled melange; then
Dean Troyerced65172012-03-02 16:36:16 -06001251 add_nova_opt "quantum_ipam_lib=nova.network.quantum.melange_ipam_lib"
1252 add_nova_opt "use_melange_mac_generation=True"
1253 add_nova_opt "melange_host=$M_HOST"
1254 add_nova_opt "melange_port=$M_PORT"
Jason Kölker64a90662012-01-23 11:17:27 -06001255 fi
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001256 if is_service_enabled q-svc && [[ "$Q_PLUGIN" = "openvswitch" ]]; then
Dean Troyerced65172012-03-02 16:36:16 -06001257 add_nova_opt "libvirt_vif_type=ethernet"
1258 add_nova_opt "libvirt_vif_driver=nova.virt.libvirt.vif.LibvirtOpenVswitchDriver"
1259 add_nova_opt "linuxnet_interface_driver=nova.network.linux_net.LinuxOVSInterfaceDriver"
1260 add_nova_opt "quantum_use_dhcp=True"
Brad Hall1bfa3d52011-10-27 18:18:20 -07001261 fi
1262else
Dean Troyerced65172012-03-02 16:36:16 -06001263 add_nova_opt "network_manager=nova.network.manager.$NET_MAN"
Brad Hall1bfa3d52011-10-27 18:18:20 -07001264fi
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001265if is_service_enabled n-vol; then
Dean Troyerced65172012-03-02 16:36:16 -06001266 add_nova_opt "volume_group=$VOLUME_GROUP"
1267 add_nova_opt "volume_name_template=${VOLUME_NAME_PREFIX}%08x"
Vishvananda Ishaya524aa542012-01-14 01:08:34 +00001268 # oneiric no longer supports ietadm
Dean Troyerced65172012-03-02 16:36:16 -06001269 add_nova_opt "iscsi_helper=tgtadm"
Jesse Andrewsd02b7b72011-11-14 08:59:05 -08001270fi
Dean Troyerced65172012-03-02 16:36:16 -06001271add_nova_opt "osapi_compute_extension=nova.api.openstack.compute.contrib.standard_extensions"
1272add_nova_opt "my_ip=$HOST_IP"
1273add_nova_opt "public_interface=$PUBLIC_INTERFACE"
1274add_nova_opt "vlan_interface=$VLAN_INTERFACE"
1275add_nova_opt "flat_network_bridge=$FLAT_NETWORK_BRIDGE"
John Garbutt8e2cffd2012-03-02 16:22:07 +00001276if [ -n "$FLAT_INTERFACE" ]; then
Dean Troyerced65172012-03-02 16:36:16 -06001277 add_nova_opt "flat_interface=$FLAT_INTERFACE"
John Garbutt8e2cffd2012-03-02 16:22:07 +00001278fi
Dean Troyerced65172012-03-02 16:36:16 -06001279add_nova_opt "sql_connection=$BASE_SQL_CONN/nova"
1280add_nova_opt "libvirt_type=$LIBVIRT_TYPE"
1281add_nova_opt "instance_name_template=${INSTANCE_NAME_PREFIX}%08x"
Anthony Young2fcb6662012-02-03 20:17:22 +00001282# All nova-compute workers need to know the vnc configuration options
1283# These settings don't hurt anything if n-xvnc and n-novnc are disabled
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001284if is_service_enabled n-cpu; then
Anthony Youngce116912012-01-17 15:46:53 -08001285 NOVNCPROXY_URL=${NOVNCPROXY_URL:-"http://$SERVICE_HOST:6080/vnc_auto.html"}
Dean Troyerced65172012-03-02 16:36:16 -06001286 add_nova_opt "novncproxy_base_url=$NOVNCPROXY_URL"
Anthony Youngce116912012-01-17 15:46:53 -08001287 XVPVNCPROXY_URL=${XVPVNCPROXY_URL:-"http://$SERVICE_HOST:6081/console"}
Dean Troyerced65172012-03-02 16:36:16 -06001288 add_nova_opt "xvpvncproxy_base_url=$XVPVNCPROXY_URL"
Anthony Youngce116912012-01-17 15:46:53 -08001289fi
1290if [ "$VIRT_DRIVER" = 'xenserver' ]; then
1291 VNCSERVER_PROXYCLIENT_ADDRESS=${VNCSERVER_PROXYCLIENT_ADDRESS=169.254.0.1}
1292else
1293 VNCSERVER_PROXYCLIENT_ADDRESS=${VNCSERVER_PROXYCLIENT_ADDRESS=127.0.0.1}
1294fi
Anthony Young50fc5c62012-01-26 09:38:33 -08001295# Address on which instance vncservers will listen on compute hosts.
1296# For multi-host, this should be the management ip of the compute host.
1297VNCSERVER_LISTEN=${VNCSERVER_LISTEN=127.0.0.1}
Dean Troyerced65172012-03-02 16:36:16 -06001298add_nova_opt "vncserver_listen=$VNCSERVER_LISTEN"
1299add_nova_opt "vncserver_proxyclient_address=$VNCSERVER_PROXYCLIENT_ADDRESS"
1300add_nova_opt "api_paste_config=$NOVA_CONF_DIR/api-paste.ini"
1301add_nova_opt "image_service=nova.image.glance.GlanceImageService"
1302add_nova_opt "ec2_dmz_host=$EC2_DMZ_HOST"
1303add_nova_opt "rabbit_host=$RABBIT_HOST"
1304add_nova_opt "rabbit_password=$RABBIT_PASSWORD"
1305add_nova_opt "glance_api_servers=$GLANCE_HOSTPORT"
1306add_nova_opt "force_dhcp_release=True"
Vishvananda Ishaya3e2b1742011-10-28 12:20:07 -07001307if [ -n "$INSTANCES_PATH" ]; then
Dean Troyerced65172012-03-02 16:36:16 -06001308 add_nova_opt "instances_path=$INSTANCES_PATH"
Vishvananda Ishayae72bdb02011-10-28 13:34:38 -07001309fi
Vishvananda Ishaya5f039322011-11-05 16:12:20 -07001310if [ "$MULTI_HOST" != "False" ]; then
Dean Troyerced65172012-03-02 16:36:16 -06001311 add_nova_opt "multi_host=True"
1312 add_nova_opt "send_arp_for_ha=True"
Jesse Andrewsd1879c52011-09-16 16:28:13 -07001313fi
James E. Blair5855a642011-10-26 15:44:27 -04001314if [ "$SYSLOG" != "False" ]; then
Dean Troyerced65172012-03-02 16:36:16 -06001315 add_nova_opt "use_syslog=True"
James E. Blair5855a642011-10-26 15:44:27 -04001316fi
Jesse Andrewsd1879c52011-09-16 16:28:13 -07001317
Dean Troyerced65172012-03-02 16:36:16 -06001318# Provide some transition from EXTRA_FLAGS to EXTRA_OPTS
1319if [[ -z "$EXTRA_OPTS" && -n "$EXTRA_FLAGS" ]]; then
1320 EXTRA_OPTS=$EXTRA_FLAGS
1321fi
1322
1323# You can define extra nova conf flags by defining the array EXTRA_OPTS,
1324# For Example: EXTRA_OPTS=(foo=true bar=2)
1325for I in "${EXTRA_OPTS[@]}"; do
1326 # Attempt to convert flags to options
1327 add_nova_opt ${I//-}
Jesse Andrews38df1222011-11-20 09:55:44 -08001328done
1329
Anthony Youngb62b4ca2011-10-26 22:29:08 -07001330# XenServer
1331# ---------
1332
1333if [ "$VIRT_DRIVER" = 'xenserver' ]; then
1334 read_password XENAPI_PASSWORD "ENTER A PASSWORD TO USE FOR XEN."
Dean Troyerced65172012-03-02 16:36:16 -06001335 add_nova_opt "connection_type=xenapi"
John Garbutt92e85602012-03-02 16:08:37 +00001336 XENAPI_CONNECTION_URL=${XENAPI_CONNECTION_URL:-"http://169.254.0.1"}
Dean Troyerced65172012-03-02 16:36:16 -06001337 add_nova_opt "xenapi_connection_url=$XENAPI_CONNECTION_URL"
1338 add_nova_opt "xenapi_connection_username=root"
1339 add_nova_opt "xenapi_connection_password=$XENAPI_PASSWORD"
1340 add_nova_opt "flat_injected=False"
Anthony Youngce116912012-01-17 15:46:53 -08001341 # Need to avoid crash due to new firewall support
1342 XEN_FIREWALL_DRIVER=${XEN_FIREWALL_DRIVER:-"nova.virt.firewall.IptablesFirewallDriver"}
Dean Troyerced65172012-03-02 16:36:16 -06001343 add_nova_opt "firewall_driver=$XEN_FIREWALL_DRIVER"
Anthony Youngb62b4ca2011-10-26 22:29:08 -07001344else
Dean Troyerced65172012-03-02 16:36:16 -06001345 add_nova_opt "connection_type=libvirt"
Armando Migliaccio34f62492012-01-31 14:33:19 +00001346 LIBVIRT_FIREWALL_DRIVER=${LIBVIRT_FIREWALL_DRIVER:-"nova.virt.libvirt.firewall.IptablesFirewallDriver"}
Dean Troyerced65172012-03-02 16:36:16 -06001347 add_nova_opt "firewall_driver=$LIBVIRT_FIREWALL_DRIVER"
Anthony Youngb62b4ca2011-10-26 22:29:08 -07001348fi
1349
Jesse Andrewscbe98d52011-10-02 17:47:32 -04001350# Nova Database
1351# ~~~~~~~~~~~~~
1352
1353# All nova components talk to a central database. We will need to do this step
1354# only once for an entire cluster.
1355
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001356if is_service_enabled mysql; then
Anthony Younga0748002011-09-16 21:37:36 -07001357 # (re)create nova database
Anthony Young7a549f42011-10-12 07:13:13 +00001358 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS nova;'
1359 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE nova;'
Jesse Andrewscbe98d52011-10-02 17:47:32 -04001360
1361 # (re)create nova database
Anthony Younga0748002011-09-16 21:37:36 -07001362 $NOVA_DIR/bin/nova-manage db sync
Anthony Younga0748002011-09-16 21:37:36 -07001363fi
1364
1365
Jesse Andrewsd74257d2011-09-13 01:24:50 -07001366# Launch Services
1367# ===============
Jesse Andrews30f68e92011-09-13 00:59:54 -07001368
Jesse Andrews1c1d1502011-09-12 19:29:56 -07001369# nova api crashes if we start it with a regular screen command,
1370# so send the start command by forcing text into the window.
Jesse Andrewsdfcd2002011-09-13 13:17:22 -07001371# Only run the services specified in ``ENABLED_SERVICES``
1372
Derrick J. Wippleraaa0dbb2012-02-21 09:53:53 -06001373# Our screenrc file builder
1374function screen_rc {
1375 SCREENRC=$TOP_DIR/stack-screenrc
1376 if [[ ! -e $SCREENRC ]]; then
1377 # Name the screen session
1378 echo "sessionname stack" > $SCREENRC
1379 # Set a reasonable statusbar
1380 echo 'hardstatus alwayslastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%< %= %H"' >> $SCREENRC
1381 echo "screen -t stack bash" >> $SCREENRC
1382 fi
1383 # If this service doesn't already exist in the screenrc file
1384 if ! grep $1 $SCREENRC 2>&1 > /dev/null; then
1385 NL=`echo -ne '\015'`
1386 echo "screen -t $1 bash" >> $SCREENRC
1387 echo "stuff \"$2$NL\"" >> $SCREENRC
1388 fi
1389}
1390
1391# Our screen helper to launch a service in a hidden named screen
Jesse Andrews1c1d1502011-09-12 19:29:56 -07001392function screen_it {
Jesse Andrews1f717602011-09-16 15:18:53 -07001393 NL=`echo -ne '\015'`
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001394 if is_service_enabled $1; then
Derrick J. Wippleraaa0dbb2012-02-21 09:53:53 -06001395 # Append the service to the screen rc file
1396 screen_rc "$1" "$2"
1397
Chmouel Boudjnah36867ad2012-02-09 16:27:58 +01001398 screen -S stack -X screen -t $1
1399 # sleep to allow bash to be ready to be send the command - we are
1400 # creating a new window in screen and then sends characters, so if
1401 # bash isn't running by the time we send the command, nothing happens
1402 sleep 1.5
Chmouel Boudjnahd966ed22012-03-05 12:42:48 +00001403
1404 if [[ -n ${SCREEN_LOGDIR} ]]; then
1405 screen -S stack -p $1 -X logfile ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log
1406 screen -S stack -p $1 -X log on
1407 ln -sf ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${1}.log
1408 fi
Chmouel Boudjnah36867ad2012-02-09 16:27:58 +01001409 screen -S stack -p $1 -X stuff "$2$NL"
Anthony Young292e46d2011-09-13 11:28:56 -07001410 fi
Jesse Andrews1c1d1502011-09-12 19:29:56 -07001411}
1412
Jesse Andrewsa16e5e92011-09-16 16:30:55 -07001413# create a new named screen to run processes in
Chmouel Boudjnah73c70892012-02-09 16:36:15 +01001414screen -d -m -S stack -t stack -s /bin/bash
Jesse Andrewsa16e5e92011-09-16 16:30:55 -07001415sleep 1
Jesse Andrewsd9eafd52011-12-10 13:55:44 -08001416# set a reasonable statusbar
1417screen -r stack -X hardstatus alwayslastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%< %= %H"
Jesse Andrewsa16e5e92011-09-16 16:30:55 -07001418
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +01001419# launch the glance registry service
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001420if is_service_enabled g-reg; then
Anthony Youngd000b222011-09-19 14:46:53 -07001421 screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
1422fi
1423
Jesse Andrews644b8e82011-10-02 17:50:41 -04001424# launch the glance api and wait for it to answer before continuing
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001425if is_service_enabled g-api; then
Anthony Youngd000b222011-09-19 14:46:53 -07001426 screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
James E. Blair92e81992011-10-11 09:26:29 -05001427 echo "Waiting for g-api ($GLANCE_HOSTPORT) to start..."
Dean Troyerc727aa82012-01-13 12:13:59 -06001428 if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://$GLANCE_HOSTPORT; do sleep 1; done"; then
James E. Blair92e81992011-10-11 09:26:29 -05001429 echo "g-api did not start"
1430 exit 1
1431 fi
Anthony Youngd000b222011-09-19 14:46:53 -07001432fi
1433
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001434if is_service_enabled key; then
termieeacc5952012-01-11 01:59:00 +00001435 # (re)create keystone database
1436 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS keystone;'
1437 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE keystone;'
1438
1439 # Configure keystone.conf
1440 KEYSTONE_CONF=$KEYSTONE_DIR/etc/keystone.conf
1441 cp $FILES/keystone.conf $KEYSTONE_CONF
1442 sudo sed -e "s,%SQL_CONN%,$BASE_SQL_CONN/keystone,g" -i $KEYSTONE_CONF
1443 sudo sed -e "s,%DEST%,$DEST,g" -i $KEYSTONE_CONF
1444 sudo sed -e "s,%SERVICE_TOKEN%,$SERVICE_TOKEN,g" -i $KEYSTONE_CONF
termie50edca62012-01-11 02:04:39 +00001445 sudo sed -e "s,%KEYSTONE_DIR%,$KEYSTONE_DIR,g" -i $KEYSTONE_CONF
termieeacc5952012-01-11 01:59:00 +00001446
1447 KEYSTONE_CATALOG=$KEYSTONE_DIR/etc/default_catalog.templates
1448 cp $FILES/default_catalog.templates $KEYSTONE_CATALOG
Gabriel Hurley7bd30872012-02-23 13:20:03 -08001449
1450 # Add swift endpoints to service catalog if swift is enabled
1451 if is_service_enabled swift; then
Gabriel Hurley155266b2012-02-23 16:54:01 -08001452 echo "catalog.RegionOne.object_store.publicURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
Gabriel Hurley7bd30872012-02-23 13:20:03 -08001453 echo "catalog.RegionOne.object_store.adminURL = http://%SERVICE_HOST%:8080/" >> $KEYSTONE_CATALOG
Gabriel Hurley155266b2012-02-23 16:54:01 -08001454 echo "catalog.RegionOne.object_store.internalURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
Gabriel Hurley7bd30872012-02-23 13:20:03 -08001455 echo "catalog.RegionOne.object_store.name = 'Swift Service'" >> $KEYSTONE_CATALOG
1456 fi
1457
1458 # Add quantum endpoints to service catalog if quantum is enabled
1459 if is_service_enabled quantum; then
1460 echo "catalog.RegionOne.network.publicURL = http://%SERVICE_HOST%:9696/" >> $KEYSTONE_CATALOG
1461 echo "catalog.RegionOne.network.adminURL = http://%SERVICE_HOST%:9696/" >> $KEYSTONE_CATALOG
1462 echo "catalog.RegionOne.network.internalURL = http://%SERVICE_HOST%:9696/" >> $KEYSTONE_CATALOG
1463 echo "catalog.RegionOne.network.name = 'Quantum Service'" >> $KEYSTONE_CATALOG
1464 fi
1465
termieeacc5952012-01-11 01:59:00 +00001466 sudo sed -e "s,%SERVICE_HOST%,$SERVICE_HOST,g" -i $KEYSTONE_CATALOG
1467
1468
1469 if [ "$SYSLOG" != "False" ]; then
Joe Heck708a2ad2012-01-18 10:19:15 -08001470 cp $KEYSTONE_DIR/etc/logging.conf.sample $KEYSTONE_DIR/etc/logging.conf
termieeacc5952012-01-11 01:59:00 +00001471 sed -i -e '/^handlers=devel$/s/=devel/=production/' \
Joe Heck708a2ad2012-01-18 10:19:15 -08001472 $KEYSTONE_DIR/etc/logging.conf
termieeacc5952012-01-11 01:59:00 +00001473 sed -i -e "/^log_file/s/log_file/\#log_file/" \
1474 $KEYSTONE_DIR/etc/keystone.conf
Joe Heck708a2ad2012-01-18 10:19:15 -08001475 KEYSTONE_LOG_CONFIG="--log-config $KEYSTONE_DIR/etc/logging.conf"
termieeacc5952012-01-11 01:59:00 +00001476 fi
1477fi
1478
Jesse Andrews644b8e82011-10-02 17:50:41 -04001479# launch the keystone and wait for it to answer before continuing
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001480if is_service_enabled key; then
termie8a41c9d2012-02-02 17:31:19 -08001481 screen_it key "cd $KEYSTONE_DIR && $KEYSTONE_DIR/bin/keystone-all --config-file $KEYSTONE_CONF $KEYSTONE_LOG_CONFIG -d --debug"
James E. Blair92e81992011-10-11 09:26:29 -05001482 echo "Waiting for keystone to start..."
Dean Troyerb3288382012-02-28 16:41:10 -06001483 if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- $KEYSTONE_AUTH_PROTOCOL://$SERVICE_HOST:$KEYSTONE_API_PORT/v2.0/; do sleep 1; done"; then
James E. Blair92e81992011-10-11 09:26:29 -05001484 echo "keystone did not start"
1485 exit 1
1486 fi
termieeacc5952012-01-11 01:59:00 +00001487
termieeacc5952012-01-11 01:59:00 +00001488 # initialize keystone with default users/endpoints
Joe Heck708a2ad2012-01-18 10:19:15 -08001489 pushd $KEYSTONE_DIR
termieeacc5952012-01-11 01:59:00 +00001490 $KEYSTONE_DIR/bin/keystone-manage db_sync
Joe Heck708a2ad2012-01-18 10:19:15 -08001491 popd
Vishvananda Ishayad1f52432012-02-09 03:50:57 +00001492
1493 # keystone_data.sh creates services, admin and demo users, and roles.
1494 SERVICE_ENDPOINT=$KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0
Dean Troyerb3288382012-02-28 16:41:10 -06001495 ADMIN_PASSWORD=$ADMIN_PASSWORD SERVICE_TENANT_NAME=$SERVICE_TENANT_NAME SERVICE_PASSWORD=$SERVICE_PASSWORD SERVICE_TOKEN=$SERVICE_TOKEN SERVICE_ENDPOINT=$SERVICE_ENDPOINT DEVSTACK_DIR=$TOP_DIR ENABLED_SERVICES=$ENABLED_SERVICES \
1496 bash $FILES/keystone_data.sh
Anthony Youngd000b222011-09-19 14:46:53 -07001497fi
1498
termieeacc5952012-01-11 01:59:00 +00001499
Jesse Andrews644b8e82011-10-02 17:50:41 -04001500# launch the nova-api and wait for it to answer before continuing
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001501if is_service_enabled n-api; then
Anthony Young9bf3d762011-09-20 09:51:16 -07001502 screen_it n-api "cd $NOVA_DIR && $NOVA_DIR/bin/nova-api"
James E. Blair92e81992011-10-11 09:26:29 -05001503 echo "Waiting for nova-api to start..."
Dean Troyerc727aa82012-01-13 12:13:59 -06001504 if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://127.0.0.1:8774; do sleep 1; done"; then
James E. Blair92e81992011-10-11 09:26:29 -05001505 echo "nova-api did not start"
1506 exit 1
1507 fi
Anthony Youngd000b222011-09-19 14:46:53 -07001508fi
Brad Hall1bfa3d52011-10-27 18:18:20 -07001509
Brad Hallf1f3a8f2011-12-12 23:04:58 +00001510# Quantum service
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001511if is_service_enabled q-svc; then
Brad Hall1bfa3d52011-10-27 18:18:20 -07001512 if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
Brad Hallf1f3a8f2011-12-12 23:04:58 +00001513 # Install deps
1514 # FIXME add to files/apts/quantum, but don't install if not needed!
1515 apt_get install openvswitch-switch openvswitch-datapath-dkms
1516 # Create database for the plugin/agent
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001517 if is_service_enabled mysql; then
Dan Wendlandtde37dbd2012-01-23 01:56:22 -08001518 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS ovs_quantum;'
Brad Hall1bfa3d52011-10-27 18:18:20 -07001519 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE IF NOT EXISTS ovs_quantum;'
1520 else
Brad Halld9e544e2011-10-28 08:28:26 -07001521 echo "mysql must be enabled in order to use the $Q_PLUGIN Quantum plugin."
1522 exit 1
Brad Hall1bfa3d52011-10-27 18:18:20 -07001523 fi
Brad Hallf1f3a8f2011-12-12 23:04:58 +00001524 QUANTUM_PLUGIN_INI_FILE=$QUANTUM_DIR/etc/plugins.ini
1525 # Make sure we're using the openvswitch plugin
1526 sed -i -e "s/^provider =.*$/provider = quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPlugin/g" $QUANTUM_PLUGIN_INI_FILE
Brad Hall1bfa3d52011-10-27 18:18:20 -07001527 fi
Dave Lapsley5a09c922012-01-25 17:22:15 -05001528 screen_it q-svc "cd $QUANTUM_DIR && PYTHONPATH=.:$QUANTUM_CLIENT_DIR:$PYTHONPATH python $QUANTUM_DIR/bin/quantum-server $QUANTUM_DIR/etc/quantum.conf"
Brad Hall1bfa3d52011-10-27 18:18:20 -07001529fi
1530
1531# Quantum agent (for compute nodes)
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001532if is_service_enabled q-agt; then
Brad Hall1bfa3d52011-10-27 18:18:20 -07001533 if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
1534 # Set up integration bridge
1535 OVS_BRIDGE=${OVS_BRIDGE:-br-int}
1536 sudo ovs-vsctl --no-wait -- --if-exists del-br $OVS_BRIDGE
1537 sudo ovs-vsctl --no-wait add-br $OVS_BRIDGE
1538 sudo ovs-vsctl --no-wait br-set-external-id $OVS_BRIDGE bridge-id br-int
Dan Wendlandtf5fb0572012-01-16 14:46:01 -08001539
1540 # Start up the quantum <-> openvswitch agent
1541 QUANTUM_OVS_CONFIG_FILE=$QUANTUM_DIR/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini
1542 sed -i -e "s/^sql_connection =.*$/sql_connection = mysql:\/\/$MYSQL_USER:$MYSQL_PASSWORD@$MYSQL_HOST\/ovs_quantum/g" $QUANTUM_OVS_CONFIG_FILE
1543 screen_it q-agt "sleep 4; sudo python $QUANTUM_DIR/quantum/plugins/openvswitch/agent/ovs_quantum_agent.py $QUANTUM_OVS_CONFIG_FILE -v"
Brad Hall1bfa3d52011-10-27 18:18:20 -07001544 fi
1545
Brad Hall1bfa3d52011-10-27 18:18:20 -07001546fi
1547
Jason Kölker64a90662012-01-23 11:17:27 -06001548# Melange service
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001549if is_service_enabled m-svc; then
1550 if is_service_enabled mysql; then
Jason Kölker64a90662012-01-23 11:17:27 -06001551 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS melange;'
1552 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE melange;'
1553 else
1554 echo "mysql must be enabled in order to use the $Q_PLUGIN Quantum plugin."
1555 exit 1
1556 fi
1557 MELANGE_CONFIG_FILE=$MELANGE_DIR/etc/melange/melange.conf
1558 cp $MELANGE_CONFIG_FILE.sample $MELANGE_CONFIG_FILE
1559 sed -i -e "s/^sql_connection =.*$/sql_connection = mysql:\/\/$MYSQL_USER:$MYSQL_PASSWORD@$MYSQL_HOST\/melange/g" $MELANGE_CONFIG_FILE
1560 cd $MELANGE_DIR && PYTHONPATH=.:$PYTHONPATH python $MELANGE_DIR/bin/melange-manage --config-file=$MELANGE_CONFIG_FILE db_sync
1561 screen_it m-svc "cd $MELANGE_DIR && PYTHONPATH=.:$PYTHONPATH python $MELANGE_DIR/bin/melange-server --config-file=$MELANGE_CONFIG_FILE"
1562 echo "Waiting for melange to start..."
1563 if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://127.0.0.1:9898; do sleep 1; done"; then
1564 echo "melange-server did not start"
1565 exit 1
1566 fi
1567 melange mac_address_range create cidr=$M_MAC_RANGE
1568fi
1569
Brad Halld9e544e2011-10-28 08:28:26 -07001570# If we're using Quantum (i.e. q-svc is enabled), network creation has to
1571# happen after we've started the Quantum service.
Ken Pepple389f4ef2012-03-08 19:37:03 -08001572if is_service_enabled mysql && is_service_enabled nova; then
Brad Hall1bfa3d52011-10-27 18:18:20 -07001573 # create a small network
1574 $NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 $FIXED_NETWORK_SIZE
1575
Tomoe Sugihara1c77d702012-03-12 21:49:54 +09001576 # create some floating ips
1577 $NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
Dean Troyer696ad332012-01-10 15:34:34 -06001578
Tomoe Sugihara1c77d702012-03-12 21:49:54 +09001579 # create a second pool
1580 $NOVA_DIR/bin/nova-manage floating create --ip_range=$TEST_FLOATING_RANGE --pool=$TEST_FLOATING_POOL
Brad Hall1bfa3d52011-10-27 18:18:20 -07001581fi
1582
Jason Kölker64a90662012-01-23 11:17:27 -06001583
root40a37002011-09-20 18:06:14 +00001584# Launching nova-compute should be as simple as running ``nova-compute`` but
1585# have to do a little more than that in our script. Since we add the group
Jesse Andrews1f717602011-09-16 15:18:53 -07001586# ``libvirtd`` to our user in this script, when nova-compute is run it is
root40a37002011-09-20 18:06:14 +00001587# within the context of our original shell (so our groups won't be updated).
Scott Moser8ab1ade2011-10-07 21:03:16 -04001588# Use 'sg' to execute nova-compute as a member of the libvirtd group.
Ken Pepple389f4ef2012-03-08 19:37:03 -08001589# We don't check for is_service_enable as screen_it does it for us
Scott Moser8ab1ade2011-10-07 21:03:16 -04001590screen_it n-cpu "cd $NOVA_DIR && sg libvirtd $NOVA_DIR/bin/nova-compute"
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +00001591screen_it n-crt "cd $NOVA_DIR && $NOVA_DIR/bin/nova-cert"
1592screen_it n-obj "cd $NOVA_DIR && $NOVA_DIR/bin/nova-objectstore"
Anthony Youngacff87a2011-10-20 10:12:58 -07001593screen_it n-vol "cd $NOVA_DIR && $NOVA_DIR/bin/nova-volume"
Anthony Young9bf3d762011-09-20 09:51:16 -07001594screen_it n-net "cd $NOVA_DIR && $NOVA_DIR/bin/nova-network"
1595screen_it n-sch "cd $NOVA_DIR && $NOVA_DIR/bin/nova-scheduler"
Ken Pepple389f4ef2012-03-08 19:37:03 -08001596screen_it n-novnc "cd $NOVNC_DIR && ./utils/nova-novncproxy --config-file $NOVA_CONF_DIR/$NOVA_CONF --web ."
1597screen_it n-xvnc "cd $NOVA_DIR && ./bin/nova-xvpvncproxy --config-file $NOVA_CONF_DIR/$NOVA_CONF"
1598screen_it n-cauth "cd $NOVA_DIR && ./bin/nova-consoleauth"
1599screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/apache2/error.log"
Jesse Andrews75a37652011-09-12 17:09:08 -07001600
Jesse Andrewsd74257d2011-09-13 01:24:50 -07001601# Install Images
1602# ==============
Jesse Andrewse49b8bd2011-09-12 18:08:04 -07001603
Anthony Young0ab1d462011-10-13 23:03:23 -07001604# Upload an image to glance.
Jesse Andrews5372f432011-10-03 01:08:24 -04001605#
Anthony Young0ab1d462011-10-13 23:03:23 -07001606# The default image is a small ***TTY*** testing image, which lets you login
1607# the username/password of root/password.
1608#
1609# TTY also uses cloud-init, supporting login via keypair and sending scripts as
1610# userdata. See https://help.ubuntu.com/community/CloudInit for more on cloud-init
1611#
Chmouel Boudjnah3d9c5d52011-11-02 17:57:11 +01001612# Override ``IMAGE_URLS`` with a comma-separated list of uec images.
Jesse Andrewsaab7eae2011-10-19 10:30:19 -07001613#
1614# * **natty**: http://uec-images.ubuntu.com/natty/current/natty-server-cloudimg-amd64.tar.gz
1615# * **oneiric**: http://uec-images.ubuntu.com/oneiric/current/oneiric-server-cloudimg-amd64.tar.gz
Jesse Andrews08e8b742011-10-02 23:42:56 -04001616
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001617if is_service_enabled g-reg; then
Anthony Young7a8989e2011-10-14 10:20:30 -07001618 # Create a directory for the downloaded image tarballs.
Jesse Andrews08e8b742011-10-02 23:42:56 -04001619 mkdir -p $FILES/images
1620
termie747ee332012-01-11 22:31:59 +00001621 ADMIN_USER=admin
1622 ADMIN_TENANT=admin
1623 TOKEN=`curl -s -d "{\"auth\":{\"passwordCredentials\": {\"username\": \"$ADMIN_USER\", \"password\": \"$ADMIN_PASSWORD\"}, \"tenantName\": \"$ADMIN_TENANT\"}}" -H "Content-type: application/json" http://$HOST_IP:5000/v2.0/tokens | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['access']['token']['id'];"`
1624
Anthony Youngb62b4ca2011-10-26 22:29:08 -07001625 # Option to upload legacy ami-tty, which works with xenserver
1626 if [ $UPLOAD_LEGACY_TTY ]; then
1627 if [ ! -f $FILES/tty.tgz ]; then
1628 wget -c http://images.ansolabs.com/tty.tgz -O $FILES/tty.tgz
1629 fi
1630
1631 tar -zxf $FILES/tty.tgz -C $FILES/images
Jesse Andrews7052f722012-03-03 00:51:46 -08001632 RVAL=`glance add --silent-upload -A $TOKEN name="tty-kernel" is_public=true container_format=aki disk_format=aki < $FILES/images/aki-tty/image`
Anthony Youngb62b4ca2011-10-26 22:29:08 -07001633 KERNEL_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "`
Jesse Andrews7052f722012-03-03 00:51:46 -08001634 RVAL=`glance add --silent-upload -A $TOKEN name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < $FILES/images/ari-tty/image`
Anthony Youngb62b4ca2011-10-26 22:29:08 -07001635 RAMDISK_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "`
termie747ee332012-01-11 22:31:59 +00001636 glance add -A $TOKEN name="tty" is_public=true container_format=ami disk_format=ami kernel_id=$KERNEL_ID ramdisk_id=$RAMDISK_ID < $FILES/images/ami-tty/image
Anthony Youngb62b4ca2011-10-26 22:29:08 -07001637 fi
1638
Anthony Young120f4862011-10-14 09:31:09 -07001639 for image_url in ${IMAGE_URLS//,/ }; do
1640 # Downloads the image (uec ami+aki style), then extracts it.
Jesse Andrewsac1831e2011-10-24 21:37:00 -07001641 IMAGE_FNAME=`basename "$image_url"`
Anthony Young120f4862011-10-14 09:31:09 -07001642 if [ ! -f $FILES/$IMAGE_FNAME ]; then
1643 wget -c $image_url -O $FILES/$IMAGE_FNAME
1644 fi
Jesse Andrewse49b8bd2011-09-12 18:08:04 -07001645
Scott Moser4f6d7b62011-12-08 16:22:51 -05001646 KERNEL=""
1647 RAMDISK=""
1648 case "$IMAGE_FNAME" in
1649 *.tar.gz|*.tgz)
1650 # Extract ami and aki files
1651 [ "${IMAGE_FNAME%.tar.gz}" != "$IMAGE_FNAME" ] &&
1652 IMAGE_NAME="${IMAGE_FNAME%.tar.gz}" ||
1653 IMAGE_NAME="${IMAGE_FNAME%.tgz}"
1654 xdir="$FILES/images/$IMAGE_NAME"
1655 rm -Rf "$xdir";
1656 mkdir "$xdir"
1657 tar -zxf $FILES/$IMAGE_FNAME -C "$xdir"
1658 KERNEL=$(for f in "$xdir/"*-vmlinuz*; do
1659 [ -f "$f" ] && echo "$f" && break; done; true)
1660 RAMDISK=$(for f in "$xdir/"*-initrd*; do
1661 [ -f "$f" ] && echo "$f" && break; done; true)
1662 IMAGE=$(for f in "$xdir/"*.img; do
1663 [ -f "$f" ] && echo "$f" && break; done; true)
1664 [ -n "$IMAGE_NAME" ]
1665 IMAGE_NAME=$(basename "$IMAGE" ".img")
1666 ;;
1667 *.img)
1668 IMAGE="$FILES/$IMAGE_FNAME";
1669 IMAGE_NAME=$(basename "$IMAGE" ".img")
1670 ;;
1671 *.img.gz)
1672 IMAGE="$FILES/${IMAGE_FNAME}"
1673 IMAGE_NAME=$(basename "$IMAGE" ".img.gz")
1674 ;;
1675 *) echo "Do not know what to do with $IMAGE_FNAME"; false;;
1676 esac
Anthony Young70dc5e02011-09-15 16:52:43 -07001677
Anthony Young120f4862011-10-14 09:31:09 -07001678 # Use glance client to add the kernel the root filesystem.
1679 # We parse the results of the first upload to get the glance ID of the
1680 # kernel for use when uploading the root filesystem.
Scott Moser4f6d7b62011-12-08 16:22:51 -05001681 KERNEL_ID=""; RAMDISK_ID="";
1682 if [ -n "$KERNEL" ]; then
Jesse Andrews7052f722012-03-03 00:51:46 -08001683 RVAL=`glance add --silent-upload -A $TOKEN name="$IMAGE_NAME-kernel" is_public=true container_format=aki disk_format=aki < "$KERNEL"`
Scott Moser4f6d7b62011-12-08 16:22:51 -05001684 KERNEL_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "`
1685 fi
1686 if [ -n "$RAMDISK" ]; then
Jesse Andrews7052f722012-03-03 00:51:46 -08001687 RVAL=`glance add --silent-upload -A $TOKEN name="$IMAGE_NAME-ramdisk" is_public=true container_format=ari disk_format=ari < "$RAMDISK"`
Scott Moser4f6d7b62011-12-08 16:22:51 -05001688 RAMDISK_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "`
1689 fi
termie747ee332012-01-11 22:31:59 +00001690 glance add -A $TOKEN name="${IMAGE_NAME%.img}" is_public=true container_format=ami disk_format=ami ${KERNEL_ID:+kernel_id=$KERNEL_ID} ${RAMDISK_ID:+ramdisk_id=$RAMDISK_ID} < <(zcat --force "${IMAGE}")
Anthony Young120f4862011-10-14 09:31:09 -07001691 done
Jesse Andrewse49b8bd2011-09-12 18:08:04 -07001692fi
Jesse Andrews24859062011-09-15 21:28:23 -07001693
Scott Moserb94f4bf2011-10-07 14:51:07 +00001694# Fin
1695# ===
1696
Dean Troyer471de7a2011-12-27 11:45:55 -06001697set +o xtrace
Scott Moserb94f4bf2011-10-07 14:51:07 +00001698
Jesse Andrews24859062011-09-15 21:28:23 -07001699# Using the cloud
1700# ===============
1701
Jesse Andrewse19d8842011-11-01 20:06:55 -07001702echo ""
1703echo ""
1704echo ""
1705
Tres Henryca85b792011-10-28 14:00:21 -07001706# If you installed the horizon on this server, then you should be able
root40a37002011-09-20 18:06:14 +00001707# to access the site using your browser.
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001708if is_service_enabled horizon; then
Anthony Young1097c7c2011-12-27 23:22:14 -08001709 echo "horizon is now available at http://$SERVICE_HOST/"
Jesse Andrews24859062011-09-15 21:28:23 -07001710fi
1711
1712# If keystone is present, you can point nova cli to this server
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001713if is_service_enabled key; then
Dean Troyerb3288382012-02-28 16:41:10 -06001714 echo "keystone is serving at $KEYSTONE_AUTH_PROTOCOL://$SERVICE_HOST:$KEYSTONE_API_PORT/v2.0/"
Jesse Andrews24859062011-09-15 21:28:23 -07001715 echo "examples on using novaclient command line is in exercise.sh"
Jesse Andrews89358af2011-10-02 14:11:17 -04001716 echo "the default users are: admin and demo"
1717 echo "the password: $ADMIN_PASSWORD"
Jesse Andrews24859062011-09-15 21:28:23 -07001718fi
termie523c4052011-09-28 19:49:40 -05001719
Anthony Young1097c7c2011-12-27 23:22:14 -08001720# Echo HOST_IP - useful for build_uec.sh, which uses dhcp to give the instance an address
1721echo "This is your host ip: $HOST_IP"
1722
Dean Troyerced65172012-03-02 16:36:16 -06001723# Warn that EXTRA_FLAGS needs to be converted to EXTRA_OPTS
1724if [[ -n "$EXTRA_FLAGS" ]]; then
1725 echo "WARNING: EXTRA_FLAGS is defined and may need to be converted to EXTRA_OPTS"
1726fi
1727
Anthony Young1097c7c2011-12-27 23:22:14 -08001728# Indicate how long this took to run (bash maintained variable 'SECONDS')
Scott Moserb94f4bf2011-10-07 14:51:07 +00001729echo "stack.sh completed in $SECONDS seconds."