Add tripleo.sh

tripleo.sh is a script to automate a TripleO setup. It's goals are to be
used in aiding:

- developer setups
- CI
- documentation generation (hopefully)

It's not a new CLI, or end user facing wrapper around existing TripleO
CLI's.

tripleo.sh should never contain any "business" logic in it that is
necessary for a successful deployment. It should instead just mirror the
steps that we document for TripleO end users.

Change-Id: I9396a487964955f59584965ecbfd4c88cca87c0e
This commit is contained in:
James Slagle 2015-09-18 06:40:31 -04:00
parent eb33b7f4ff
commit fdbff2b7eb
2 changed files with 379 additions and 0 deletions

49
scripts/set-os-type Executable file
View File

@ -0,0 +1,49 @@
#!/bin/bash
TRIPLEO_OS_FAMILY='unsupported' # Generic OS Family: debian, redhat, suse
TRIPLEO_OS_DISTRO='unsupported' # Specific distro: centos, fedora, rhel,
# opensuse, sles, ubuntu
if [ -f /etc/redhat-release ]; then
TRIPLEO_OS_FAMILY='redhat'
if $(grep -Eqs 'Red Hat Enterprise Linux' /etc/redhat-release); then
TRIPLEO_OS_DISTRO='rhel'
fi
if $(grep -Eqs 'CentOS' /etc/redhat-release); then
TRIPLEO_OS_DISTRO='centos'
fi
if $(grep -Eqs 'Fedora' /etc/redhat-release); then
TRIPLEO_OS_DISTRO='fedora'
fi
fi
if [ -f /etc/debian_version ]; then
TRIPLEO_OS_FAMILY='debian'
if $(grep -Eqs 'Ubuntu' /etc/lsb-release); then
TRIPLEO_OS_DISTRO='ubuntu'
fi
if $(grep -Eqs 'Debian' /etc/os-release); then
TRIPLEO_OS_DISTRO='debian'
fi
fi
function get_os_release {
(
source /etc/os-release
echo $ID
)
}
if [ -f /etc/os-release ]; then
if [ "$(get_os_release)" = "opensuse" ]; then
TRIPLEO_OS_FAMILY='suse'
TRIPLEO_OS_DISTRO='opensuse'
fi
if [ "$(get_os_release)" = "sles" ]; then
TRIPLEO_OS_FAMILY='suse'
TRIPLEO_OS_DISTRO='sles'
fi
fi
export TRIPLEO_OS_FAMILY
export TRIPLEO_OS_DISTRO

330
scripts/tripleo.sh Executable file
View File

