PageRenderTime 66ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 0ms

/nova.sh

https://github.com/sriprasanna/swift-scripts
Shell | 236 lines | 181 code | 35 blank | 20 comment | 32 complexity | 4fa548aa5a53b341ff6fa2974a2460d9 MD5 | raw file
  1. #!/usr/bin/env bash
  2. DIR=`pwd`
  3. CMD=$1
  4. SOURCE_BRANCH=lp:nova
  5. if [ -n "$2" ]; then
  6. SOURCE_BRANCH=$2
  7. fi
  8. DIRNAME=nova
  9. NOVA_DIR=$DIR/$DIRNAME
  10. if [ -n "$3" ]; then
  11. NOVA_DIR=$DIR/$3
  12. fi
  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
  17. HOST_IP=`ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
  18. fi
  19. TEST=0
  20. USE_MYSQL=1
  21. MYSQL_PASS=nova
  22. USE_LDAP=0
  23. LIBVIRT_TYPE=qemu
  24. if [ "$USE_MYSQL" == 1 ]; then
  25. SQL_CONN=mysql://root:$MYSQL_PASS@localhost/nova
  26. else
  27. SQL_CONN=sqlite:///$NOVA_DIR/nova.sqlite
  28. fi
  29. if [ "$USE_LDAP" == 1 ]; then
  30. AUTH=ldapdriver.LdapDriver
  31. else
  32. AUTH=dbdriver.DbDriver
  33. fi
  34. mkdir -p /etc/nova
  35. cat >/etc/nova/nova-manage.conf << NOVA_CONF_EOF
  36. --verbose
  37. --nodaemon
  38. --dhcpbridge_flagfile=/etc/nova/nova-manage.conf
  39. --FAKE_subdomain=ec2
  40. --cc_host=$HOST_IP
  41. --routing_source_ip=$HOST_IP
  42. --sql_connection=$SQL_CONN
  43. --auth_driver=nova.auth.$AUTH
  44. --libvirt_type=$LIBVIRT_TYPE
  45. NOVA_CONF_EOF
  46. if [ "$CMD" == "branch" ]; then
  47. sudo yum -y install bzr
  48. rm -rf $NOVA_DIR
  49. bzr branch $SOURCE_BRANCH $NOVA_DIR
  50. cd $NOVA_DIR
  51. mkdir -p $NOVA_DIR/instances
  52. mkdir -p $NOVA_DIR/networks
  53. # just to ensure python 2.6 is used to run the nova services
  54. sed -i "s_/usr/bin/env python_/usr/bin/env python2.6_" $NOVA_DIR/bin/*
  55. fi
  56. # You should only have to run this once
  57. if [ "$CMD" == "install" ]; then
  58. #sudo su -
  59. cat >/etc/yum.repos.d/aoe2ools.repo << EUCA_REPO_CONF_EOF
  60. [eucalyptus]
  61. name=aoe2ools
  62. baseurl=http://www.eucalyptussoftware.com/downloads/repo/euca2ools/1.3.1/yum/centos/
  63. enabled=1
  64. gpgcheck=0
  65. EUCA_REPO_CONF_EOF
  66. #rpm -Uvh 'http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm'
  67. yum -y install dnsmasq vblade kpartx kvm gawk iptables ebtables bzr screen euca2ools curl rabbitmq-server gcc gcc-c++ autoconf automake swig openldap openldap-servers nginx python26 python26-devel python26-distribute git openssl-devel python26-tools mysql-server qemu kmod-kvm libxml2 libxslt libxslt-devel mysql-devel gnutls gnutls-devel
  68. wget -c http://sourceforge.net/projects/aoetools/files/aoetools/32/aoetools-32.tar.gz/download
  69. tar -zxvf aoetools-32.tar.gz
  70. cd aoetools-32
  71. make
  72. make install
  73. cd ..
  74. rm -rfv aoetools*
  75. cat > /etc/udev/rules.d/60-aoe.rules << AOE_RULES_EOF
  76. SUBSYSTEM=="aoe", KERNEL=="discover", NAME="etherd/%k", GROUP="disk", MODE="0220"
  77. SUBSYSTEM=="aoe", KERNEL=="err", NAME="etherd/%k", GROUP="disk", MODE="0440"
  78. SUBSYSTEM=="aoe", KERNEL=="interfaces", NAME="etherd/%k", GROUP="disk", MODE="0220"
  79. SUBSYSTEM=="aoe", KERNEL=="revalidate", NAME="etherd/%k", GROUP="disk", MODE="0220"
  80. # aoe block devices
  81. KERNEL=="etherd*", NAME="%k", GROUP="disk"
  82. AOE_RULES_EOF
  83. modprobe aoe
  84. modprobe kvm
  85. easy_install-2.6 twisted sqlalchemy mox greenlet carrot python-daemon eventlet tornado IPy routes lxml MySQL-python webob boto lockfile==0.8
  86. wget -c "http://python-gflags.googlecode.com/files/python-gflags-1.4.tar.gz"
  87. tar -zxvf python-gflags-1.4.tar.gz
  88. cd python-gflags-1.4
  89. python2.6 setup.py install
  90. cd ..
  91. rm -rfv python-gflags-*
  92. wget -c "ftp://xmlsoft.org/libxml2/libxml2-2.7.3.tar.gz"
  93. tar -zxvf libxml2-2.7.3.tar.gz
  94. cd libxml2-2.7.3
  95. ./configure --with-python=/usr/bin/python26 --prefix=/usr
  96. make all
  97. make install
  98. cd python
  99. python2.6 setup.py install
  100. cd ..
  101. rm -rfv libxml2-2.7*
  102. service mysqld start
  103. cat > nova.sql << NOVA_SQL
  104. create user 'nova'@'localhost' identified by 'nova';
  105. create user 'nova'@'%' identified by 'nova';
  106. grant all privileges on *.* to 'nova'@'localhost' with grant option;
  107. grant all privileges on *.* to 'nova'@'%' with grant option;
  108. create database nova;
  109. NOVA_SQL
  110. mysql < nova.sql
  111. #as per yum, kvm conflicts with libvirt , hence we were not able to install libvirt through yum
  112. # we had to build it any way, as we need to install the libvirt-python bindings for python2.6
  113. wget -c ftp://libvirt.org/libvirt/libvirt-0.8.5.tar.gz
  114. tar -zxvf libvirt-0.8.5.tar.gz
  115. cd libvirt-0.8.5
  116. ./configure --prefix=/usr --with-python=/usr/bin/python2.6
  117. make
  118. make install
  119. cd ..
  120. rm -rfv libvirt*
  121. wget -c http://pypi.python.org/packages/source/M/M2Crypto/M2Crypto-0.20.2.tar.gz
  122. # CentOS specific openssl fix to compile the swig files, cant fugure out how to speficy the openssl include
  123. # headers in swig.
  124. sed -i 's_opensslconf-\(.*\)_/usr/include/openssl/opensslconf-\1_' /usr/include/openssl/opensslconf.h
  125. tar -zxvf M2Crypto-0.20.2.tar.gz
  126. cd M2Crypto-0.20.2
  127. python2.6 setup.py install
  128. cd ..
  129. rm -rfv M2Crypto*
  130. wget http://c2477062.cdn.cloudfiles.rackspacecloud.com/images.tgz
  131. tar -C $DIR -zxf images.tgz
  132. fi
  133. NL=`echo -ne '\015'`
  134. function screen_it {
  135. screen -S nova -X screen -t $1
  136. screen -S nova -p $1 -X stuff "$2$NL"
  137. }
  138. if [ "$CMD" == "run" ]; then
  139. killall dnsmasq
  140. screen -d -m -S nova -t nova
  141. sleep 1
  142. if [ "$USE_MYSQL" == 1 ]; then
  143. mysql -p$MYSQL_PASS -e 'DROP DATABASE nova;'
  144. mysql -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
  145. else
  146. rm $NOVA_DIR/nova.sqlite
  147. fi
  148. if [ "$USE_LDAP" == 1 ]; then
  149. sudo $NOVA_DIR/nova/auth/slap.sh
  150. fi
  151. rm -rf $NOVA_DIR/instances
  152. mkdir -p $NOVA_DIR/instances
  153. rm -rf $NOVA_DIR/networks
  154. mkdir -p $NOVA_DIR/networks
  155. $NOVA_DIR/tools/clean-vlans
  156. if [ ! -d "$NOVA_DIR/images" ]; then
  157. ln -s $DIR/images $NOVA_DIR/images
  158. fi
  159. if [ "$TEST" == 1 ]; then
  160. cd $NOVA_DIR
  161. python $NOVA_DIR/run_tests.py
  162. cd $DIR
  163. fi
  164. # create an admin user called 'admin'
  165. $NOVA_DIR/bin/nova-manage user admin admin admin admin
  166. # create a project called 'admin' with project manager of 'admin'
  167. $NOVA_DIR/bin/nova-manage project create admin admin
  168. # export environment variables for project 'admin' and user 'admin'
  169. $NOVA_DIR/bin/nova-manage project environment admin admin $NOVA_DIR/novarc
  170. # create 3 small networks
  171. $NOVA_DIR/bin/nova-manage network create 10.0.0.0/8 3 16
  172. # nova api crashes if we start it with a regular screen command,
  173. # so send the start command by forcing text into the window.
  174. screen_it api "$NOVA_DIR/bin/nova-api --flagfile=/etc/nova/nova-manage.conf"
  175. screen_it objectstore "$NOVA_DIR/bin/nova-objectstore --flagfile=/etc/nova/nova-manage.conf"
  176. screen_it compute "$NOVA_DIR/bin/nova-compute --flagfile=/etc/nova/nova-manage.conf"
  177. screen_it network "$NOVA_DIR/bin/nova-network --flagfile=/etc/nova/nova-manage.conf"
  178. screen_it scheduler "$NOVA_DIR/bin/nova-scheduler --flagfile=/etc/nova/nova-manage.conf"
  179. screen_it volume "$NOVA_DIR/bin/nova-volume --flagfile=/etc/nova/nova-manage.conf"
  180. screen_it test ". $NOVA_DIR/novarc"
  181. screen -x
  182. fi
  183. if [ "$CMD" == "run" ] || [ "$CMD" == "terminate" ]; then
  184. # shutdown instances
  185. . $NOVA_DIR/novarc; euca-describe-instances | grep i- | cut -f2 | xargs euca-terminate-instances
  186. sleep 2
  187. fi
  188. if [ "$CMD" == "run" ] || [ "$CMD" == "clean" ]; then
  189. screen -S nova -X quit
  190. rm *.pid*
  191. $NOVA_DIR/tools/setup_iptables.sh clear
  192. fi
  193. if [ "$CMD" == "scrub" ]; then
  194. $NOVA_DIR/tools/clean-vlans
  195. if [ "$LIBVIRT_TYPE" == "uml" ]; then
  196. virsh -c uml:///system list | grep i- | awk '{print \$1}' | xargs -n1 virsh -c uml:///system destroy
  197. else
  198. virsh list | grep i- | awk '{print \$1}' | xargs -n1 virsh destroy
  199. fi
  200. vblade-persist ls | grep vol- | awk '{print \$1\" \"\$2}' | xargs -n2 vblade-persist destroy
  201. fi