Commit d71f59e9 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Clean up code and support pithos-hosted images

 * Drop "custom" image format type. The same functionality is provided
   by network-hosted images.
 * Images with id that starts with "http:", "https:", "ftp:", "ftps:"
   are considered to be network hosted and are downloaded via cURL.
 * Images with id that starts with "pithos:" are considered to be
   pithos-hosted.
 * Support for pithos and network hosted images is disabled by default.
   You may enable it when configuring the project  using
   --enable-pithos-backend and --enable-network-backend respectively.
parent de0cc3e9
......@@ -4,6 +4,18 @@ else
progress_monitor_support=no
endif
if PITHOSIMGSUPPORT
pithos_backend_support=yes
else
pithos_backend_support=no
endif
if NETWORKIMGSUPPORT
network_backend_support=yes
else
network_backend_support=no
endif
osname=$(PACKAGE)
osdir=$(OS_DIR)/$(osname)
defaultdir=$(DEFAULT_DIR)
......@@ -38,7 +50,9 @@ edit = sed \
-e 's|@QEMU_IMG[@]|$(QEMU_IMG)|g' \
-e 's|@INSTALL_MBR[@]|$(INSTALL_MBR)|g' \
-e 's|@PROGRESS_MONITOR[@]|$(PROGRESS_MONITOR)|g' \
-e 's|@progress_monitor_support[@]|$(progress_monitor_support)|g'
-e 's|@progress_monitor_support[@]|$(progress_monitor_support)|g' \
-e 's|@pithos_backend_support[@]|$(pithos_backend_support)|g' \
-e 's|@network_backend_support[@]|$(network_backend_support)|g'
%:%.in Makefile
rm -f $@ $@.tmp
......
......@@ -27,6 +27,8 @@ CURL="curl"
PROGRESS_MONITOR="snf-progress-monitor"
progress_monitor_support="@progress_monitor_support@"
pithos_backend_support="@pithos_backend_support@"
network_backend_support="@network_backend_support@"
CLEANUP=( )
......@@ -181,6 +183,28 @@ create_floppy() {
umount "$target"
}
get_backend_type() {
local id=$1
if [[ "$id" =~ ^pithos: ]]; then
if [ "$pithos_backend_support" = "yes" ]; then
echo "pithos"
else
log_error "Retrieving images from pithos is not supported"
exit 1
fi
elif [[ "$id" =~ ^(http|ftp)s?: ]]; then
if [ "$network_backend_support" = "yes" ]; then
echo "network";
else
log_error "Retrieving images from the network is not supported."
exit 1
fi
else
echo "local";
fi
}
# this one is only to be called by create
ganeti_os_main() {
if [ -z "$OS_API_VERSION" -o "$OS_API_VERSION" = "5" ]; then
......@@ -192,8 +216,9 @@ ganeti_os_main() {
get_api10_arguments
elif [ "$OS_API_VERSION" = "20" ]; then
get_api20_arguments
IMAGE_NAME=$IMG_ID
IMAGE_TYPE=$IMG_FORMAT
IMAGE_NAME="$IMG_ID"
IMAGE_TYPE="$IMG_FORMAT"
BACKEND_TYPE=$(get_backend_type $IMG_ID)
else
log_error "Unknown OS API VERSION $OS_API_VERSION"
exit 1
......@@ -279,7 +304,8 @@ fi
: ${HELPER_CACHE_FILE:="@HELPER_DIR@/cache.tar"}
: ${HELPER_EXTRA_PKGS:="linux-image-amd64,e2fsprogs,ntfs-3g,ntfsprogs,xmlstarlet,python,parted,reglookup,chntpw"}
: ${HELPER_MIRROR:=""}
: ${PITHOS_DB:="sqlite:////@localstatedir@/lib/pithos/backend.db"}
: ${PITHOS_DATA:="@localstatedir@/lib/pithos/"}
SCRIPT_NAME=$(basename $0)
......
......@@ -7,19 +7,36 @@ AC_CONFIG_SRCDIR(configure)
AM_INIT_AUTOMAKE([1.9 foreign tar-ustar -Wall -Wno-portability])
AM_INIT_AUTOMAKE([subdir-objects])
AC_ARG_ENABLE([pithos_backend],
AS_HELP_STRING([--enable-pithos-backend],
[enable support for pithos-hosted images])
)
AS_IF([test "x$enable_pithos_backend" = "xyes"],,
[AC_MSG_NOTICE(pithos backend support not enabled)])
AM_CONDITIONAL(PITHOSIMGSUPPORT, [test "x$enable_pithos_backend" = "xyes"])
AC_ARG_ENABLE([network_backend],
AS_HELP_STRING([--enable-network-backend],
[enable support for network-hosted images
(this depends on cURL)])
)
AS_IF([test "x$enable_network_backend" = "xyes"],,
[AC_MSG_NOTICE(network backend support not enabled)])
AM_CONDITIONAL(NETWORKIMGSUPPORT, [test "x$enable_network_backend" = "xyes"])
# --with-progress-monitor
AC_ARG_WITH([progress-monitor],
[AS_HELP_STRING([--with-progress-monitor=PRGRM_PATH],
[path to progress-monitor program]
[[snf-progress-monitor]])],
[if test "$withval" = "yes" ; then
AC_PATH_PROG(PROGRESS_MONITOR, [snf-progress-monitor], [], [$PATH:/usr/sbin:/sbin])
if test -z "$PROGRESS_MONITOR" ; then
AC_MSG_FAILURE([Could not find snf-progress-monitor.])
fi
else
PROGRESS_MONITOR="$withval"
fi],
AC_PATH_PROG(PROGRESS_MONITOR, [snf-progress-monitor], [], [$PATH:/usr/sbin:/sbin])
if test -z "$PROGRESS_MONITOR" ; then
AC_MSG_FAILURE([Could not find snf-progress-monitor.])
fi
else
PROGRESS_MONITOR="$withval"
fi],
[AC_MSG_NOTICE(progress-monitor support not enabled)]
)
......@@ -117,9 +134,13 @@ if test -z "$TIMELIMIT" ; then
AC_MSG_ERROR([timelimit not found in $PATH:/usr/sbin:/sbin])
fi
AC_PATH_PROG(CURL, [curl], [], [$PATH:/usr/sbin:/sbin])
if test -z "$CURL" ; then
AC_MSG_ERROR([curl not found in $PATH:/usr/sbin:/sbin])
if test "x$enable_network_backend" = "xyes" ; then
AC_PATH_PROG(CURL, [curl], [], [$PATH:/usr/sbin:/sbin])
if test -z "$CURL" ; then
AC_MSG_ERROR([curl is needed for network backend support but was not \
found in $PATH:/usr/sbin:/sbin]
[To disable network backend support ommit --enable-network-backend])
fi
fi
AC_CONFIG_FILES([
......
......@@ -24,19 +24,27 @@ set -o pipefail
ganeti_os_main
if [ "$IMAGE_TYPE" = custom ]; then
image_file=/dev/null
image_size=\
$($CURL -sI "$IMAGE_NAME" | grep ^Content-Length: | cut -d" " -f2)
else
image_file="$IMAGE_DIR/$IMAGE_NAME.$IMAGE_TYPE"
image_size="$(stat -L -c %s "$image_file")"
fi
if [ ! -e "$image_file" ]; then
log_error "Image file \`$image_file' does not exit."
exit 1
fi
case $BACKEND_TYPE in
local)
image_file="$IMAGE_DIR/$(echo "$IMAGE_NAME" | sed 's/^file://').$IMAGE_TYPE"
if [ ! -e "$image_file" ]; then
log_error "Image file \`$image_file' does not exit."
exit 1
fi
image_size="$(stat -L -c %s "$image_file")"
;;
network)
image_cmd="$CURL $(printf "%q" "$IMAGE_NAME") 2> /dev/null"
image_size=$($CURL -sI "$IMAGE_NAME" | grep ^Content-Length: | cut -d" " -f2)
;;
pithos)
cmd_args= "--db $(printf "%q" "${PITHOS_DB}") \
--data $(printf "%q" "${PITHOS_DATA}") \
$(printf "%q" "${IMAGE_NAME}")"
image_cmd="./pithcat $cmd_args"
image_size=$(./pithcat -s $cmd_args)
;;
esac
monitor="" #Empty if progress monitor support is disabled
if [ "$progress_monitor_support" = "yes" ]; then
......@@ -69,20 +77,19 @@ case "$IMAGE_TYPE" in
snf_export_PROPERTY_OSFAMILY="linux"
fi
;;
diskdump|custom)
diskdump)
target="$blockdev"
;;
esac
if [ "$IMAGE_TYPE" = "custom" ]; then
"$CURL" "$IMAGE_NAME" 2>/dev/null |\
$monitor dd bs=4M of="$target" oflag=direct
else
if [ "$BACKEND_TYPE" = "local" ]; then
# dd the dump to its new home :-)
# Deploying an image file on a target block device is a streaming copy
# operation. Enable the direct I/O flag on the output fd to avoid polluting
# the host cache with useless data.
$monitor dd bs=4M if="$image_file" of="$target" oflag=direct
else
$image_cmd | $monitor dd bs=4M of="$target" oflag=direct
fi
# Create a floppy image
......
......@@ -54,6 +54,12 @@
# define a mirror. Debootstrap will use it's default debian URL.
# HELPER_MIRROR="http://ftp.debian.org/debian"
# PITHOS_DB: Pithos database in SQLAlchemy format
# PITHOS_DB="sqlite:////var/lib/pithos/backend.db"
# PITHOS_DATA: Directory where pithos data are hosted
# PITHOS_DATA="/var/lib/pithos/"
# Paths for needed programs. Uncommend and change the variables below, if you
# don't want to use the default one.
# LOSETUP="losetup"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment