Add Amphora base image creation scripts for Octavia
Implements: blueprint base-image Change-Id: I3e72db6d2f19fe45138758eb0821e27aa1c2542a
This commit is contained in:
parent
7a3f947081
commit
9df9ff9137
205
diskimage-create/README.rst
Normal file
205
diskimage-create/README.rst
Normal file
@ -0,0 +1,205 @@
|
||||
Diskimage-builder script for creating Octavia Amphora images
|
||||
============================================================
|
||||
|
||||
Octavia is an operator-grade reference implementation for Load Balancing as a
|
||||
Service (LBaaS) for OpenStack. The component of Octavia that does the load
|
||||
balancing is known as amphora. Amphora may be a virtual machine, may be a
|
||||
container, or may run on bare metal. Creating images for bare metal amphora
|
||||
installs is outside the scope of this version but may be added in a
|
||||
future release.
|
||||
|
||||
Prerequisites
|
||||
=============
|
||||
|
||||
This script assumes a typical Linux environment and was developed on
|
||||
Ubuntu 12.04.5 LTS.
|
||||
|
||||
Python pip should be installed as well as the following python modules:
|
||||
|
||||
| argparse
|
||||
| Babel>=1.3
|
||||
| dib-utils
|
||||
| PyYAML
|
||||
|
||||
Your cache directory should have at least 1GB available, the working directory
|
||||
will need ~1.5GB, and your image destination will need ~500MB
|
||||
|
||||
The script expects to find the diskimage-builder and tripleo-image-elements
|
||||
git repositories one directory above the Octavia git repository.
|
||||
|
||||
| /<some directory>/octavia
|
||||
| /<some directory>/diskimage-builder
|
||||
| /<some directory>/tripleo-image-elements
|
||||
|
||||
| cd /<some directory>
|
||||
| git clone https://github.com/stackforge/octavia.git
|
||||
| git clone https://git.openstack.org/openstack/diskimage-builder.git
|
||||
| git clone https://git.openstack.org/openstack/tripleo-image-elements.git
|
||||
|
||||
These paths can be overriden with the following environment variables:
|
||||
|
||||
| OCTAVIA_REPO_PATH = /<some directory>/octavia
|
||||
| DIB_REPO_PATH = /<some directory>/diskimage-builder
|
||||
| DIB_ELEMENTS = /<some directory>/diskimage-builder/elements
|
||||
| ELEMENTS_REPO_PATH = /<some directory>/tripleo-image-elements
|
||||
| TRIPLEO_ELEMENTS_PATH = /<some directory>/tripleo-image-elements/elements
|
||||
|
||||
The following packages are required on each platform:
|
||||
Ubuntu and Fedora: qemu kpartx git
|
||||
CentOS and RedHat Enterprise Linux: qemu-kvm qemu-img kpartx git
|
||||
CentOS requires the EPEL repo and python-argparse:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ sudo rpm -Uvh --force http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm
|
||||
$ yum install python-argparse
|
||||
|
||||
Test Prerequisites
|
||||
------------------
|
||||
The tox image tests require libguestfs-tools 1.24 or newer.
|
||||
Libguestfs allows testing the Amphora image without requiring root privledges.
|
||||
On Ubuntu systems you also need to give read access to the kernels for the user
|
||||
running the tests:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ sudo chmod 0644 /boot/vmlinuz*
|
||||
|
||||
Tests were run on Ubuntu 14.04.1 LTS during development.
|
||||
|
||||
Usage
|
||||
=====
|
||||
This script and associated elements will build Amphora images. Current support
|
||||
is with an Ubuntu base OS and HAProxy. The script can use Fedora
|
||||
or CentOS as a base OS but these will not initially be tested or supported.
|
||||
As the project progresses and/or the diskimage-builder project adds support
|
||||
for additional base OS options they may become available for Amphora images.
|
||||
This does not mean that they are necessarily supported or tested.
|
||||
|
||||
The script will use environment variables to customize the build beyond the
|
||||
Octavia project defaults, such as adding elements.
|
||||
|
||||
The supported and tested image is created by using the diskimage-create.sh
|
||||
defaults (no command line parameters or environment variables set). As the
|
||||
project progresses we may add additional supported configurations.
|
||||
|
||||
Command syntax:
|
||||
|
||||
|
||||
.. line-block::
|
||||
|
||||
$ diskimage-create.sh
|
||||
[-a i386 | **amd64** | armhf ]
|
||||
[-b **haproxy** ]
|
||||
[-c **~/.cache/image-create** | <cache directory> ]
|
||||
[-h]
|
||||
[-i **ubuntu** | fedora | centos ]
|
||||
[-o **amphora-x64-haproxy** | <filename> ]
|
||||
[-r <root password> ]
|
||||
[-s **5** | <size in GB> ]
|
||||
[-t **qcow2** | tar ]
|
||||
[-v]
|
||||
[-w <working directory> ]
|
||||
|
||||
'-a' is the architecture type for the image (default: amd64)
|
||||
'-b' is the backend type (default: haproxy)
|
||||
'-c' is the path to the cache directory (default: ~/.cache/image-create)
|
||||
'-h' display help message
|
||||
'-i' is the base OS (default: ubuntu)
|
||||
'-o' is the output image file name
|
||||
'-r' enable the root account in the generated image (default: disabled)
|
||||
'-s' is the image size to produce in gigabytes (default: 5)
|
||||
'-t' is the image type (default: qcow2)
|
||||
'-v' display the script version
|
||||
'-w' working directory for image building (default: .)
|
||||
|
||||
|
||||
Environment Variables
|
||||
=====================
|
||||
These are optional environment variables that can be set to override the script
|
||||
defaults.
|
||||
|
||||
CLOUD_INIT_DATASOURCES
|
||||
- Comma seperated list of cloud-int datasources
|
||||
- Default: ConfigDrive
|
||||
- Options: NoCloud, ConfigDrive, OVF, MAAS, Ec2, <others>
|
||||
- Reference: https://launchpad.net/cloud-init
|
||||
|
||||
BASE_OS_MIRROR
|
||||
- URL to a mirror for the base OS selected
|
||||
- Default: None
|
||||
|
||||
DIB_ELEMENTS
|
||||
- Override the elements used to build the image
|
||||
- Default: None
|
||||
|
||||
DIB_LOCAL_ELEMENTS
|
||||
- Elements to add to the build (requires DIB_LOCAL_ELEMENTS_PATH be
|
||||
specified)
|
||||
- Default: None
|
||||
|
||||
DIB_LOCAL_ELEMENTS_PATH
|
||||
- Path to the local elements directory
|
||||
- Default: None
|
||||
|
||||
DIB_REPO_PATH
|
||||
- Directory containing diskimage-builder
|
||||
- Default: <directory above OCTAVIA_HOME>/diskimage-builder
|
||||
- Reference: https://github.com/openstack/diskimage-builder
|
||||
|
||||
ELEMENTS_PATH
|
||||
- Directory that contains the default elements
|
||||
- Default: <ELEMENTS_REPO_PATH>/elements
|
||||
- Reference: https://github.com/openstack/tripleo-image-elements
|
||||
|
||||
ELEMENTS_REPO_PATH
|
||||
- Directory containing tripleo-image-elements
|
||||
- Default: <directory above OCTAVIA_HOME>/tripleo-image-elements
|
||||
- Reference: https://github.com/openstack/tripleo-image-elements
|
||||
|
||||
OCTAVIA_REPO_PATH
|
||||
- Directory containing octavia
|
||||
- <directory above the script location>
|
||||
- Reference: https://github.com/stackforge/octavia
|
||||
|
||||
Container Support
|
||||
=================
|
||||
The Docker command line required to import a tar file created with this script
|
||||
is:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ docker import - image:amphora-x64-haproxy < amphora-x64-haproxy.tar
|
||||
|
||||
|
||||
References
|
||||
==========
|
||||
|
||||
This documentation and script(s) leverage prior work by the OpenStack TripleO
|
||||
and Sahara teams. Thank you to everyone that worked on them for providing a
|
||||
great foundation for creating Octavia Amphora images.
|
||||
|
||||
| https://github.com/openstack/diskimage-builder
|
||||
| https://github.com/openstack/diskimage-builder/blob/master/docs/docker.md
|
||||
| https://github.com/openstack/tripleo-image-elements
|
||||
| https://github.com/openstack/sahara-image-elements
|
||||
|
||||
Copyright
|
||||
=========
|
||||
|
||||
Copyright 2014 Hewlett-Packard Development Company, L.P.
|
||||
|
||||
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.
|
||||
|
342
diskimage-create/diskimage-create.sh
Executable file
342
diskimage-create/diskimage-create.sh
Executable file
@ -0,0 +1,342 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2014 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
usage() {
|
||||
echo
|
||||
echo "Usage: $(basename $0)"
|
||||
echo " [-a i386 | **amd64** | armhf ]"
|
||||
echo " [-b **haproxy** ]"
|
||||
echo " [-c **~/.cache/image-create** | <cache directory> ]"
|
||||
echo " [-h]"
|
||||
echo " [-i **ubuntu** | fedora | centos ]"
|
||||
echo " [-o **amphora-x64-haproxy** | <filename> ]"
|
||||
echo " [-r <root password> ]"
|
||||
echo " [-s **5** | <size in GB> ]"
|
||||
echo " [-t **qcow2** | tar ]"
|
||||
echo " [-v]"
|
||||
echo " [-w <working directory> ]"
|
||||
echo
|
||||
echo " '-a' is the architecture type for the image (default: amd64)"
|
||||
echo " '-b' is the backend type (default: haproxy)"
|
||||
echo " '-c' is the path to the cache directory (default: ~/.cache/image-create)"
|
||||
echo " '-h' display this help message"
|
||||
echo " '-i' is the base OS (default: ubuntu)"
|
||||
echo " '-o' is the output image file name"
|
||||
echo " '-r' enable the root account in the generated image (default: disabled)"
|
||||
echo " '-s' is the image size to produce in gigabytes (default: 5)"
|
||||
echo " '-t' is the image type (default: qcow2)"
|
||||
echo " '-v' display the script version"
|
||||
echo " '-w' working directory for image building (default: .)"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
version() {
|
||||
echo "Amphora disk image creation script version:"\
|
||||
"`cat $OCTAVIA_REPO_PATH/diskimage-create/version.txt`"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Figure out where our directory is located
|
||||
if [ -z $OCTAVIA_REPO_PATH ]; then
|
||||
AMP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
OCTAVIA_REPO_PATH=${OCTAVIA_REPO_PATH:-${AMP_DIR%/*}}
|
||||
fi
|
||||
|
||||
while getopts "a:b:c:hi:o:t:r:s:vw:" opt; do
|
||||
case $opt in
|
||||
a)
|
||||
AMP_ARCH=$OPTARG
|
||||
if [ $AMP_ARCH != "i386" ] && \
|
||||
[ $AMP_ARCH != "amd64" ] && \
|
||||
[ $AMP_ARCH != "armhf" ]; then
|
||||
echo "Error: Unsupported architecture " $AMP_ARCH " specified"
|
||||
exit 3
|
||||
fi
|
||||
;;
|
||||
b)
|
||||
if [ $OPTARG == "haproxy" ]; then
|
||||
AMP_BACKEND=$OPTARG-octavia
|
||||
else
|
||||
echo "Error: Unsupported backend type " $AMP_BACKEND " specified"
|
||||
exit 3
|
||||
fi
|
||||
;;
|
||||
c)
|
||||
AMP_CACHEDIR=$OPTARG
|
||||
;;
|
||||
h)
|
||||
usage
|
||||
;;
|
||||
i)
|
||||
AMP_BASEOS=$OPTARG
|
||||
if [ $AMP_BASEOS != "ubuntu" ] && \
|
||||
[ $AMP_BASEOS != "fedora" ] && \
|
||||
[ $AMP_BASEOS != "centos" ]; then
|
||||
echo "Error: Unsupported base OS " $AMP_BASEOS " specified"
|
||||
exit 3
|
||||
fi
|
||||
;;
|
||||
o)
|
||||
AMP_OUTPUTFILENAME=$OPTARG
|
||||
;;
|
||||
t)
|
||||
AMP_IMAGETYPE=$OPTARG
|
||||
if [ $AMP_IMAGETYPE != "qcow2" ] && \
|
||||
[ $AMP_IMAGETYPE != "tar" ]; then
|
||||
echo "Error: Unsupported image type " $AMP_IMAGETYPE " specified"
|
||||
exit 3
|
||||
fi
|
||||
;;
|
||||
r)
|
||||
AMP_ROOTPW=$OPTARG
|
||||
;;
|
||||
s)
|
||||
AMP_IMAGESIZE=$OPTARG
|
||||
if ! [[ $AMP_IMAGESIZE =~ ^[0-9]+$ ]]; then
|
||||
echo "Error: Invalid image size " $AMP_IMAGESIZE " specified"
|
||||
exit 3
|
||||
fi
|
||||
;;
|
||||
v)
|
||||
version
|
||||
;;
|
||||
w)
|
||||
AMP_WORKING_DIR=$OPTARG
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1))
|
||||
if [ "$1" ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
# Set the Octavia Amphora defaults if they aren't already set
|
||||
AMP_ARCH=${AMP_ARCH:-"amd64"}
|
||||
|
||||
AMP_BACKEND=${AMP_BACKEND:-"haproxy-octavia"}
|
||||
|
||||
AMP_CACHEDIR=${AMP_CACHEDIR:-"$HOME/.cache/image-create"}
|
||||
|
||||
AMP_BASEOS=${AMP_BASEOS:-"ubuntu"}
|
||||
|
||||
AMP_OUTPUTFILENAME=${AMP_OUTPUTFILENAME:-"$AMP_DIR/amphora-x64-haproxy"}
|
||||
|
||||
AMP_IMAGETYPE=${AMP_IMAGETYPE:-"qcow2"}
|
||||
|
||||
AMP_IMAGESIZE=${AMP_IMAGESIZE:-5}
|
||||
|
||||
OCTAVIA_ELEMENTS_PATH=$OCTAVIA_REPO_PATH/elements
|
||||
|
||||
if ! [ -d $OCTAVIA_ELEMENTS_PATH ]; then
|
||||
echo "ERROR: Octavia elements directory not found at: " $OCTAVIA_ELEMENTS_PATH " Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DIB_REPO_PATH=${DIB_REPO_PATH:-${OCTAVIA_REPO_PATH%/*}/diskimage-builder}
|
||||
|
||||
if ! [ -d $DIB_REPO_PATH ]; then
|
||||
echo "ERROR: diskimage-builder repo directory not found at: " $DIB_REPO_PATH " Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export PATH=$PATH:$DIB_REPO_PATH/bin
|
||||
|
||||
DIB_ELEMENTS_PATH=${DIB_REPO_PATH:-${OCTAVIA_REPO_PATH%/*}/diskimage-builder/elements}
|
||||
|
||||
if ! [ -d $DIB_ELEMENTS_PATH ]; then
|
||||
echo "ERROR: diskimage-builder elements directory not found at: " $DIB_ELEMENTS_PATH " Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ELEMENTS_REPO_PATH=${ELEMENTS_REPO_PATH:-${OCTAVIA_REPO_PATH%/*}/tripleo-image-elements}
|
||||
|
||||
if ! [ -d $ELEMENTS_REPO_PATH ]; then
|
||||
echo "ERROR: tripleo-image-elements repo directory not found at: " $ELEMENTS_REPO_PATH " Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TRIPLEO_ELEMENTS_PATH=${ELEMENTS_PATH:-$ELEMENTS_REPO_PATH/elements}
|
||||
|
||||
if ! [ -d $TRIPLEO_ELEMENTS_PATH ]; then
|
||||
echo "ERROR: tripleo-image-elements elements directory not found at: " $TRIPLEO_ELEMENTS_PATH " Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$DIB_LOCAL_ELEMENTS_PATH" ]; then
|
||||
export ELEMENTS_PATH=$DIB_ELEMENTS_PATH:$TRIPLEO_ELEMENTS_PATH:$OCTAVIA_ELEMENTS_PATH:$DIB_LOCAL_ELEMENTS_PATH
|
||||
else
|
||||
export ELEMENTS_PATH=$DIB_ELEMENTS_PATH:$TRIPLEO_ELEMENTS_PATH:$OCTAVIA_ELEMENTS_PATH
|
||||
fi
|
||||
|
||||
export CLOUD_INIT_DATASOURCES=${CLOUD_INIT_DATASOURCES:-"ConfigDrive"}
|
||||
|
||||
# Find out what platform we are on
|
||||
if [ -e /etc/os-release ]; then
|
||||
platform=$(head -1 /etc/os-release)
|
||||
else
|
||||
platform=$(head -1 /etc/system-release | grep -e CentOS -e 'Red Hat Enterprise Linux' || :)
|
||||
if [ -z "$platform" ]; then
|
||||
echo -e "Unknown Host OS. Impossible to build images.\nAborting"
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$AMP_ROOTPW" ] && [ "$platform" != 'NAME="Ubuntu"' ]; then
|
||||
if [ "$(getenforce)" != "Disabled" ]; then
|
||||
echo "A root password cannot be enabled for images built on this platform while SELinux is enabled."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$AMP_ROOTPW" ]; then
|
||||
echo "Warning: Using a root password in the image, NOT FOR PRODUCTION USAGE."
|
||||
fi
|
||||
|
||||
# Make sure we have the required packages installed
|
||||
if [ "$platform" = 'NAME="Ubuntu"' ]; then
|
||||
PKG_LIST="qemu kpartx git"
|
||||
for pkg in $PKG_LIST; do
|
||||
if ! dpkg --get-selections | grep -q "^$pkg[[:space:]]*install$" >/dev/null; then
|
||||
echo "Required package " $pkg " is not installed. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Also check if we can build the BASEOS on this Ubuntu version
|
||||
UBUNTU_VERSION=`lsb_release -r | awk '{print $2}'`
|
||||
if [ "$AMP_BASEOS" != "ubuntu" ] && \
|
||||
[ 1 -eq $(echo "$UBUNTU_VERSION < 14.04" | bc) ]; then
|
||||
echo "Ubuntu minimum version 14.04 required to build $AMP_BASEOS."
|
||||
echo "Earlier versions don't support the extended attributes required."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
elif [ "$platform" = 'NAME=Fedora' ]; then
|
||||
PKG_LIST="qemu kpartx git"
|
||||
for pkg in $PKG_LIST; do
|
||||
if ! yum list $pkg &> /dev/null; then
|
||||
echo "Required package " $pkg " is not installed. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
else
|
||||
# centos or rhel
|
||||
PKG_LIST="qemu-kvm qemu-img kpartx git"
|
||||
for pkg in $PKG_LIST; do
|
||||
if ! yum list $pkg &> /dev/null; then
|
||||
echo "Required package " $pkg " is not installed. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if [ ${platform:0:6} = "CentOS" ]; then
|
||||
# install EPEL repo, in order to install argparse
|
||||
PKG_LIST="python-argparse"
|
||||
if ! yum list $pkg &> /dev/null; then
|
||||
echo "CentOS requires the python-argparse package be "
|
||||
echo "installed separately from the EPEL repo."
|
||||
echo "Required package " $pkg " is not installed. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
PKG_LIST="Babel argparse dib-utils PyYAML"
|
||||
for pkg in $PKG_LIST; do
|
||||
if ! pip freeze 2>/dev/null| grep -q "^$pkg==" &>/dev/null; then
|
||||
echo "Required python package " $pkg " is not installed. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$AMP_WORKING_DIR" ]; then
|
||||
mkdir -p $AMP_WORKING_DIR
|
||||
TEMP=$(mktemp -d $AMP_WORKING_DIR/diskimage-create.XXXXXX)
|
||||
else
|
||||
TEMP=$(mktemp -d diskimage-create.XXXXXX)
|
||||
fi
|
||||
pushd $TEMP > /dev/null
|
||||
|
||||
# Setup some environment variables with the commit IDs used to build the image
|
||||
pushd $DIB_REPO_PATH > /dev/null
|
||||
export DIB_COMMIT_ID=`git rev-parse HEAD`
|
||||
popd > /dev/null
|
||||
|
||||
pushd $ELEMENTS_REPO_PATH > /dev/null
|
||||
export ELEMENTS_COMMIT_ID=`git rev-parse HEAD`
|
||||
popd > /dev/null
|
||||
|
||||
pushd $OCTAVIA_REPO_PATH > /dev/null
|
||||
export OCTAVIA_COMMIT_ID=`git rev-parse HEAD`
|
||||
popd > /dev/null
|
||||
|
||||
|
||||
# Setup the elements list
|
||||
|
||||
if [ "$AMP_BASEOS" = "ubuntu" ]; then
|
||||
AMP_element_sequence=${AMP_element_sequence:-"base vm ubuntu"}
|
||||
if [ "$BASE_OS_MIRROR" ]; then
|
||||
AMP_element_sequence="$AMP_element_sequence apt-mirror"
|
||||
export UBUNTU_MIRROR="$BASE_OS_MIRROR"
|
||||
fi
|
||||
elif [ "$AMP_BASEOS" = "fedora" ]; then
|
||||
AMP_element_sequence=${AMP_element_sequence:-"base vm fedora"}
|
||||
if [ "$BASE_OS_MIRROR" ]; then
|
||||
AMP_element_sequence="$AMP_element_sequence fedora-mirror"
|
||||
export FEDORA_MIRROR="$BASE_OS_MIRROR"
|
||||
fi
|
||||
elif [ "$AMP_BASEOS" = "centos" ]; then
|
||||
AMP_element_sequence=${AMP_element_sequence:-"base vm centos7"}
|
||||
if [ "$BASE_OS_MIRROR" ]; then
|
||||
AMP_element_sequence="$AMP_element_sequence centos-mirror"
|
||||
export CENTOS_MIRROR="$BASE_OS_MIRROR"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$AMP_ROOTPW" ]; then
|
||||
AMP_element_sequence="$AMP_element_sequence root-passwd"
|
||||
export DIB_PASSWORD=$AMP_ROOTPW
|
||||
fi
|
||||
|
||||
# Add the Octavia Amphora backend element
|
||||
AMP_element_sequence="$AMP_element_sequence $AMP_BACKEND"
|
||||
|
||||
# Allow full elements override
|
||||
if [ "$DIB_ELEMENTS" ]; then
|
||||
AMP_element_sequence="$DIB_ELEMENTS"
|
||||
fi
|
||||
|
||||
if [ "$DIB_LOCAL_ELEMENTS" ]; then
|
||||
AMP_element_sequence="$AMP_element_sequence $DIB_LOCAL_ELEMENTS"
|
||||
fi
|
||||
|
||||
# Build the image
|
||||
|
||||
if [ "$AMP_BASEOS" = "ubuntu" ]; then
|
||||
export DIB_CLOUD_INIT_DATASOURCES=$CLOUD_INIT_DATASOURCES
|
||||
fi
|
||||
|
||||
disk-image-create -a $AMP_ARCH -o $AMP_OUTPUTFILENAME -t $AMP_IMAGETYPE --image-size $AMP_IMAGESIZE --image-cache $AMP_CACHEDIR $AMP_element_sequence
|
||||
|
||||
popd > /dev/null # out of $TEMP
|
||||
rm -rf $TEMP
|
90
diskimage-create/image-tests.sh
Executable file
90
diskimage-create/image-tests.sh
Executable file
@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2014 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# This file is necessary because tox cannot handle pipes in commands
|
||||
|
||||
echo "Examining the Amphora image. This will take some time."
|
||||
|
||||
if [ "$1" ]; then
|
||||
AMP_IMAGE_LOCATION=$1/amphora-x64-haproxy.qcow2
|
||||
else
|
||||
AMP_IMAGE_LOCATION=amphora-x64-haproxy.qcow2
|
||||
fi
|
||||
|
||||
if ! [ -f $AMP_IMAGE_LOCATION ]; then
|
||||
echo "ERROR: Amphora image not found at: $AMP_IMAGE_LOCATION"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check the image size
|
||||
virt-df -a $AMP_IMAGE_LOCATION | \
|
||||
grep -q "amphora-x64-haproxy.qcow2:/dev/sda1[ \t]*5015940[ \t]*.*"
|
||||
if [ $? != 0 ]; then
|
||||
echo "ERROR: Amphora image did not pass the default size test"
|
||||
exit 1
|
||||
else
|
||||
echo "Amphora image size is correct"
|
||||
fi
|
||||
|
||||
# Check the kernel
|
||||
virt-inspector $AMP_IMAGE_LOCATION | \
|
||||
virt-inspector --xpath \
|
||||
'/operatingsystems/operatingsystem/distro' \
|
||||
| grep -q '<distro>ubuntu</distro>'
|
||||
if [ $? != 0 ]; then
|
||||
echo "ERROR: Amphora image is using the wrong default distribution"
|
||||
exit 1
|
||||
else
|
||||
echo "Amphora image is using the correct distribution"
|
||||
fi
|
||||
|
||||
virt-inspector $AMP_IMAGE_LOCATION | \
|
||||
virt-inspector --xpath \
|
||||
'/operatingsystems/operatingsystem/arch' \
|
||||
| grep -q '<arch>x86_64</arch>'
|
||||
if [ $? != 0 ]; then
|
||||
echo "ERROR: Amphora image is using the wrong default architecture"
|
||||
exit 1
|
||||
else
|
||||
echo "Amphora image is using the correct architecture"
|
||||
fi
|
||||
|
||||
virt-inspector $AMP_IMAGE_LOCATION | \
|
||||
virt-inspector --xpath \
|
||||
'/operatingsystems/operatingsystem/format' \
|
||||
| grep -q '<format>installed</format>'
|
||||
if [ $? != 0 ]; then
|
||||
echo "ERROR: Amphora image is in the wrong format (should be installed)"
|
||||
exit 1
|
||||
else
|
||||
echo "Amphora image is using the correct format"
|
||||
fi
|
||||
|
||||
# Check for HAProxy
|
||||
virt-inspector $AMP_IMAGE_LOCATION | \
|
||||
virt-inspector --xpath \
|
||||
'/operatingsystems/operatingsystem/applications/application/name[text()="haproxy"]' \
|
||||
| grep -q '<name>haproxy</name>'
|
||||
if [ $? != 0 ]; then
|
||||
echo "ERROR: Amphora image is missing the haproxy package"
|
||||
exit 1
|
||||
else
|
||||
echo "HAProxy package found in the Amphora image"
|
||||
fi
|
||||
|
||||
echo "Amphora image looks good."
|
||||
exit 0
|
4
diskimage-create/requirements.txt
Normal file
4
diskimage-create/requirements.txt
Normal file
@ -0,0 +1,4 @@
|
||||
argparse
|
||||
Babel>=1.3
|
||||
dib-utils
|
||||
PyYAML
|
3
diskimage-create/test-requirements.txt
Normal file
3
diskimage-create/test-requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
bashate
|
||||
doc8
|
||||
Pygments
|
28
diskimage-create/tox.ini
Normal file
28
diskimage-create/tox.ini
Normal file
@ -0,0 +1,28 @@
|
||||
[tox]
|
||||
minversion = 1.8
|
||||
envlist = bashate,docs,py27
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
setenv = VIRTUAL_ENV={envdir}
|
||||
install_command = pip install -U {opts} {packages}
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
whitelist_externals = virt-df
|
||||
virt-inspector
|
||||
mkdir
|
||||
rm
|
||||
commands = mkdir -p {toxinidir}/.amp_tox_test
|
||||
./diskimage-create.sh -o {toxinidir}/.amp_tox_test/amphora-x64-haproxy -w {toxworkdir}
|
||||
# Work around tox limitations with command pipes
|
||||
# https://bitbucket.org/hpk42/tox/issue/73/pipe-output-of-command-into-file
|
||||
./image-tests.sh {toxinidir}/.amp_tox_test
|
||||
rm -rf {toxinidir}/.amp_tox_test
|
||||
|
||||
[testenv:docs]
|
||||
commands = doc8 README.rst ../elements/centos-mirror/README.rst ../elements/apt-mirror/README.rst ../elements/fedora-mirror/README.rst ../elements/haproxy-octavia/README.rst ../elements/root-passwd/README.rst
|
||||
|
||||
[testenv:bashate]
|
||||
commands = bashate diskimage-create.sh
|
||||
bashate image-tests.sh
|
||||
|
1
diskimage-create/version.txt
Normal file
1
diskimage-create/version.txt
Normal file
@ -0,0 +1 @@
|
||||
0.1
|
9
elements/apt-mirror/README.rst
Normal file
9
elements/apt-mirror/README.rst
Normal file
@ -0,0 +1,9 @@
|
||||
This element enables the use of a mirror for updating Ubuntu cloud images.
|
||||
Using a local mirror increases the speed of building the image.
|
||||
|
||||
The Ubuntu mirror URL is specified by setting the 'UBUNTU_MIRROR' environment
|
||||
variable.
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ export UBUNTU_MIRROR=http://<local mirror hostname>/<path to mirror>
|
3
elements/apt-mirror/finalise.d/99-setup
Executable file
3
elements/apt-mirror/finalise.d/99-setup
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
rm /etc/apt/apt.conf.d/01proxy
|
5
elements/apt-mirror/pre-install.d/00-apt
Executable file
5
elements/apt-mirror/pre-install.d/00-apt
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
mkdir -p /etc/apt/apt.conf.d/
|
||||
touch /etc/apt/apt.conf.d/01proxy
|
||||
echo -e "Acquire::http { Proxy \"$UBUNTU_MIRROR\"; };" > /etc/apt/apt.conf.d/01proxy
|
5
elements/apt-mirror/root.d/0-check
Executable file
5
elements/apt-mirror/root.d/0-check
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
if [ -z "$UBUNTU_MIRROR" ]; then
|
||||
echo "You should specify parameter 'UBUNTU_MIRROR'"
|
||||
exit 2
|
||||
fi
|
9
elements/centos-mirror/README.rst
Normal file
9
elements/centos-mirror/README.rst
Normal file
@ -0,0 +1,9 @@
|
||||
This element enables the use of a mirror for updating CentOS cloud images.
|
||||
Using a local mirror increases the speed of building the image.
|
||||
|
||||
The CentOS mirror URL is specified by setting the 'CENTOS_MIRROR' environment
|
||||
variable.
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ export UBUNTU_MIRROR=http://<local mirror hostname>/<path to mirror>
|
3
elements/centos-mirror/finalise.d/99-setup
Executable file
3
elements/centos-mirror/finalise.d/99-setup
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
mv /opt/repos/* /etc/yum.repos.d/
|
13
elements/centos-mirror/pre-install.d/00-yum
Executable file
13
elements/centos-mirror/pre-install.d/00-yum
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
mkdir -p /opt/repos
|
||||
mv /etc/yum.repos.d/* /opt/repos/
|
||||
cat >> /etc/yum.repos.d/centos.repo <<EOF
|
||||
[Local-Repository]
|
||||
name=CentOS \$releasever - \$basearch - Local
|
||||
baseurl=$CENTOS_MIRROR
|
||||
enabled=1
|
||||
gpgcheck=0
|
||||
priority=1
|
||||
EOF
|
||||
yum makecache
|
5
elements/centos-mirror/root.d/0-check
Executable file
5
elements/centos-mirror/root.d/0-check
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
if [ -z "$CENTOS_MIRROR" ]; then
|
||||
echo "You should specify parameter 'CENTOS_MIRROR'"
|
||||
exit 2
|
||||
fi
|
9
elements/fedora-mirror/README.rst
Normal file
9
elements/fedora-mirror/README.rst
Normal file
@ -0,0 +1,9 @@
|
||||
This element enables the use of a mirror for updating Fedora cloud images.
|
||||
Using a local mirror increases the speed of building the image.
|
||||
|
||||
The Fedora mirror URL is specified by setting the 'FEDORA_MIRROR' environment
|
||||
variable.
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ export UBUNTU_MIRROR=http://<local mirror hostname>/<path to mirror>
|
3
elements/fedora-mirror/finalise.d/99-setup
Executable file
3
elements/fedora-mirror/finalise.d/99-setup
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
mv /opt/repos/* /etc/yum.repos.d/
|
13
elements/fedora-mirror/pre-install.d/00-yum
Executable file
13
elements/fedora-mirror/pre-install.d/00-yum
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
mkdir -p /opt/repos
|
||||
mv /etc/yum.repos.d/* /opt/repos
|
||||
cat >> /etc/yum.repos.d/fedora.repo <<EOF
|
||||
[Local-Repository]
|
||||
name=Fedora \$releasever - \$basearch - Local
|
||||
baseurl=$FEDORA_MIRROR
|
||||
enabled=1
|
||||
gpgcheck=0
|
||||
priority=1
|
||||
EOF
|
||||
yum makecache
|
5
elements/fedora-mirror/root.d/0-check
Executable file
5
elements/fedora-mirror/root.d/0-check
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
if [ -z "$FEDORA_MIRROR" ]; then
|
||||
echo "You should specify parameter 'FEDORA_MIRROR'"
|
||||
exit 2
|
||||
fi
|
3
elements/haproxy-octavia/README.rst
Normal file
3
elements/haproxy-octavia/README.rst
Normal file
@ -0,0 +1,3 @@
|
||||
Element to install an Octavia Amphora with an haproxy backend.
|
||||
|
||||
|
3
elements/haproxy-octavia/element-deps
Normal file
3
elements/haproxy-octavia/element-deps
Normal file
@ -0,0 +1,3 @@
|
||||
os-svc-install
|
||||
package-installs
|
||||
sysctl
|
6
elements/haproxy-octavia/install.d/76-haproxy
Executable file
6
elements/haproxy-octavia/install.d/76-haproxy
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eux
|
||||
set -o pipefail
|
||||
|
||||
[ -d /var/lib/haproxy ] || install -d -D -m 0755 -o root -g root /var/lib/haproxy
|
@ -0,0 +1 @@
|
||||
haproxy
|
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -eux
|
||||
set -o pipefail
|
||||
|
||||
# Allow haproxy to proxy any port if SELinux is in enforcing mode
|
||||
# https://bugs.launchpad.net/tripleo/+bug/1339938
|
||||
if [[ -x /usr/sbin/semanage ]]; then
|
||||
setsebool -P haproxy_connect_any 1
|
||||
fi
|
@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
set -o pipefail
|
||||
|
||||
sysctl-set-value net.ipv4.tcp_max_tw_buckets 5800000
|
||||
sysctl-set-value net.ipv4.tcp_max_orphans 5800000
|
||||
sysctl-set-value net.ipv4.tcp_max_syn_backlog 40960
|
||||
sysctl-set-value net.ipv4.tcp_keepalive_time 300
|
||||
sysctl-set-value net.ipv4.tcp_tw_recycle 0
|
||||
sysctl-set-value net.ipv4.tcp_tw_reuse 1
|
||||
sysctl-set-value net.ipv4.tcp_timestamps 0
|
||||
sysctl-set-value net.ipv4.tcp_ecn 0
|
||||
sysctl-set-value net.ipv4.tcp_sack 0
|
||||
sysctl-set-value net.ipv4.tcp_dsack 0
|
||||
sysctl-set-value net.ipv4.netfilter.ip_conntrack_max 1524288
|
||||
sysctl-set-value net.core.somaxconn 40960
|
||||
sysctl-set-value net.ipv4.tcp_synack_retries 3
|
||||
sysctl-set-value net.core.netdev_max_backlog 40960
|
||||
sysctl-set-value fs.file-max 1048576
|
||||
sysctl-set-value net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait 5
|
||||
sysctl-set-value net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait 5
|
||||
sysctl-set-value net.ipv4.tcp_fin_timeout 5
|
||||
|
||||
# Currently the tripleo-image-elements sysctl element can't handle multi-value
|
||||
# settings, so I will set them manually here
|
||||
NAME=net.ipv4.tcp_rmem
|
||||
VALUE="16384 65536 524288"
|
||||
FILENAME="/etc/sysctl.d/${NAME}.conf"
|
||||
cat > $FILENAME <<EOF_CAT
|
||||
$NAME = $VALUE
|
||||
EOF_CAT
|
||||
|
||||
NAME=net.ipv4.tcp_wmem
|
||||
VALUE="16384 349520 699040"
|
||||
FILENAME="/etc/sysctl.d/${NAME}.conf"
|
||||
cat > $FILENAME <<EOF_CAT
|
||||
$NAME = $VALUE
|
||||
EOF_CAT
|
||||
|
||||
NAME=net.ipv4.ip_local_port_range
|
||||
VALUE="1024 65000"
|
||||
FILENAME="/etc/sysctl.d/${NAME}.conf"
|
||||
cat > $FILENAME <<EOF_CAT
|
||||
$NAME = $VALUE
|
||||
EOF_CAT
|
2
elements/haproxy-octavia/svc-map
Normal file
2
elements/haproxy-octavia/svc-map
Normal file
@ -0,0 +1,2 @@
|
||||
haproxy:
|
||||
default: haproxy
|
5
elements/root-passwd/README.rst
Normal file
5
elements/root-passwd/README.rst
Normal file
@ -0,0 +1,5 @@
|
||||
This element assigns a password to the root account in the image and enables
|
||||
password login via ssh.
|
||||
|
||||
This is useful when booting outside of a cloud environment (e.g. manually via
|
||||
kvm) and for testing.
|
11
elements/root-passwd/post-install.d/99-setup
Executable file
11
elements/root-passwd/post-install.d/99-setup
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
if [ -z "$DIB_PASSWORD" ]; then
|
||||
echo "Error during setup password for root"
|
||||
exit 1
|
||||
fi
|
||||
sed -i "s/disable_root: true/disable_root: false/" /etc/cloud/cloud.cfg
|
||||
install-packages augeas-tools openssh-server openssh-client
|
||||
augtool -s set /files/etc/ssh/sshd_config/PasswordAuthentication yes
|
||||
augtool -s set /files/etc/ssh/sshd_config/PermitRootLogin yes
|
||||
augtool -s set /files/etc/ssh/ssh_config/PasswordAuthentication yes
|
||||
echo -e "$DIB_PASSWORD\n$DIB_PASSWORD\n" | passwd
|
@ -60,17 +60,23 @@ Command syntax:
|
||||
[-a i386 | **amd64** | armhf ]
|
||||
[-b **haproxy** ]
|
||||
[-c **~/.cache/image-create** | <cache directory> ]
|
||||
[-h]
|
||||
[-i **ubuntu** | fedora | centos ]
|
||||
[-o **amphora-x64-haproxy** | <filename> ]
|
||||
[-t **qcow2** | tar ]
|
||||
[-r <root password> ]
|
||||
[-s **5** | <size in GB> ]
|
||||
[-t **qcow2** | tar ]
|
||||
[-w <working directory> ]
|
||||
'-a' is the architecture type for the image (default: amd64)
|
||||
'-b' is the backend type (default: haproxy)
|
||||
'-c' is the path to the cache directory (default: ~/.cache/image-create)
|
||||
'-h' display help message
|
||||
'-i' is the base OS (default: ubuntu)
|
||||
'-o' is the output image file name
|
||||
'-t' is the image type (default: qcow2)
|
||||
'-r' enable the root account in the generated image (default: disabled)
|
||||
'-s' is the image size to produce in gigabytes (default: 5)
|
||||
'-t' is the image type (default: qcow2)
|
||||
'-w' working directory for image building (default: .)
|
||||
|
||||
|
||||
.. line-block::
|
||||
@ -78,6 +84,7 @@ Command syntax:
|
||||
Environment variables supported by the script:
|
||||
BASE_OS_MIRROR - URL to a mirror for the base OS selected (-i).
|
||||
DIB_REPO_PATH - Path to the diskimage-builder repository (default: ../../diskimage-builder)
|
||||
ELEMENTS_REPO_PATH - Path to the /tripleo-image-elements repository (default: ../../tripleo-image-elements)
|
||||
DIB_ELEMENTS - Override the elements used to build the image
|
||||
DIB_LOCAL_ELEMENTS - Elements to add to the build (requires DIB_LOCAL_ELEMENTS_PATH be specified)
|
||||
DIB_LOCAL_ELEMENTS_PATH - Path to the local elements directory
|
||||
|
Loading…
Reference in New Issue
Block a user