f8a15e6c34ac690bf69aa70f53cc6ff1d384f962
[integration/packaging.git] / docker / openstack / compute / start.sh
1 #!/bin/sh
2 # On docker run, Env Variables "STACK_PASS & SERV_HOST" should be set using -e
3 #  example 'docker run -e "STACK_PASS=stack" -e "SERV_HOST=192.168.0.5" compute'
4 # or overided below by uncommenting:
5 #STACK_PASS="stack"
6 # SERV_HOST="192.168.0.5"
7 # ODL_NETWORK should be set in the 'docker run' script
8 set -o nounset # throw an error if a variable is unset to prevent unexpected behaviors
9 ODL_NETWORK=${ODL_NETWORK}
10 DEVSTACK_HOME="/home/stack/devstack"
11 CONF_PATH=$DEVSTACK_HOME/local.conf
12 BRANCH_NAME=stable/newton
13 TAG_NAME="origin/${BRANCH_NAME}"
14
15 #Set Nameserver to google
16 echo nameserver 8.8.8.8 | sudo tee -a /etc/resolv.conf
17
18 # change the stack user password
19 echo "stack:$STACK_PASS" | sudo chpasswd
20
21 # get container IP
22 ip=`/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1`
23
24 # Start SSH Service
25 # Centos7: sudo: service: command not found
26 #sudo service ssh start
27
28 # Start openvswitch
29 # Centos7: sudo: service: command not found
30 #sudo service openvswitch-switch start
31
32 # set the correct branch in devstack
33 cd $DEVSTACK_HOME
34 git fetch
35 git checkout -b ${BRANCH_NAME} -t ${TAG_NAME}
36
37 # copy local.conf into devstack and customize, based on environment including:
38 # ODL_NETWORK, ip, DEVSTACK_HOME, SERV_HOST
39 cp /home/stack/local.conf $CONF_PATH
40
41 # Configure local.conf
42 # update the ip of this host & SERVICE_HOST
43 sed -i "s/HOST_IP=.*/HOST_IP=${ip}/" $CONF_PATH
44 sed -i "s/SERVICE_HOST=.*/SERVICE_HOST=$SERV_HOST/" $CONF_PATH
45 # modify the local.conf according to ODL_NETWORK value
46 echo "Preparing $CONF_PATH for ODL=$ODL_NETWORK"
47 echo
48 if [ "$ODL_NETWORK" = "false" ] ; then
49     # prepare local.conf to NOT use ODL networking (default to Neutron)
50     sed -i "s:^\(enable_plugin networking-odl\):#\1:g" $CONF_PATH
51     sed -i "s:^\(ODL_MODE=compute\):#\1:g" $CONF_PATH
52     sed -i "s:^\(ENABLED_SERVICES=\).*:\1n-cpu,q-agt:g" $CONF_PATH
53 else
54     # prepare local.conf to use ODL networking
55     sed -i "s:^#\(enable_plugin networking-odl\):\1:g" $CONF_PATH
56     sed -i "s:^#\(ODL_MODE=compute\):\1:g" $CONF_PATH
57     sed -i "s:^\(ENABLED_SERVICES=\).*:\1n-cpu:g" $CONF_PATH
58 fi
59
60 $DEVSTACK_HOME/stack.sh
61