New devstack scripts added

This commit is contained in:
Dmitry Teselkin 2013-03-19 17:45:41 +04:00
parent 7f5f8bcc9f
commit 998b210043
10 changed files with 388 additions and 0 deletions

View File

@ -0,0 +1,27 @@
lab_id=101
lab_password=swordfish
HOST_IP=172.18.124.${lab_id}
#PUBLIC_INTERFACE=eth1
FIXED_RANGE=10.0.${lab_id}.0/24
NETWORK_GATEWAY=10.0.${lab_id}.1
#PUBLIC_INTERFACE=eth0
FLAT_INTERFACE=eth1
ADMIN_PASSWORD=$lab_password
MYSQL_PASSWORD=$lab_password
RABBIT_PASSWORD=$lab_password
SERVICE_PASSWORD=$lab_password
SERVICE_TOKEN=tokentoken
ENABLED_SERVICES+=,heat,h-api,h-api-cfn,h-api-cw,h-eng
LOGFILE=/opt/stack/devstack/stack.sh.log
SCREEN_LOGDIR=/opt/stack/log/
#SCREEN_LOGDIR=/dev/null
API_RATE_LIMIT=False
EXTRA_OPTS=(force_config_drive=true libvirt_images_type=qcow2 force_raw_images=false)

View File

@ -0,0 +1,75 @@
#!/bin/bash
# Test if the named environment variable is set and not zero length
# is_set env-var
#function is_set() {
# local var=\$"$1"
# eval "[ -n \"$var\" ]" # For ex.: sh -c "[ -n \"$var\" ]" would be better, but several exercises depends on this
#}
# Prints "message" and exits
# die "message"
#function die() {
# local exitcode=$?
# if [ $exitcode == 0 ]; then
# exitcode=1
# fi
# set +o xtrace
# local msg="[ERROR] $0:$1 $2"
# echo $msg 1>&2;
# if [[ -n ${SCREEN_LOGDIR} ]]; then
# echo $msg >> "${SCREEN_LOGDIR}/error.log"
# fi
# exit $exitcode
#}
# Checks an environment variable is not set or has length 0 OR if the
# exit code is non-zero and prints "message" and exits
# NOTE: env-var is the variable name without a '$'
# die_if_not_set env-var "message"
function die_if_not_set() {
local exitcode=$?
set +o xtrace
local evar=$1; shift
if ! is_set $evar || [ $exitcode != 0 ]; then
if [[ -z "$1" ]] ; then
die "Env var '$evar' is not set!"
else
die $@
fi
fi
}
function restart_service {
while [[ -n "$1" ]] ; do
echo "Restarting service '$1' ..."
sudo service $1 restart
shift 1
done
}
# Normalize config values to True or False
# Accepts as False: 0 no false False FALSE
# Accepts as True: 1 yes true True TRUE
# VAR=$(trueorfalse default-value test-value)
#function trueorfalse() {
# local default=$1
# local testval=$2
#
# [[ -z "$testval" ]] && { echo "$default"; return; }
# [[ "0 no false False FALSE" =~ "$testval" ]] && { echo "False"; return; }
# [[ "1 yes true True TRUE" =~ "$testval" ]] && { echo "True"; return; }
# echo "$default"
#}

View File

@ -0,0 +1,15 @@
#!/bin/bash
DEVSTACK_DIR=/home/stack/devstack
MYSQL_DB_TMPFS=true
MYSQL_DB_TMPFS_SIZE=128M
NOVA_CACHE_TMPFS=true
NOVA_CACHE_TMPFS_SIZE=24G
#======================================
source $DEVSTACK_DIR/openrc admin admin
source ./functions.sh

View File

@ -0,0 +1,72 @@
#!/bin/bash
if [ -z "$1" ] ; then
source ./localrc
fi
function glance_image_create {
local __image_name=$1
if [[ -z "$__image_name" ]] ; then
echo "No image name provided!"
return
fi
echo "Importing image '$__image_name' into Glance..."
glance image-delete "$__image_name"
glance image-create \
--name "$__image_name" \
--disk-format qcow2 \
--container-format bare \
--is-public true \
--copy-from "http://172.18.124.100:8888/$__image_name.qcow2"
}
# Executing post-stack actions
#===============================================================================
if [ -z "$(sudo rabbitmqctl list_users | grep keero)" ] ; then
echo "Adding RabbitMQ 'keero' user"
sudo rabbitmqctl add_user keero keero
else
echo "User 'Keero' already exists."
fi
if [ -z "$(sudo rabbitmq-plugins list -e | grep rabbitmq_management)" ] ; then
echo "Enabling RabbitMQ management plugin"
sudo rabbitmq-plugins enable rabbitmq_management
else
echo "RabbitMQ management plugin already enabled."
fi
echo "Restarting RabbitMQ ..."
restart_service rabbitmq-server
echo "* Removing nova flavors ..."
for id in $(nova flavor-list | awk '$2 ~ /[[:digit:]]/ {print $2}') ; do
echo "** Removing flavor '$id'"
nova flavor-delete $id
done
echo "* Creating new flavors ..."
nova flavor-create m1.small auto 1024 40 1
nova flavor-create m1.medium auto 2048 40 2
nova flavor-create m1.large auto 4096 40 4
if [ -z "$(nova keypair-list | grep keero_key)" ] ; then
echo "Creating keypair 'keero_key' ..."
nova keypair-add keero_key
else
echo "Keypair 'keero_key' already exists"
fi
#===============================================================================
glance_image_create "ws-2012-full"

