blob: 478592f9a7ac5c1d4872ab37755e53a217c26494 [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
Jesse Andrewsbe395c12011-09-12 19:11:30 -07005# FIXME: commands should be: stack.sh should allow specifying a subset of services
6
Jesse Andrewsba23cc72011-09-11 03:22:13 -07007# Quit script on error
8set -o errexit
9
10# Log commands as they are run for debugging
11set -o xtrace
12
13DIR=`pwd`
14DEST=/opt
Jesse Andrewsba23cc72011-09-11 03:22:13 -070015
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070016# Set the destination directories for openstack projects
Jesse Andrewsba23cc72011-09-11 03:22:13 -070017NOVA_DIR=$DEST/nova
18DASH_DIR=$DEST/dash
19GLANCE_DIR=$DEST/glance
20KEYSTONE_DIR=$DEST/keystone
21NOVACLIENT_DIR=$DEST/python-novaclient
22API_DIR=$DEST/openstackx
23NOVNC_DIR=$DEST/noVNC
24
25# Use the first IP unless an explicit is set by a HOST_IP environment variable
26if [ ! -n "$HOST_IP" ]; then
27 HOST_IP=`LC_ALL=C ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
28fi
29
Jesse Andrewsbe395c12011-09-12 19:11:30 -070030# NOVA network / hypervisor configuration
Jesse Andrewsba23cc72011-09-11 03:22:13 -070031INTERFACE=${INTERFACE:-eth0}
32FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27}
33FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
34LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu}
35NET_MAN=${NET_MAN:-VlanManager}
36# NOTE(vish): If you are using FlatDHCP on multiple hosts, set the interface
37# below but make sure that the interface doesn't already have an
38# ip or you risk breaking things.
39# FLAT_INTERFACE=eth0
40
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070041# TODO: set rabbitmq conn string explicitly as well
42# TODO: switch to mysql for all services
Jesse Andrews55508d62011-09-12 19:00:28 -070043SQL_CONN=${SQL_CONN:-sqlite:///$NOVA_DIR/nova.sqlite}
Jesse Andrewsba23cc72011-09-11 03:22:13 -070044
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070045
Jesse Andrews75a37652011-09-12 17:09:08 -070046# install apt requirements
47apt-get install -y -q `cat $DIR/apts/* | cut -d\# -f1`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070048
Jesse Andrews75a37652011-09-12 17:09:08 -070049# install python requirements
50pip install `cat $DIR/pips/*`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070051
Jesse Andrews61632572011-09-12 17:40:00 -070052# git clone only if directory doesn't exist already
53function git_clone {
54 if [ ! -d $2 ]; then
55 git clone $1 $2
56 fi
57}
58
Jesse Andrews75a37652011-09-12 17:09:08 -070059# compute service
Jesse Andrews61632572011-09-12 17:40:00 -070060git_clone https://github.com/cloudbuilders/nova.git $NOVA_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070061# image catalog service
Jesse Andrews61632572011-09-12 17:40:00 -070062git_clone https://github.com/cloudbuilders/glance.git $GLANCE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070063# unified auth system (manages accounts/tokens)
Jesse Andrews61632572011-09-12 17:40:00 -070064git_clone https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070065# a websockets/html5 or flash powered VNC console for vm instances
Jesse Andrews61632572011-09-12 17:40:00 -070066git_clone https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070067# django powered web control panel for openstack
Jesse Andrews61632572011-09-12 17:40:00 -070068git_clone https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070069# python client library to nova that dashboard (and others) use
Jesse Andrews61632572011-09-12 17:40:00 -070070git_clone https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070071# openstackx is a collection of extensions to openstack.compute & nova
72# that is *deprecated*. The code is being moved into python-novaclient & nova.
Jesse Andrews61632572011-09-12 17:40:00 -070073git_clone https://github.com/cloudbuilders/openstackx.git $API_DIR
Jesse Andrewsba23cc72011-09-11 03:22:13 -070074
Jesse Andrews75a37652011-09-12 17:09:08 -070075# setup our checkouts so they are installed into python path
76# allowing `import nova` or `import glance.client`
77cd $NOVACLIENT_DIR; python setup.py develop
78cd $KEYSTONE_DIR; python setup.py develop
79cd $GLANCE_DIR; python setup.py develop
80cd $API_DIR; python setup.py develop
81cd $DASH_DIR/django-openstack; python setup.py develop
82cd $DASH_DIR/openstack-dashboard; python setup.py develop
Jesse Andrewsba23cc72011-09-11 03:22:13 -070083
Jesse Andrews75a37652011-09-12 17:09:08 -070084# attempt to load modules: kvm (hardware virt) and nbd (network block
85# device - used to manage qcow images)
86modprobe nbd || true
87modprobe kvm || true
88# if kvm wasn't running before we need to restart libvirt to enable it
89/etc/init.d/libvirt-bin restart
Jesse Andrewsba23cc72011-09-11 03:22:13 -070090
Jesse Andrewsbe395c12011-09-12 19:11:30 -070091# FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded?
92
Jesse Andrews75a37652011-09-12 17:09:08 -070093# setup nova instance directory
94mkdir -p $NOVA_DIR/instances
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070095
Jesse Andrews75a37652011-09-12 17:09:08 -070096# if there is a partition labeled nova-instances use it (ext filesystems
97# can be labeled via e2label)
98if [ -L /dev/disk/by-label/nova-instances ]; then
99 mount -L nova-instances /$NOVA_DIR/instances
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700100fi
101
Jesse Andrews75a37652011-09-12 17:09:08 -0700102# *Dashboard*: setup django application to serve via apache/wsgi
103
104# Dash currently imports quantum even if you aren't using it. Instead
105# of installing quantum we can create a simple module that will pass the
106# initial imports
107mkdir $DASH_DIR/openstack-dashboard/quantum
108touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
109touch $DASH_DIR/openstack-dashboard/quantum/client.py
110# local_settings has
111cd $DASH_DIR/openstack-dashboard
112cp local/local_settings.py.example local/local_settings.py
113dashboard/manage.py syncdb
114
115# ## Setup Apache
116# create an empty directory to use as our
117mkdir $DASH_DIR/.blackhole
118# FIXME(ja): can't figure out how to make $DASH_DIR work in sed, also install to available/a2e it
119cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /etc/apache2/sites-enabled/000-default
120
121chown -R www-data:www-data $DASH_DIR
122
123mkdir -p /var/log/glance
124
Jesse Andrews75a37652011-09-12 17:09:08 -0700125# add useful screenrc
126cp $DIR/files/screenrc ~/.screenrc
127
128# TODO: update current user to allow sudo for all commands in files/sudo/*
129
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700130NL=`echo -ne '\015'`
131
132function screen_it {
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700133 # nova api crashes if we start it with a regular screen command,
134 # so send the start command by forcing text into the window.
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700135 screen -S nova -X screen -t $1
136 screen -S nova -p $1 -X stuff "$2$NL"
137}
138
139function add_nova_flag {
140 echo "$1" >> $NOVA_DIR/bin/nova.conf
141}
142
Jesse Andrews75a37652011-09-12 17:09:08 -0700143# (re)create nova.conf
144rm -f $NOVA_DIR/bin/nova.conf
145add_nova_flag "--verbose"
146add_nova_flag "--nodaemon"
147add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
148add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
149add_nova_flag "--my_ip=$HOST_IP"
150add_nova_flag "--public_interface=$INTERFACE"
151add_nova_flag "--vlan_interface=$INTERFACE"
152add_nova_flag "--sql_connection=$SQL_CONN"
153add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
154add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
155add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
156add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/noVNC/noVNC"
157add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
158add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
159if [ -n "$FLAT_INTERFACE" ]; then
160 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700161fi
162
Jesse Andrews75a37652011-09-12 17:09:08 -0700163# create a new named screen to store things in
164screen -d -m -S nova -t nova
165sleep 1
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700166
Jesse Andrews75a37652011-09-12 17:09:08 -0700167# Clean out the instances directory
168rm -rf $NOVA_DIR/instances/*
169
170# delete traces of nova networks from prior runs
171killall dnsmasq || true
172rm -rf $NOVA_DIR/networks
173mkdir -p $NOVA_DIR/networks
174
175# (re)create nova database
176rm -f $NOVA_DIR/nova.sqlite
177$NOVA_DIR/bin/nova-manage db sync
178
179# initialize keystone with default users/endpoints
Jesse Andrews75a37652011-09-12 17:09:08 -0700180rm -f /opt/keystone/keystone.db
Jesse Andrews73e27b82011-09-12 17:55:00 -0700181BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
Jesse Andrews75a37652011-09-12 17:09:08 -0700182
183# create a small network
184$NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
185
186# create some floating ips
187$NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
188
189# delete existing glance images/database. Glance will recreate the db
190# when it is ran.
191rm -rf /var/lib/glance/images/*
192rm -f $GLANCE_DIR/glance.sqlite
193
Jesse Andrews75a37652011-09-12 17:09:08 -0700194screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
195screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
Jesse Andrews75a37652011-09-12 17:09:08 -0700196screen_it key "$KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf"
Jesse Andrews55508d62011-09-12 19:00:28 -0700197screen_it n-api "$NOVA_DIR/bin/nova-api"
198screen_it n-cpu "$NOVA_DIR/bin/nova-compute"
199screen_it n-net "$NOVA_DIR/bin/nova-network"
200screen_it n-sch "$NOVA_DIR/bin/nova-scheduler"
201screen_it n-vnc "$NOVA_DIR/bin/nova-vncproxy"
Jesse Andrews75a37652011-09-12 17:09:08 -0700202screen_it dash "/etc/init.d/apache2 restart; tail -f /var/log/apache2/error.log"
203
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700204
205
206# ---- download an install images ----
207
208mkdir -p $DEST/images
209cd $DEST/images
210# prepare initial images for loading into glance
211if [ ! -f $DEST/tty.tgz ]; then
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700212 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700213fi
214
215# extract ami-tty/image, aki-tty/image & ari-tty/image
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700216tar -zxf $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700217
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700218# add images to glance
219# FIXME: kernel/ramdisk is hardcoded - use return result from add
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700220glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image
221glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image
222glance add name="tty" is_public=true container_format=ami disk_format=ami kernel_id=1 ramdisk_id=2 < ami-tty/image
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700223