8cd2097190
Move to the 22.04 LTS release. Also stop installing python2, since its EOL. Depends-On: Idd3e6a6fdb8cf13727cd674c76efd89b3aacfc52 Change-Id: I9b4c134ecc9279487e253fa3bc38ae32fe487ac6 Signed-off-by: Goutham Pacha Ravi <gouthampravi@gmail.com>
269 lines
7.9 KiB
Bash
Executable File
269 lines
7.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -eu
|
|
set -o pipefail
|
|
|
|
# Collect configuration
|
|
# ---------------------
|
|
|
|
# Development options
|
|
DIB_UPDATE_REQUESTED=${DIB_UPDATE_REQUESTED:-true}
|
|
USE_OFFLINE_MODE=${USE_OFFLINE_MODE:-"yes"}
|
|
ENABLE_DEBUG_MODE=${ENABLE_DEBUG_MODE:-"no"}
|
|
DISABLE_IMG_COMPRESSION=${DISABLE_IMG_COMPRESSION:-"no"}
|
|
|
|
# Manila user settings
|
|
MANILA_USER=${MANILA_USER:-"manila"}
|
|
MANILA_PASSWORD=${MANILA_PASSWORD-"manila"}
|
|
MANILA_USER_AUTHORIZED_KEYS=${MANILA_USER_AUTHORIZED_KEYS:-"None"}
|
|
|
|
# Manila image settings
|
|
MANILA_IMG_ARCH=${MANILA_IMG_ARCH:-"amd64"}
|
|
MANILA_IMG_OS=${MANILA_IMG_OS:-"manila-ubuntu-minimal"}
|
|
MANILA_IMG_OS_VER=${MANILA_IMG_OS_VER:-"jammy"}
|
|
MANILA_IMG_NAME=${MANILA_IMG_NAME:-"manila-service-image"}
|
|
|
|
# Manila image creation default
|
|
MANILA_SHARE_PROTO=${MANILA_SHARE_PROTO:-"default"}
|
|
MANILA_DISTRO=${MANILA_DISTRO:-"ubuntu"}
|
|
|
|
#Misc settings
|
|
DHCP_TIMEOUT=${DHCP_TIMEOUT:-"300"}
|
|
|
|
# Path to elements
|
|
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
|
|
export DIB_DHCP_TIMEOUT=$DHCP_TIMEOUT
|
|
|
|
# CLI
|
|
# ---
|
|
err() {
|
|
echo -e "${0##*/}: $@" >&2
|
|
}
|
|
|
|
print_usage() {
|
|
echo "Usage: ${0##*/} [-s share-proto] [-d distro] [-h]"
|
|
echo "Options:"
|
|
echo " -s | --share-proto: name of the share protocol. \
|
|
Possible options are nfs, nfs-ganesha, cephfs, cifs or zfs"
|
|
echo " -d | --distro: name of the Linux distro. \
|
|
Possible options are ubuntu or centos"
|
|
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}" != "nfs-ganesha" ] &&
|
|
[ "${MANILA_SHARE_PROTO}" != "cifs" ] && [ "${MANILA_SHARE_PROTO}" != "zfs" ] &&
|
|
[ "${MANILA_SHARE_PROTO}" != "cephfs" ]; then
|
|
err "Protocol ${MANILA_SHARE_PROTO} not supported. Valid options are nfs, nfs-ganesha, cephfs, cifs or zfs."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
valid_distro() {
|
|
if ["${MANILA_DISTRO}" != "ubuntu" ] && [ "${MANILA_DISTRO}" != "centos" ]; then
|
|
err "Distro ${MANILA_DISTRO} not supported. Valid options are ubuntu or centos."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
parse_arguments() {
|
|
while [[ $# > 0 ]]; do
|
|
case "$1" in
|
|
-s|--share)
|
|
export MANILA_SHARE_PROTO=$2
|
|
valid_share_protocol
|
|
shift 2
|
|
;;
|
|
-d|--distro)
|
|
export MANILA_DISTRO=$2
|
|
export MANILA_IMG_OS=manila-$2-minimal
|
|
valid_distro
|
|
shift 2
|
|
;;
|
|
-h|--help)
|
|
print_usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
err "Error: Unknown option: $1."
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
# Verify configuration
|
|
# --------------------
|
|
configure() {
|
|
REQUIRED_ELEMENTS="manila-ssh vm $MANILA_IMG_OS dhcp-all-interfaces"
|
|
IMAGE_FORMAT="qcow2"
|
|
OPTIONAL_ELEMENTS=
|
|
OPTIONAL_DIB_ARGS=
|
|
|
|
if [ "$MANILA_SHARE_PROTO" = "default" ]; then
|
|
# NOTE(vkmc) Generic driver uses 2 protocols by default
|
|
# NFS and CIFS. This is required by the gate.
|
|
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS ${MANILA_DISTRO}-nfs ${MANILA_DISTRO}-cifs"
|
|
elif [ "$MANILA_SHARE_PROTO" = "nfs" ]; then
|
|
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS ${MANILA_DISTRO}-nfs"
|
|
elif [ "$MANILA_SHARE_PROTO" = "nfs-ganesha" ]; then
|
|
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS ${MANILA_DISTRO}-nfs-ganesha"
|
|
elif [ "$MANILA_SHARE_PROTO" = "cifs" ]; then
|
|
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS ${MANILA_DISTRO}-cifs"
|
|
elif [ "$MANILA_SHARE_PROTO" = "zfs" ]; then
|
|
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS ${MANILA_DISTRO}-zfs"
|
|
elif [ "$MANILA_SHARE_PROTO" = "cephfs" ]; then
|
|
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS cephfs"
|
|
fi
|
|
|
|
if [ "$USE_OFFLINE_MODE" = "yes" ]; then
|
|
OPTIONAL_DIB_ARGS="$OPTIONAL_DIB_ARGS -offline"
|
|
fi
|
|
|
|
if [ "$ENABLE_DEBUG_MODE" = "yes" ]; then
|
|
OPTIONAL_DIB_ARGS="$OPTIONAL_DIB_ARGS -x"
|
|
MANILA_USER_AUTHORIZED_KEYS=${MANILA_USER_AUTHORIZED_KEYS:-"$HOME/.ssh/id_rsa.pub"}
|
|
fi
|
|
|
|
if [ "$DISABLE_IMG_COMPRESSION" = "yes" ]; then
|
|
OPTIONAL_DIB_ARGS="$OPTIONAL_DIB_ARGS -u"
|
|
fi
|
|
}
|
|
|
|
# Verify dependencies
|
|
# -------------------
|
|
|
|
is_installed() {
|
|
if [ "$platform" = 'ubuntu' ]; then
|
|
dpkg -s "$1" &> /dev/null
|
|
else
|
|
# centos, fedora, opensuse, or rhel
|
|
if ! rpm -q "$1" &> /dev/null; then
|
|
rpm -q "$(rpm -q --whatprovides "$1")"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
need_required_packages() {
|
|
case "$platform" in
|
|
"ubuntu")
|
|
package_list="qemu kpartx debootstrap"
|
|
;;
|
|
"fedora")
|
|
package_list="qemu-img kpartx debootstrap"
|
|
;;
|
|
"opensuse")
|
|
package_list="qemu kpartx debootstrap"
|
|
;;
|
|
"rhel" | "centos")
|
|
package_list="qemu-kvm qemu-img kpartx debootstrap"
|
|
;;
|
|
*)
|
|
err "Unknown platform '$platform' for the package list.\nAborting"
|
|
exit 2
|
|
;;
|
|
esac
|
|
|
|
for p in `echo $package_list`; do
|
|
if ! is_installed $p; then
|
|
return 0
|
|
fi
|
|
done
|
|
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
|
|
# install required packages if requested
|
|
if [ -n "$DIB_UPDATE_REQUESTED" ]; then
|
|
case "$platform" in
|
|
"ubuntu")
|
|
sudo apt-get update
|
|
sudo apt-get install $package_list -y
|
|
;;
|
|
"opensuse")
|
|
sudo zypper --non-interactive --gpg-auto-import-keys in $package_list
|
|
;;
|
|
"fedora" | "rhel" | "centos")
|
|
if [ ${platform} = "fedora" ]; then
|
|
sudo dnf install $package_list -y
|
|
else
|
|
sudo yum install $package_list -y
|
|
fi
|
|
;;
|
|
*)
|
|
err "Unknown platform '$platform' for installing packages.\nAborting"
|
|
exit 2
|
|
;;
|
|
esac
|
|
else
|
|
err "Missing one of the following packages: $package_list"
|
|
err "Please install manually or rerun with the update option (-u)."
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Build image
|
|
# -----------
|
|
build_image() {
|
|
disk-image-create \
|
|
-t $IMAGE_FORMAT \
|
|
-a $MANILA_IMG_ARCH \
|
|
$OPTIONAL_DIB_ARGS \
|
|
-o $MANILA_IMG_NAME \
|
|
$OPTIONAL_ELEMENTS $REQUIRED_ELEMENTS
|
|
}
|
|
|
|
main() {
|
|
parse_arguments "$@"
|
|
configure
|
|
verify_dependencies
|
|
build_image
|
|
exit 0
|
|
}
|
|
|
|
main "$@"
|