View File

@ -0,0 +1,25 @@
#!/bin/bash
if [[ -z "$1" ]] ; then
source ./localrc
fi
#Remove certificates
echo "* Removing old certificate files"
for file in $(sudo find $DEVSTACK_DIR/accrc/ -type f -regex ".+.pem.*") ; do
echo "Removing file '$file'"
sudo rm -f "$file"
done
# Remove logs
echo Removing 'devstack' logs
sudo rm -f /var/log/devstack/*
#sudo rm -f /opt/stack/devstack/stack.sh.log
echo "* Removing 'apache2' logs"
for file in $(sudo find /var/log/apache2 -type f) ; do
echo "Removing file '$file'"
sudo rm -f "$file"
done

View File

@ -0,0 +1,99 @@
#!/bin/bash
if [ -z "$1" ] ; then
source ./localrc
fi
# Executing pre-stack actions
#===============================================================================
# Executing checks
#-----------------
die_if_not_set DEVSTACK_DIR
die_if_not_set MYSQL_DB_TMPFS_SIZE
die_if_not_set NOVA_CACHE_TMPFS_SIZE
#-----------------
restart_service dbus rabbitmq-server
# Moving MySQL database to tmpfs
#-------------------------------
if [[ $(trueorfalse True $MYSQL_DB_TMPFS) = "True" ]] ; then
die_if_not_set MYSQL_DB_TMPFS_SIZE
mount_dir=/var/lib/mysql
sudo -s << EOF
echo "Stopping MySQL Server"
service mysql stop
umount $mount_dir
mount -t tmpfs -o size=$MYSQL_DB_TMPFS_SIZE tmpfs $mount_dir
chmod 700 $mount_dir
chown mysql:mysql $mount_dir
mysql_install_db
/usr/bin/mysqld_safe --skip-grant-tables &
sleep 5
EOF
sudo mysql << EOF
FLUSH PRIVILEGES;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('swordfish');
SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('swordfish');
EOF
sudo -s << EOF
killall mysqld
sleep 5
echo "Starting MySQL Server"
service mysql start
EOF
else
echo "MYSQL_DB_TMPFS = '$MYSQL_DB_TMPFS'"
fi
#-------------------------------
# Devstack log folder
#--------------------
sudo -s << EOF
mkdir -p $SCREEN_LOGDIR
chown stack:stack $SCREEN_LOGDIR
EOF
#--------------------
# Moving nova images cache to tmpfs
#----------------------------------
if [[ $(trueorfalse True $NOVA_CACHE_TMPFS) = "True" ]] ; then
die_if_not_set NOVA_CACHE_TMPFS_SIZE
mount_dir=/opt/stack/data/nova/instances
sudo -s << EOF
umount $mount_dir
mount -t tmpfs -o size=$NOVA_CACHE_TMPFS_SIZE tmpfs $mount_dir
chmod 775 $mount_dir
chown stack:stack $mount_dir
EOF
else
echo "NOVA_CACHE_TMPFS = '$NOVA_CACHE_TMPFS'"
fi
#----------------------------------
# Replacing devstack's localrc config
#------------------------------------
if [[ -f "devstack.localrc" ]] ; then
rm -f "$DEVSTACK_DIR/localrc"
cp devstack.localrc "$DEVSTACK_DIR/localrc"
else
echo "File 'devstack.localrc' not found!"
fi
#------------------------------------
#===============================================================================

View File

@ -0,0 +1,6 @@
#!/bin/bash
if [[ -z "$1" ]] ; then
source ./localrc
fi

View File

@ -0,0 +1,25 @@
#!/bin/bash
source ./localrc
# Executing pre-stack actions
#===============================================================================
source ./pre-stack.sh no-localrc
#===============================================================================
# Creating stack
#===============================================================================
$DEVSTACK_DIR/stack.sh
#===============================================================================
# Executing post-stack actions
#===============================================================================
source ./post-stack.sh no-localrc
#===============================================================================

View File

@ -0,0 +1,22 @@
#!/bin/bash
image_file=$1
function die {
echo "$@"
exit 1
}
[ -z "$image_file" ] && die "VM name MUST be provided!"
[ -f "$image_file" ] || die "File '$image_file' not found."
echo "Starting VM '$image_file' ..."
kvm \
-m 2048 \
-drive file="$image_file",if=virtio \
-redir tcp:3389::3389 -redir tcp:3390::3390 \
-nographic \
-usbdevice tablet \
-vnc :20

View File

@ -0,0 +1,22 @@
#!/bin/bash
source ./localrc
# Executing pre-unstack actions
#===============================================================================
source ./pre-unstack.sh no-localrc
#===============================================================================
# Executing unstack.sh
#===============================================================================
$DEVSTACK_DIR/unstack.sh
#===============================================================================
# Executing post-unstack actions
#===============================================================================
source ./post-unstack.sh no-localrc
#===============================================================================