Merge branch 'pithos-backend'
authorNikos Skalkotos <skalkoto@grnet.gr>
Mon, 12 Dec 2011 14:05:38 +0000 (16:05 +0200)
committerNikos Skalkotos <skalkoto@grnet.gr>
Mon, 12 Dec 2011 14:05:38 +0000 (16:05 +0200)
snf-image-host/Makefile.am
snf-image-host/common.sh.in
snf-image-host/configure.ac
snf-image-host/create
snf-image-host/defaults

index 80349ae..623e2ee 100644 (file)
@@ -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
index f581c97..089a195 100644 (file)
@@ -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)
 
index e4fa0f0..c2d2eda 100644 (file)
@@ -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([
index 9c063ac..b4b9c01 100755 (executable)
@@ -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
index 9e6c838..aa53a1e 100644 (file)
 # 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"