Merge "Enables end user to pick share protocol"
This commit is contained in:
39
README.rst
39
README.rst
@@ -7,8 +7,9 @@ Team and repository tags
|
|||||||
|
|
||||||
.. Change things from this point on
|
.. Change things from this point on
|
||||||
|
|
||||||
Manila image elements project
|
=============================
|
||||||
==============================
|
Manila Image Elements Project
|
||||||
|
=============================
|
||||||
|
|
||||||
This repo is a place for Manila-related diskimage-builder elements.
|
This repo is a place for Manila-related diskimage-builder elements.
|
||||||
|
|
||||||
@@ -19,14 +20,40 @@ This repo is a place for Manila-related diskimage-builder elements.
|
|||||||
|
|
||||||
|
|
||||||
Build instructions
|
Build instructions
|
||||||
------------------
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Before building the image, make sure all system dependencies
|
||||||
|
listed in bindep.txt file, are installed.
|
||||||
|
|
||||||
|
Default generic using tox
|
||||||
|
-------------------------
|
||||||
|
|
||||||
Script for creating Ubuntu based image with our elements and default parameters.
|
Script for creating Ubuntu based image with our elements and default parameters.
|
||||||
|
|
||||||
Before building image make sure all system dependencies,
|
You should only need to run this command:
|
||||||
listed in other-requirements.txt file, are installed.
|
|
||||||
After it, you should only need to run this command:
|
|
||||||
|
|
||||||
.. sourcecode:: bash
|
.. sourcecode:: bash
|
||||||
|
|
||||||
tox -e buildimage
|
tox -e buildimage
|
||||||
|
|
||||||
|
On completion, an Ubuntu minimal image with NFS will be available for use.
|
||||||
|
|
||||||
|
Non-default image using tox
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
A finer-grained image creation control can be obtained by specifying extra parameters.
|
||||||
|
Precisely, the syntax is as follows:
|
||||||
|
|
||||||
|
.. sourcecode:: bash
|
||||||
|
|
||||||
|
tox -e buildimage -- -s nfs
|
||||||
|
|
||||||
|
Where <share-protocol> can be nfs, cifs or zfs.
|
||||||
|
|
||||||
|
For example, running:
|
||||||
|
|
||||||
|
.. sourcecode:: bash
|
||||||
|
|
||||||
|
tox -e buildimage -- -s cifs
|
||||||
|
|
||||||
|
Will generate an Ubuntu based image with CIFS.
|
||||||
|
|||||||
176
bin/manila-image-create
Normal file → Executable file
176
bin/manila-image-create
Normal file → Executable file
@@ -3,19 +3,10 @@
|
|||||||
set -eu
|
set -eu
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
SCRIPT_HOME=$(dirname $(readlink -f $0))
|
|
||||||
if [ -d $SCRIPT_HOME/../share/manila-elements ]; then
|
|
||||||
_PREFIX=$SCRIPT_HOME/../share/manila-elements
|
|
||||||
elif [ -d $SCRIPT_HOME/../../../elements ]; then
|
|
||||||
_PREFIX=$SCRIPT_HOME/../../..
|
|
||||||
else
|
|
||||||
_PREFIX=$SCRIPT_HOME/..
|
|
||||||
fi
|
|
||||||
export ELEMENTS_PATH=$_PREFIX/elements
|
|
||||||
|
|
||||||
# Collect configuration
|
# Collect configuration
|
||||||
# --------------------
|
# ---------------------
|
||||||
# Development options:
|
|
||||||
|
# Development options
|
||||||
DIB_UPDATE_REQUESTED=${DIB_UPDATE_REQUESTED:-true}
|
DIB_UPDATE_REQUESTED=${DIB_UPDATE_REQUESTED:-true}
|
||||||
USE_OFFLINE_MODE=${USE_OFFLINE_MODE:-"yes"}
|
USE_OFFLINE_MODE=${USE_OFFLINE_MODE:-"yes"}
|
||||||
ENABLE_DEBUG_MODE=${ENABLE_DEBUG_MODE:-"no"}
|
ENABLE_DEBUG_MODE=${ENABLE_DEBUG_MODE:-"no"}
|
||||||
@@ -32,12 +23,71 @@ MANILA_IMG_OS=${MANILA_IMG_OS:-"manila-ubuntu-minimal"}
|
|||||||
MANILA_IMG_OS_VER=${MANILA_IMG_OS_VER:-"trusty"}
|
MANILA_IMG_OS_VER=${MANILA_IMG_OS_VER:-"trusty"}
|
||||||
MANILA_IMG_NAME=${MANILA_IMG_NAME:-"manila-service-image"}
|
MANILA_IMG_NAME=${MANILA_IMG_NAME:-"manila-service-image"}
|
||||||
|
|
||||||
# Manila features
|
# Manila image creation default
|
||||||
MANILA_ENABLE_NFS_SUPPORT=${MANILA_ENABLE_NFS_SUPPORT:-"yes"}
|
MANILA_SHARE_PROTO=${MANILA_SHARE_PROTO:-"nfs"}
|
||||||
MANILA_ENABLE_CIFS_SUPPORT=${MANILA_ENABLE_CIFS_SUPPORT:-"yes"}
|
|
||||||
|
|
||||||
# Manila Generic share driver replication feature requires ZFS:
|
# Path to elements
|
||||||
MANILA_ENABLE_ZFS_SUPPORT=${MANILA_ENABLE_ZFS_SUPPORT:-"no"}
|
SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
if [ -d $SCRIPT_HOME/../share/manila-elements ]; then
|
||||||
|
_PREFIX=$SCRIPT_HOME/../share/manila-elements
|
||||||
|
elif [ -d $SCRIPT_HOME/../../../elements ]; then
|
||||||
|
_PREFIX=$SCRIPT_HOME/../../..
|
||||||
|
else
|
||||||
|
_PREFIX=$SCRIPT_HOME/..
|
||||||
|
fi
|
||||||
|
export ELEMENTS_PATH=$_PREFIX/elements
|
||||||
|
|
||||||
|
# diskimage-builder general settings
|
||||||
|
export DIB_DEFAULT_INSTALLTYPE=package
|
||||||
|
export DIB_RELEASE=$MANILA_IMG_OS_VER
|
||||||
|
|
||||||
|
# diskimage-builder user settings
|
||||||
|
export DIB_MANILA_USER_USERNAME=$MANILA_USER
|
||||||
|
export DIB_MANILA_USER_PASSWORD=$MANILA_PASSWORD
|
||||||
|
export DIB_MANILA_USER_AUTHORIZED_KEYS=$MANILA_USER_AUTHORIZED_KEYS
|
||||||
|
|
||||||
|
# CLI
|
||||||
|
# ---
|
||||||
|
err() {
|
||||||
|
echo -e "${0##*/}: $@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
print_usage() {
|
||||||
|
echo "Usage: ${0##*/} [-s share-proto] [-h]"
|
||||||
|
echo "Options:"
|
||||||
|
echo " -s | --share-proto: name of the share protocol. Possible options are nfs, cifs or zfs"
|
||||||
|
echo " -h | --help: print this usage message and exit"
|
||||||
|
echo ""
|
||||||
|
echo "Usage example: manila_image_elements -s nfs"
|
||||||
|
}
|
||||||
|
|
||||||
|
valid_share_protocol(){
|
||||||
|
if [ "${MANILA_SHARE_PROTO}" != "nfs" ] && [ "${MANILA_SHARE_PROTO}" != "cifs" ] && [ "${MANILA_SHARE_PROTO}" != "zfs" ]; then
|
||||||
|
err "Protocol ${MANILA_SHARE_PROTO} not supported. Valid options are nfs, cifs or zfs."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
parse_arguments() {
|
||||||
|
while [[ $# > 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-s|--share)
|
||||||
|
export MANILA_SHARE_PROTO=$2
|
||||||
|
valid_share_protocol
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
print_usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
err "Error: Unknown option: $1."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Verify configuration
|
# Verify configuration
|
||||||
# --------------------
|
# --------------------
|
||||||
@@ -46,19 +96,15 @@ IMAGE_FORMAT="qcow2"
|
|||||||
OPTIONAL_ELEMENTS=
|
OPTIONAL_ELEMENTS=
|
||||||
OPTIONAL_DIB_ARGS=
|
OPTIONAL_DIB_ARGS=
|
||||||
|
|
||||||
if [ "$MANILA_ENABLE_CIFS_SUPPORT" != "yes" ] && [ "$MANILA_ENABLE_NFS_SUPPORT" != "yes" ]; then
|
configure() {
|
||||||
echo "You should enable NFS or CIFS support for manila image."
|
OPTIONAL_ELEMENTS=
|
||||||
fi
|
OPTIONAL_DIB_ARGS=
|
||||||
|
|
||||||
if [ "$MANILA_ENABLE_NFS_SUPPORT" = "yes" ]; then
|
if [ "$MANILA_SHARE_PROTO" = "nfs" ]; then
|
||||||
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS manila-nfs"
|
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS manila-nfs"
|
||||||
fi
|
elif [ "$MANILA_SHARE_PROTO" = "cifs" ]; then
|
||||||
|
|
||||||
if [ "$MANILA_ENABLE_CIFS_SUPPORT" = "yes" ]; then
|
|
||||||
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS manila-cifs"
|
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS manila-cifs"
|
||||||
fi
|
elif [ "$MANILA_SHARE_PROTO" = "zfs" ]; then
|
||||||
|
|
||||||
if [ "$MANILA_ENABLE_ZFS_SUPPORT" = "yes" ]; then
|
|
||||||
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS manila-zfs"
|
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS manila-zfs"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -74,30 +120,10 @@ fi
|
|||||||
if [ "$DISABLE_IMG_COMPRESSION" = "yes" ]; then
|
if [ "$DISABLE_IMG_COMPRESSION" = "yes" ]; then
|
||||||
OPTIONAL_DIB_ARGS="$OPTIONAL_DIB_ARGS -u"
|
OPTIONAL_DIB_ARGS="$OPTIONAL_DIB_ARGS -u"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Verify dependencies
|
# Verify dependencies
|
||||||
# -------------------
|
# -------------------
|
||||||
if [ -e /etc/os-release ]; then
|
|
||||||
platform=$(cat /etc/os-release | awk -F= '/^ID=/ {print tolower($2);}')
|
|
||||||
# remove eventual quotes around ID=...
|
|
||||||
platform=$(echo $platform | sed -e 's,^",,;s,"$,,')
|
|
||||||
elif [ -e /etc/system-release ]; then
|
|
||||||
case "$(head -1 /etc/system-release)" in
|
|
||||||
"Red Hat Enterprise Linux Server"*)
|
|
||||||
platform=rhel
|
|
||||||
;;
|
|
||||||
"CentOS"*)
|
|
||||||
platform=centos
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo -e "Unknown value in /etc/system-release. Impossible to build images.\nAborting"
|
|
||||||
exit 2
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
else
|
|
||||||
echo -e "Unknown host OS. Impossible to build images.\nAborting"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
is_installed() {
|
is_installed() {
|
||||||
if [ "$platform" = 'ubuntu' ]; then
|
if [ "$platform" = 'ubuntu' ]; then
|
||||||
@@ -125,7 +151,7 @@ need_required_packages() {
|
|||||||
package_list="qemu-kvm qemu-img kpartx"
|
package_list="qemu-kvm qemu-img kpartx"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo -e "Unknown platform '$platform' for the package list.\nAborting"
|
err "Unknown platform '$platform' for the package list.\nAborting"
|
||||||
exit 2
|
exit 2
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -138,6 +164,29 @@ need_required_packages() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
verify_dependencies() {
|
||||||
|
if [ -e /etc/os-release ]; then
|
||||||
|
platform=$(cat /etc/os-release | awk -F= '/^ID=/ {print tolower($2);}')
|
||||||
|
# remove eventual quotes around ID=...
|
||||||
|
platform=$(echo $platform | sed -e 's,^",,;s,"$,,')
|
||||||
|
elif [ -e /etc/system-release ]; then
|
||||||
|
case "$(head -1 /etc/system-release)" in
|
||||||
|
"Red Hat Enterprise Linux Server"*)
|
||||||
|
platform=rhel
|
||||||
|
;;
|
||||||
|
"CentOS"*)
|
||||||
|
platform=centos
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
err "Unknown value in /etc/system-release. Impossible to build images.\nAborting"
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
err "Unknown host OS. Impossible to build images.\nAborting"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
if need_required_packages; then
|
if need_required_packages; then
|
||||||
# install required packages if requested
|
# install required packages if requested
|
||||||
if [ -n "$DIB_UPDATE_REQUESTED" ]; then
|
if [ -n "$DIB_UPDATE_REQUESTED" ]; then
|
||||||
@@ -157,32 +206,35 @@ if need_required_packages; then
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo -e "Unknown platform '$platform' for installing packages.\nAborting"
|
err "Unknown platform '$platform' for installing packages.\nAborting"
|
||||||
exit 2
|
exit 2
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
echo "Missing one of the following packages: $package_list"
|
err "Missing one of the following packages: $package_list"
|
||||||
echo "Please install manually or rerun with the update option (-u)."
|
err "Please install manually or rerun with the update option (-u)."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
# Export diskimage-builder settings
|
|
||||||
# ---------------------------------
|
|
||||||
export DIB_DEFAULT_INSTALLTYPE=package
|
|
||||||
export DIB_RELEASE=$MANILA_IMG_OS_VER
|
|
||||||
|
|
||||||
# User settings
|
|
||||||
export DIB_MANILA_USER_USERNAME=$MANILA_USER
|
|
||||||
export DIB_MANILA_USER_PASSWORD=$MANILA_PASSWORD
|
|
||||||
export DIB_MANILA_USER_AUTHORIZED_KEYS=$MANILA_USER_AUTHORIZED_KEYS
|
|
||||||
|
|
||||||
# Build image
|
# Build image
|
||||||
# -----------
|
# -----------
|
||||||
|
build_image() {
|
||||||
disk-image-create \
|
disk-image-create \
|
||||||
-t $IMAGE_FORMAT \
|
-t $IMAGE_FORMAT \
|
||||||
-a $MANILA_IMG_ARCH \
|
-a $MANILA_IMG_ARCH \
|
||||||
$OPTIONAL_DIB_ARGS \
|
$OPTIONAL_DIB_ARGS \
|
||||||
-o $MANILA_IMG_NAME \
|
-o $MANILA_IMG_NAME \
|
||||||
$OPTIONAL_ELEMENTS $REQUIRED_ELEMENTS
|
$OPTIONAL_ELEMENTS $REQUIRED_ELEMENTS
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
parse_arguments "$@"
|
||||||
|
configure
|
||||||
|
verify_dependencies
|
||||||
|
build_image
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user