~0x44/nova/bug838466

386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
1
#!/usr/bin/env bash
2
DIR=`pwd`
3
CMD=$1
583.4.5 by Vishvananda Ishaya
wrap sqlalchemy exceptions in a generic error
4
if [ "$CMD" = "branch" ]; then
5
    SOURCE_BRANCH=${2:-lp:nova}
6
    DIRNAME=${3:-nova}
7
else
8
    DIRNAME=${2:-nova}
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
9
fi
583.4.5 by Vishvananda Ishaya
wrap sqlalchemy exceptions in a generic error
10
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
11
NOVA_DIR=$DIR/$DIRNAME
12
13
if [ ! -n "$HOST_IP" ]; then
14
    # NOTE(vish): This will just get the first ip in the list, so if you
15
    #             have more than one eth device set up, this will fail, and
16
    #             you should explicitly set HOST_IP in your environment
205.2.35 by Anthony Young
add ajax console proxy to nova.sh
17
    HOST_IP=`LC_ALL=C ifconfig  | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
18
fi
403.5.7 by Vishvananda Ishaya
merged trunk, added recent nova.sh
19
403.5.1 by Vishvananda Ishaya
fixes flatdhcp, updates nova.sh, allows for empty bridge device
20
USE_MYSQL=${USE_MYSQL:-0}
21
MYSQL_PASS=${MYSQL_PASS:-nova}
22
TEST=${TEST:-0}
403.5.7 by Vishvananda Ishaya
merged trunk, added recent nova.sh
23
USE_LDAP=${USE_LDAP:-0}
382.5.3 by Ryan Lane
Added a script to use OpenDJ as an LDAP server instead of OpenLDAP. Also modified nova.sh to add an USE_OPENDJ option, that will be checked when USE_LDAP is set.
24
# Use OpenDJ instead of OpenLDAP when using LDAP
25
USE_OPENDJ=${USE_OPENDJ:-0}
583.4.1 by Vishvananda Ishaya
add helpful error messages to nova-manage and update nova.sh
26
# Use IPv6
27
USE_IPV6=${USE_IPV6:-0}
403.5.1 by Vishvananda Ishaya
fixes flatdhcp, updates nova.sh, allows for empty bridge device
28
LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu}
425.1.1 by Vishvananda Ishaya
update of nova.sh because default flagfile moved
29
NET_MAN=${NET_MAN:-VlanManager}
403.5.7 by Vishvananda Ishaya
merged trunk, added recent nova.sh
30
# NOTE(vish): If you are using FlatDHCP on multiple hosts, set the interface
31
#             below but make sure that the interface doesn't already have an
32
#             ip or you risk breaking things.
33
# FLAT_INTERFACE=eth0
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
34
35
if [ "$USE_MYSQL" == 1 ]; then
36
    SQL_CONN=mysql://root:$MYSQL_PASS@localhost/nova
37
else
38
    SQL_CONN=sqlite:///$NOVA_DIR/nova.sqlite
39
fi
40
41
if [ "$USE_LDAP" == 1 ]; then
42
    AUTH=ldapdriver.LdapDriver
43
else
44
    AUTH=dbdriver.DbDriver
45
fi
46
47
if [ "$CMD" == "branch" ]; then
48
    sudo apt-get install -y bzr
583.4.5 by Vishvananda Ishaya
wrap sqlalchemy exceptions in a generic error
49
    if [ ! -e "$DIR/.bzr" ]; then
50
        bzr init-repo $DIR
51
    fi
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
52
    rm -rf $NOVA_DIR
53
    bzr branch $SOURCE_BRANCH $NOVA_DIR
54
    cd $NOVA_DIR
55
    mkdir -p $NOVA_DIR/instances
56
    mkdir -p $NOVA_DIR/networks
583.4.5 by Vishvananda Ishaya
wrap sqlalchemy exceptions in a generic error
57
    exit
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
58
fi
59
60
# You should only have to run this once
61
if [ "$CMD" == "install" ]; then
62
    sudo apt-get install -y python-software-properties
435.3.1 by Vishvananda Ishaya
fix nova.sh to reflect new location of ppa
63
    sudo add-apt-repository ppa:nova-core/trunk
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
64
    sudo apt-get update
583.4.1 by Vishvananda Ishaya
add helpful error messages to nova-manage and update nova.sh
65
    sudo apt-get install -y dnsmasq-base kpartx kvm gawk iptables ebtables
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
66
    sudo apt-get install -y user-mode-linux kvm libvirt-bin
403.5.4 by Vishvananda Ishaya
updated nova.sh
67
    sudo apt-get install -y screen euca2ools vlan curl rabbitmq-server
68
    sudo apt-get install -y lvm2 iscsitarget open-iscsi
205.2.36 by Anthony Young
apt-get install socat, which is used to connect to the console
69
    sudo apt-get install -y socat
403.5.1 by Vishvananda Ishaya
fixes flatdhcp, updates nova.sh, allows for empty bridge device
70
    echo "ISCSITARGET_ENABLE=true" | sudo tee /etc/default/iscsitarget
71
    sudo /etc/init.d/iscsitarget restart
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
72
    sudo modprobe kvm
73
    sudo /etc/init.d/libvirt-bin restart
515.9.2 by Vishvananda Ishaya
fix injection and xml
74
    sudo modprobe nbd
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
75
    sudo apt-get install -y python-twisted python-sqlalchemy python-mox python-greenlet python-carrot
583.4.5 by Vishvananda Ishaya
wrap sqlalchemy exceptions in a generic error
76
    sudo apt-get install -y python-migrate python-eventlet python-gflags python-ipy python-tempita
515.9.2 by Vishvananda Ishaya
fix injection and xml
77
    sudo apt-get install -y python-libvirt python-libxml2 python-routes python-cheetah
583.4.1 by Vishvananda Ishaya
add helpful error messages to nova-manage and update nova.sh
78
    sudo apt-get install -y python-netaddr python-paste python-pastedeploy python-glance
79
583.4.4 by Vishvananda Ishaya
fix ipv6 conditional
80
    if [ "$USE_IPV6" == 1 ]; then
583.4.1 by Vishvananda Ishaya
add helpful error messages to nova-manage and update nova.sh
81
        sudo apt-get install -y radvd
82
        sudo bash -c "echo 1 > /proc/sys/net/ipv6/conf/all/forwarding"
83
        sudo bash -c "echo 0 > /proc/sys/net/ipv6/conf/all/accept_ra"
84
    fi
85
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
86
    if [ "$USE_MYSQL" == 1 ]; then
87
        cat <<MYSQL_PRESEED | debconf-set-selections
88
mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS
89
mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS
90
mysql-server-5.1 mysql-server/start_on_boot boolean true
91
MYSQL_PRESEED
92
        apt-get install -y mysql-server python-mysqldb
93
    fi
583.4.5 by Vishvananda Ishaya
wrap sqlalchemy exceptions in a generic error
94
    mkdir -p $DIR/images
95
    wget -c http://images.ansolabs.com/tty.tgz
96
    tar -C $DIR/images -zxf tty.tgz
97
    exit
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
98
fi
99
100
NL=`echo -ne '\015'`
101
102
function screen_it {
103
    screen -S nova -X screen -t $1
104
    screen -S nova -p $1 -X stuff "$2$NL"
105
}
106
107
if [ "$CMD" == "run" ]; then
583.4.5 by Vishvananda Ishaya
wrap sqlalchemy exceptions in a generic error
108
109
  cat >$NOVA_DIR/bin/nova.conf << NOVA_CONF_EOF
110
--verbose
111
--nodaemon
112
--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf
113
--network_manager=nova.network.manager.$NET_MAN
114
--cc_host=$HOST_IP
115
--routing_source_ip=$HOST_IP
116
--sql_connection=$SQL_CONN
117
--auth_driver=nova.auth.$AUTH
118
--libvirt_type=$LIBVIRT_TYPE
119
NOVA_CONF_EOF
120
121
    if [ -n "$FLAT_INTERFACE" ]; then
122
        echo "--flat_interface=$FLAT_INTERFACE" >>$NOVA_DIR/bin/nova.conf
123
    fi
124
125
    if [ "$USE_IPV6" == 1 ]; then
126
        echo "--use_ipv6" >>$NOVA_DIR/bin/nova.conf
127
    fi
128
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
129
    killall dnsmasq
583.4.4 by Vishvananda Ishaya
fix ipv6 conditional
130
    if [ "$USE_IPV6" == 1 ]; then
583.4.1 by Vishvananda Ishaya
add helpful error messages to nova-manage and update nova.sh
131
       killall radvd
132
    fi
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
133
    screen -d -m -S nova -t nova
134
    sleep 1
135
    if [ "$USE_MYSQL" == 1 ]; then
136
        mysql -p$MYSQL_PASS -e 'DROP DATABASE nova;'
137
        mysql -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
138
    else
139
        rm $NOVA_DIR/nova.sqlite
140
    fi
141
    if [ "$USE_LDAP" == 1 ]; then
382.5.3 by Ryan Lane
Added a script to use OpenDJ as an LDAP server instead of OpenLDAP. Also modified nova.sh to add an USE_OPENDJ option, that will be checked when USE_LDAP is set.
142
        if [ "$USE_OPENDJ" == 1 ]; then
143
            echo '--ldap_user_dn=cn=Directory Manager' >> \
144
                /etc/nova/nova-manage.conf
145
            sudo $NOVA_DIR/nova/auth/opendj.sh
146
        else
147
            sudo $NOVA_DIR/nova/auth/slap.sh
148
        fi
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
149
    fi
150
    rm -rf $NOVA_DIR/instances
151
    mkdir -p $NOVA_DIR/instances
152
    rm -rf $NOVA_DIR/networks
153
    mkdir -p $NOVA_DIR/networks
154
    $NOVA_DIR/tools/clean-vlans
155
    if [ ! -d "$NOVA_DIR/images" ]; then
156
        ln -s $DIR/images $NOVA_DIR/images
157
    fi
158
159
    if [ "$TEST" == 1 ]; then
160
        cd $NOVA_DIR
161
        python $NOVA_DIR/run_tests.py
162
        cd $DIR
163
    fi
164
583.4.1 by Vishvananda Ishaya
add helpful error messages to nova-manage and update nova.sh
165
    # create the database
166
    $NOVA_DIR/bin/nova-manage db sync
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
167
    # create an admin user called 'admin'
168
    $NOVA_DIR/bin/nova-manage user admin admin admin admin
169
    # create a project called 'admin' with project manager of 'admin'
170
    $NOVA_DIR/bin/nova-manage project create admin admin
171
    # export environment variables for project 'admin' and user 'admin'
172
    $NOVA_DIR/bin/nova-manage project environment admin admin $NOVA_DIR/novarc
403.5.1 by Vishvananda Ishaya
fixes flatdhcp, updates nova.sh, allows for empty bridge device
173
    # create a small network
174
    $NOVA_DIR/bin/nova-manage network create 10.0.0.0/8 1 32
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
175
176
    # nova api crashes if we start it with a regular screen command,
177
    # so send the start command by forcing text into the window.
425.1.1 by Vishvananda Ishaya
update of nova.sh because default flagfile moved
178
    screen_it api "$NOVA_DIR/bin/nova-api"
179
    screen_it objectstore "$NOVA_DIR/bin/nova-objectstore"
180
    screen_it compute "$NOVA_DIR/bin/nova-compute"
181
    screen_it network "$NOVA_DIR/bin/nova-network"
182
    screen_it scheduler "$NOVA_DIR/bin/nova-scheduler"
183
    screen_it volume "$NOVA_DIR/bin/nova-volume"
205.2.35 by Anthony Young
add ajax console proxy to nova.sh
184
    screen_it ajax_console_proxy "$NOVA_DIR/bin/nova-ajax-console-proxy"
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
185
    screen_it test ". $NOVA_DIR/novarc"
403.5.1 by Vishvananda Ishaya
fixes flatdhcp, updates nova.sh, allows for empty bridge device
186
    screen -S nova -x
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
187
fi
188
189
if [ "$CMD" == "run" ] || [ "$CMD" == "terminate" ]; then
190
    # shutdown instances
191
    . $NOVA_DIR/novarc; euca-describe-instances | grep i- | cut -f2 | xargs euca-terminate-instances
192
    sleep 2
403.5.4 by Vishvananda Ishaya
updated nova.sh
193
    # delete volumes
194
    . $NOVA_DIR/novarc; euca-describe-volumes | grep vol- | cut -f2 | xargs -n1 euca-delete-volume
583.4.1 by Vishvananda Ishaya
add helpful error messages to nova-manage and update nova.sh
195
    sleep 2
386.2.26 by Todd Willey
Nova quickstart: move vish's novascript into contrib, and convert reademe.md to a quickstart.rst
196
fi
197
198
if [ "$CMD" == "run" ] || [ "$CMD" == "clean" ]; then
199
    screen -S nova -X quit
200
    rm *.pid*
201
fi
202
203
if [ "$CMD" == "scrub" ]; then
204
    $NOVA_DIR/tools/clean-vlans
205
    if [ "$LIBVIRT_TYPE" == "uml" ]; then
206
        virsh -c uml:///system list | grep i- | awk '{print \$1}' | xargs -n1 virsh -c uml:///system destroy
207
    else
208
        virsh list | grep i- | awk '{print \$1}' | xargs -n1 virsh destroy
209
    fi
210
fi