blob: ebbb4793b2f6ca2ee77f1299447ff9d1b0884fd1 [file] [log] [blame]
Jesse Andrewsba23cc72011-09-11 03:22:13 -07001#!/usr/bin/env bash
2
Jesse Andrews6f3baaf2011-09-12 11:59:38 -07003# **stack.sh** is rackspace cloudbuilder's opinionated openstack dev installation.
Jesse Andrewsba23cc72011-09-11 03:22:13 -07004
5# Quit script on error
6set -o errexit
7
8# Log commands as they are run for debugging
9set -o xtrace
10
11DIR=`pwd`
12DEST=/opt
Jesse Andrewsba23cc72011-09-11 03:22:13 -070013
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070014# Set the destination directories for openstack projects
Jesse Andrewsba23cc72011-09-11 03:22:13 -070015NOVA_DIR=$DEST/nova
16DASH_DIR=$DEST/dash
17GLANCE_DIR=$DEST/glance
18KEYSTONE_DIR=$DEST/keystone
19NOVACLIENT_DIR=$DEST/python-novaclient
20API_DIR=$DEST/openstackx
21NOVNC_DIR=$DEST/noVNC
22
23# Use the first IP unless an explicit is set by a HOST_IP environment variable
24if [ ! -n "$HOST_IP" ]; then
25 HOST_IP=`LC_ALL=C ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
26fi
27
28# NOVA CONFIGURATION
29INTERFACE=${INTERFACE:-eth0}
30FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27}
31FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
32LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu}
33NET_MAN=${NET_MAN:-VlanManager}
34# NOTE(vish): If you are using FlatDHCP on multiple hosts, set the interface
35# below but make sure that the interface doesn't already have an
36# ip or you risk breaking things.
37# FLAT_INTERFACE=eth0
38
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070039# TODO: set rabbitmq conn string explicitly as well
40# TODO: switch to mysql for all services
Jesse Andrewsba23cc72011-09-11 03:22:13 -070041SQL_CONN=sqlite:///$NOVA_DIR/nova.sqlite
42
Jesse Andrews75a37652011-09-12 17:09:08 -070043# FIXME: commands should be: stack.sh should allow specifying a subset of services
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070044
Jesse Andrews75a37652011-09-12 17:09:08 -070045# install apt requirements
46apt-get install -y -q `cat $DIR/apts/* | cut -d\# -f1`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070047
Jesse Andrews75a37652011-09-12 17:09:08 -070048# install python requirements
49pip install `cat $DIR/pips/*`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070050
Jesse Andrews61632572011-09-12 17:40:00 -070051# git clone only if directory doesn't exist already
52function git_clone {
53 if [ ! -d $2 ]; then
54 git clone $1 $2
55 fi
56}
57
Jesse Andrews75a37652011-09-12 17:09:08 -070058# compute service
Jesse Andrews61632572011-09-12 17:40:00 -070059git_clone https://github.com/cloudbuilders/nova.git $NOVA_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070060# image catalog service
Jesse Andrews61632572011-09-12 17:40:00 -070061git_clone https://github.com/cloudbuilders/glance.git $GLANCE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070062# unified auth system (manages accounts/tokens)
Jesse Andrews61632572011-09-12 17:40:00 -070063git_clone https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070064# a websockets/html5 or flash powered VNC console for vm instances
Jesse Andrews61632572011-09-12 17:40:00 -070065git_clone https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070066# django powered web control panel for openstack
Jesse Andrews61632572011-09-12 17:40:00 -070067git_clone https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070068# python client library to nova that dashboard (and others) use
Jesse Andrews61632572011-09-12 17:40:00 -070069git_clone https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070070# openstackx is a collection of extensions to openstack.compute & nova
71# that is *deprecated*. The code is being moved into python-novaclient & nova.
Jesse Andrews61632572011-09-12 17:40:00 -070072git_clone https://github.com/cloudbuilders/openstackx.git $API_DIR
Jesse Andrewsba23cc72011-09-11 03:22:13 -070073
Jesse Andrews75a37652011-09-12 17:09:08 -070074# setup our checkouts so they are installed into python path
75# allowing `import nova` or `import glance.client`
76cd $NOVACLIENT_DIR; python setup.py develop
77cd $KEYSTONE_DIR; python setup.py develop
78cd $GLANCE_DIR; python setup.py develop
79cd $API_DIR; python setup.py develop
80cd $DASH_DIR/django-openstack; python setup.py develop
81cd $DASH_DIR/openstack-dashboard; python setup.py develop
Jesse Andrewsba23cc72011-09-11 03:22:13 -070082
Jesse Andrews75a37652011-09-12 17:09:08 -070083# attempt to load modules: kvm (hardware virt) and nbd (network block
84# device - used to manage qcow images)
85modprobe nbd || true
86modprobe kvm || true
87# if kvm wasn't running before we need to restart libvirt to enable it
88/etc/init.d/libvirt-bin restart
Jesse Andrewsba23cc72011-09-11 03:22:13 -070089
Jesse Andrews75a37652011-09-12 17:09:08 -070090# setup nova instance directory
91mkdir -p $NOVA_DIR/instances
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070092
Jesse Andrews75a37652011-09-12 17:09:08 -070093# if there is a partition labeled nova-instances use it (ext filesystems
94# can be labeled via e2label)
95if [ -L /dev/disk/by-label/nova-instances ]; then
96 mount -L nova-instances /$NOVA_DIR/instances
Jesse Andrewsba23cc72011-09-11 03:22:13 -070097fi
98
Jesse Andrews75a37652011-09-12 17:09:08 -070099# *Dashboard*: setup django application to serve via apache/wsgi
100
101# Dash currently imports quantum even if you aren't using it. Instead
102# of installing quantum we can create a simple module that will pass the
103# initial imports
104mkdir $DASH_DIR/openstack-dashboard/quantum
105touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
106touch $DASH_DIR/openstack-dashboard/quantum/client.py
107# local_settings has
108cd $DASH_DIR/openstack-dashboard
109cp local/local_settings.py.example local/local_settings.py
110dashboard/manage.py syncdb
111
112# ## Setup Apache
113# create an empty directory to use as our
114mkdir $DASH_DIR/.blackhole
115# FIXME(ja): can't figure out how to make $DASH_DIR work in sed, also install to available/a2e it
116cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /etc/apache2/sites-enabled/000-default
117
118chown -R www-data:www-data $DASH_DIR
119
120mkdir -p /var/log/glance
121
122# prepare initial images for loading into glance
123if [ ! -f $DEST/tty.tgz ]; then
124 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
125fi
126
127mkdir -p $DEST/images
128tar -C $DEST/images -zxf $DEST/tty.tgz
129
130# add useful screenrc
131cp $DIR/files/screenrc ~/.screenrc
132
133# TODO: update current user to allow sudo for all commands in files/sudo/*
134
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700135NL=`echo -ne '\015'`
136
137function screen_it {
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700138 # nova api crashes if we start it with a regular screen command,
139 # so send the start command by forcing text into the window.
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700140 screen -S nova -X screen -t $1
141 screen -S nova -p $1 -X stuff "$2$NL"
142}
143
144function add_nova_flag {
145 echo "$1" >> $NOVA_DIR/bin/nova.conf
146}
147
Jesse Andrews75a37652011-09-12 17:09:08 -0700148# (re)create nova.conf
149rm -f $NOVA_DIR/bin/nova.conf
150add_nova_flag "--verbose"
151add_nova_flag "--nodaemon"
152add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
153add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
154add_nova_flag "--my_ip=$HOST_IP"
155add_nova_flag "--public_interface=$INTERFACE"
156add_nova_flag "--vlan_interface=$INTERFACE"
157add_nova_flag "--sql_connection=$SQL_CONN"
158add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
159add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
160add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
161add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/noVNC/noVNC"
162add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
163add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
164if [ -n "$FLAT_INTERFACE" ]; then
165 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700166fi
167
Jesse Andrews75a37652011-09-12 17:09:08 -0700168# create a new named screen to store things in
169screen -d -m -S nova -t nova
170sleep 1
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700171
Jesse Andrews75a37652011-09-12 17:09:08 -0700172# Clean out the instances directory
173rm -rf $NOVA_DIR/instances/*
174
175# delete traces of nova networks from prior runs
176killall dnsmasq || true
177rm -rf $NOVA_DIR/networks
178mkdir -p $NOVA_DIR/networks
179
180# (re)create nova database
181rm -f $NOVA_DIR/nova.sqlite
182$NOVA_DIR/bin/nova-manage db sync
183
184# initialize keystone with default users/endpoints
185# FIXME(ja): move initial_data.sh into this script
186rm -f /opt/keystone/keystone.db
187curl -OL https://raw.github.com/cloudbuilders/deploy.sh/master/initial_data.sh
188BIN_DIR=$KEYSTONE_DIR/bin bash initial_data.sh
189
190# create a small network
191$NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
192
193# create some floating ips
194$NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
195
196# delete existing glance images/database. Glance will recreate the db
197# when it is ran.
198rm -rf /var/lib/glance/images/*
199rm -f $GLANCE_DIR/glance.sqlite
200
201screen_it n-api "$NOVA_DIR/bin/nova-api"
202screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
203screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
204screen_it cpu "$NOVA_DIR/bin/nova-compute"
205screen_it net "$NOVA_DIR/bin/nova-network"
206screen_it sched "$NOVA_DIR/bin/nova-scheduler"
207screen_it key "$KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf"
208screen_it vnc "$NOVA_DIR/bin/nova-vncproxy"
209screen_it dash "/etc/init.d/apache2 restart; tail -f /var/log/apache2/error.log"
210
211# FIXME: switch to just importing images
212# remove previously converted images
213rm -rf $DIR/images/[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]
214$NOVA_DIR/bin/nova-manage image convert $DIR/images
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700215