@ -0,0 +1,330 @@
#!/bin/bash
# Copyright 2015 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##############################################################################
# tripleo.sh is a script to automate a TripleO setup. It's goals are to be
# used in aiding:
#
# - developer setups
# - CI
# - documentation generation (hopefully)
#
# It's not a new CLI, or end user facing wrapper around existing TripleO
# CLI's.
#
# tripleo.sh should never contain any "business" logic in it that is
# necessary for a successful deployment. It should instead just mirror the
# steps that we document for TripleO end users.
#
##############################################################################
set -eu
set -o pipefail
SCRIPT_NAME=${SCRIPT_NAME:-$(basename $0)}
function show_options () {
echo "Usage: $SCRIPT_NAME [options]"
echo
echo "Automates TripleO setup steps."
echo
echo "$SCRIPT_NAME is also configurable via environment variables, most of"
echo "which are not exposed via cli args for simplicity. See the source"
echo "for the set of environment variables that can be overridden."
echo
echo "Note that cli args always take precedence over environment"
echo "variables."
echo
echo "Options:"
echo " --repo-setup -- Perform repository setup."
echo " --undercloud -- Install the undercloud."
echo " --overcloud-images -- Build and load overcloud images."
echo " --register-nodes -- Register and configure nodes."
echo " --introspect-nodes -- Introspect nodes."
echo " --flavors -- Create flavors for deployment."
echo " --overcloud-deploy -- Deploy an overcloud."
echo " --all, -a -- Run all of the above commands."
echo " -x -- enable tracing"
echo " --help, -h -- Print this help message."
echo
exit 1
}
if [ ${#@} = 0 ]; then
show_options
exit 1
fi
TEMP=$(getopt -o ,h \
-l,help,repo-setup,undercloud,overcloud-images,register-nodes,introspect-nodes,flavors,overcloud-deploy,all \
-o,x,h,a \
-n $SCRIPT_NAME -- "$@")
if [ $? != 0 ]; then
show_options
exit 1
fi
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
ALL=${ALL:-""}
DELOREAN_REPO_FILE=${DELOREAN_REPO_FILE:-"delorean.repo"}
DELOREAN_REPO_URL=${DELOREAN_REPO_URL:-"\
http://trunk.rdoproject.org/centos7/current-tripleo/"}
FLAVORS=${FLAVORS:-""}
INSTACKENV_JSON_PATH=${INSTACKENV_JSON_PATH:-"$HOME/instackenv.json"}
INTROSPECT_NODES=${INTROSPECT_NODES:-""}
REGISTER_NODES=${REGISTER_NODES:-""}
OVERCLOUD_DEPLOY=${OVERCLOUD_DEPLOY:-""}
OVERCLOUD_DEPLOY_ARGS=${OVERCLOUD_DEPLOY_ARGS:-""}
OVERCLOUD_IMAGES_PATH=${OVERCLOUD_IMAGES_PATH:-"$HOME"}
OVERCLOUD_IMAGES=${OVERCLOUD_IMAGES:-""}
OVERCLOUD_IMAGES_DIB_YUM_REPO_CONF=${OVERCLOUD_IMAGES_DIB_YUM_REPO_CONF:-"\
/etc/yum.repos.d/delorean.repo \
/etc/yum.repos.d/delorean-current.repo \
/etc/yum.repos.d/delorean-deps.repo"}
RDO_RELEASE=${RDO_RELEASE:-kilo}
REPO_SETUP=${REPO_SETUP:-""}
STDERR=/dev/null
UNDERCLOUD=${UNDERCLOUD:-""}
UNDERCLOUD_CONF=${UNDERCLOUD_CONF:-"/usr/share/instack-undercloud/undercloud.conf.sample"}
# TODO: remove this when Image create in openstackclient supports the v2 API
export OS_IMAGE_API_VERSION=1
while true ; do
case "$1" in
--all|-a ) ALL="1"; shift 1;;
--flavors) FLAVORS="1"; shift 1;;
--introspect-nodes) INTROSPECT_NODES="1"; shift 1;;
--register-nodes) REGISTER_NODES="1"; shift 1;;
--overcloud-deploy) OVERCLOUD_DEPLOY="1"; shift 1;;
--overcloud-images) OVERCLOUD_IMAGES="1"; shift 1;;
--repo-setup) REPO_SETUP="1"; shift 1;;
--undercloud) UNDERCLOUD="1"; shift 1;;
-x) set -x; STDERR=/dev/stderr; shift 1;;
-h | --help) show_options 0;;
--) shift ; break ;;
*) echo "Error: unsupported option $1." ; exit 1 ;;
esac
done
function log {
echo "#################"
echo -n "$SCRIPT_NAME -- "
echo $@
echo "#################"
}
function stackrc_check {
OS_AUTH_URL=${OS_AUTH_URL:-""}
if [ -z "$OS_AUTH_URL" ]; then
echo "You must source a stackrc file for the Undercloud."
echo "Attempting to source stackrc at $HOME/stackrc"
source $HOME/stackrc
echo "Done."
fi
}
function repo_setup {
log "Repository setup"
# sets $TRIPLEO_OS_FAMILY and $TRIPLEO_OS_DISTRO
source $(dirname ${BASH_SOURCE[0]:-$0})/set-os-type
if [ "$TRIPLEO_OS_DISTRO" = "centos" ]; then
# Enable epel
rpm -q epel-release || sudo yum -y install epel-release
fi
# Enable the Delorean Deps repository
sudo curl -o /etc/yum.repos.d/delorean-deps.repo http://trunk.rdoproject.org/centos7/delorean-deps.repo
sudo sed -i -e 's%priority=.*%priority=30%' /etc/yum.repos.d/delorean-deps.repo
# Enable last known good RDO Trunk Delorean repository
sudo curl -o /etc/yum.repos.d/delorean.repo $DELOREAN_REPO_URL/$DELOREAN_REPO_FILE
sudo sed -i -e 's%priority=.*%priority=20%' /etc/yum.repos.d/delorean.repo
# Enable latest RDO Trunk Delorean repository
sudo curl -o /etc/yum.repos.d/delorean-current.repo http://trunk.rdoproject.org/centos7/current/delorean.repo
sudo sed -i -e 's%priority=.*%priority=10%' /etc/yum.repos.d/delorean-current.repo
sudo sed -i 's/\[delorean\]/\[delorean-current\]/' /etc/yum.repos.d/delorean-current.repo
# TODO: remove python-hardware from the list below once centos7/current-tripleo includes https://review.gerrithub.io/#/c/247917/
sudo /bin/bash -c "cat <<-EOF>>/etc/yum.repos.d/delorean-current.repo
includepkgs=diskimage-builder,openstack-heat,instack,instack-undercloud,openstack-ironic,openstack-ironic-inspector,os-cloud-config,os-net-config,python-ironic-inspector-client,python-tripleoclient,tripleo-common,openstack-tripleo-heat-templates,openstack-tripleo-image-elements,openstack-tuskar-ui-extras,openstack-puppet-modules,python-hardware
EOF"
# Install the yum-plugin-priorities package so that the Delorean repository
# takes precedence over the main RDO repositories.
sudo yum -y install yum-plugin-priorities
log "Repository setup - DONE."
}
function undercloud {
log "Undercloud install"
sudo yum install -y python-tripleoclient
if [ ! -f ~/undercloud.conf ]; then
cp -b -f $UNDERCLOUD_CONF ~/undercloud.conf
else
log "~/undercloud.conf already exists, not overwriting"
fi
# Hostname check, add to /etc/hosts if needed
if ! grep -E "^127.0.0.1\s*$HOSTNAME" /etc/hosts; then
sudo /bin/bash -c "echo \"127.0.0.1 $HOSTNAME\" >> /etc/hosts"
fi
openstack undercloud install
log "Undercloud install - DONE."
}
function overcloud_images {
log "Overcloud images"
log "Overcloud images saved in $OVERCLOUD_IMAGES_PATH"
# (slagle) TODO: This needs to be fixed in python-tripleoclient or
# diskimage-builder!
# Ensure yum-plugin-priorities is installed
echo -e '#!/bin/bash\nyum install -y yum-plugin-priorities' | sudo tee /usr/share/diskimage-builder/elements/yum/pre-install.d/99-tmphacks
sudo chmod +x /usr/share/diskimage-builder/elements/yum/pre-install.d/99-tmphacks
log "Overcloud images saved in $OVERCLOUD_IMAGES_PATH"
pushd $OVERCLOUD_IMAGES_PATH
DIB_YUM_REPO_CONF=$OVERCLOUD_IMAGES_DIB_YUM_REPO_CONF \
openstack overcloud image build --all 2>&1 | \
tee -a overcloud-image-build.log
stackrc_check
openstack overcloud image upload
popd
log "Overcloud images - DONE."
}
function register_nodes {
log "Register nodes"
if [ ! -f $INSTACKENV_JSON_PATH ]; then
echo Could not find instackenv.json at $INSTACKENV_JSON_PATH
echo Specify the path to instackenv.json with '$INSTACKENV_JSON_PATH'
exit 1
fi
stackrc_check
openstack baremetal import --json $INSTACKENV_JSON_PATH
ironic node-list
openstack baremetal configure boot
log "Register nodes - DONE."
}
function introspect_nodes {
log "Introspect nodes"
stackrc_check
openstack baremetal introspection bulk start
log "Introspect nodes - DONE."
}
function flavors {
log "Flavors"
stackrc_check
openstack flavor create --id auto --ram 4096 --disk 40 --vcpus 1 baremetal
openstack flavor \
set --property "capabilities:boot_option"="local" \
baremetal
log "Flavors - DONE."
}
function overcloud_deploy {
log "Overcloud deploy"
# Force use of --templates
if [[ ! $OVERCLOUD_DEPLOY_ARGS =~ --templates ]]; then
OVERCLOUD_DEPLOY_ARGS="$OVERCLOUD_DEPLOY_ARGS --templates"
fi
stackrc_check
openstack overcloud deploy $OVERCLOUD_DEPLOY_ARGS
log "Overcloud deployment started - DONE."
}
if [ "$REPO_SETUP" = 1 ]; then
repo_setup
fi
if [ "$UNDERCLOUD" = 1 ]; then
undercloud
fi
if [ "$OVERCLOUD_IMAGES" = 1 ]; then
overcloud_images
fi
if [ "$REGISTER_NODES" = 1 ]; then
register_nodes
fi
if [ "$INTROSPECT_NODES" = 1 ]; then
introspect_nodes
fi
if [ "$FLAVORS" = 1 ]; then
flavors
fi
if [ "$OVERCLOUD_DEPLOY" = 1 ]; then
overcloud_deploy
fi
if [ "$ALL" = 1 ]; then
repo_setup
undercloud
overcloud_images
register_nodes
introspect_nodes
flavors
overcloud_deploy
fi