Revision d71f59e9

b/snf-image-host/Makefile.am
4 4
progress_monitor_support=no
5 5
endif
6 6

  
7
if PITHOSIMGSUPPORT
8
pithos_backend_support=yes
9
else
10
pithos_backend_support=no
11
endif
12

  
13
if NETWORKIMGSUPPORT
14
network_backend_support=yes
15
else
16
network_backend_support=no
17
endif
18

  
7 19
osname=$(PACKAGE)
8 20
osdir=$(OS_DIR)/$(osname)
9 21
defaultdir=$(DEFAULT_DIR)
......
38 50
	   -e 's|@QEMU_IMG[@]|$(QEMU_IMG)|g' \
39 51
	   -e 's|@INSTALL_MBR[@]|$(INSTALL_MBR)|g' \
40 52
	   -e 's|@PROGRESS_MONITOR[@]|$(PROGRESS_MONITOR)|g' \
41
	   -e 's|@progress_monitor_support[@]|$(progress_monitor_support)|g'
53
	   -e 's|@progress_monitor_support[@]|$(progress_monitor_support)|g' \
54
	   -e 's|@pithos_backend_support[@]|$(pithos_backend_support)|g' \
55
	   -e 's|@network_backend_support[@]|$(network_backend_support)|g'
42 56

  
43 57
%:%.in Makefile
44 58
	rm -f $@ $@.tmp
b/snf-image-host/common.sh.in
27 27
PROGRESS_MONITOR="snf-progress-monitor"
28 28

  
29 29
progress_monitor_support="@progress_monitor_support@"
30
pithos_backend_support="@pithos_backend_support@"
31
network_backend_support="@network_backend_support@"
30 32

  
31 33
CLEANUP=( )
32 34

  
......
181 183
    umount "$target"
182 184
}
183 185

  
186
get_backend_type() {
187
    local id=$1
188

  
189
    if [[ "$id" =~ ^pithos: ]]; then
190
        if [ "$pithos_backend_support" = "yes" ]; then
191
            echo "pithos"
192
        else
193
            log_error "Retrieving images from pithos is not supported"
194
            exit 1
195
        fi
196
    elif [[ "$id" =~ ^(http|ftp)s?: ]]; then
197
        if [ "$network_backend_support" = "yes" ]; then
198
            echo "network";
199
        else
200
            log_error "Retrieving images from the network is not supported."
201
            exit 1
202
        fi
203
    else
204
        echo "local";
205
    fi
206
}
207

  
184 208
# this one is only to be called by create
185 209
ganeti_os_main() {
186 210
    if [ -z "$OS_API_VERSION" -o "$OS_API_VERSION" = "5" ]; then
......
192 216
        get_api10_arguments
193 217
    elif [ "$OS_API_VERSION" = "20" ]; then
194 218
        get_api20_arguments
195
        IMAGE_NAME=$IMG_ID
196
        IMAGE_TYPE=$IMG_FORMAT
219
        IMAGE_NAME="$IMG_ID"
220
        IMAGE_TYPE="$IMG_FORMAT"
221
        BACKEND_TYPE=$(get_backend_type $IMG_ID)
197 222
    else
198 223
        log_error "Unknown OS API VERSION $OS_API_VERSION"
199 224
        exit 1
......
279 304
: ${HELPER_CACHE_FILE:="@HELPER_DIR@/cache.tar"}
280 305
: ${HELPER_EXTRA_PKGS:="linux-image-amd64,e2fsprogs,ntfs-3g,ntfsprogs,xmlstarlet,python,parted,reglookup,chntpw"}
281 306
: ${HELPER_MIRROR:=""}
282

  
307
: ${PITHOS_DB:="sqlite:////@localstatedir@/lib/pithos/backend.db"}
308
: ${PITHOS_DATA:="@localstatedir@/lib/pithos/"}
283 309

  
284 310
SCRIPT_NAME=$(basename $0)
285 311

  
b/snf-image-host/configure.ac
7 7
AM_INIT_AUTOMAKE([1.9 foreign tar-ustar -Wall -Wno-portability])
8 8
AM_INIT_AUTOMAKE([subdir-objects])
9 9

  
10
AC_ARG_ENABLE([pithos_backend],
11
   AS_HELP_STRING([--enable-pithos-backend],
12
    [enable support for pithos-hosted images])
13
)
14
AS_IF([test "x$enable_pithos_backend" = "xyes"],,
15
    [AC_MSG_NOTICE(pithos backend support not enabled)])
16
AM_CONDITIONAL(PITHOSIMGSUPPORT, [test "x$enable_pithos_backend" = "xyes"])
17

  
18
AC_ARG_ENABLE([network_backend],
19
   AS_HELP_STRING([--enable-network-backend],
20
    [enable support for network-hosted images
21
    (this depends on cURL)])
22
)
23
AS_IF([test "x$enable_network_backend" = "xyes"],,
24
    [AC_MSG_NOTICE(network backend support not enabled)])
25
AM_CONDITIONAL(NETWORKIMGSUPPORT, [test "x$enable_network_backend" = "xyes"])
26

  
10 27
# --with-progress-monitor
11 28
AC_ARG_WITH([progress-monitor],
12 29
  [AS_HELP_STRING([--with-progress-monitor=PRGRM_PATH],
13 30
    [path to progress-monitor program]
14 31
    [[snf-progress-monitor]])],
15 32
    [if test "$withval" = "yes" ; then
16
    AC_PATH_PROG(PROGRESS_MONITOR, [snf-progress-monitor], [], [$PATH:/usr/sbin:/sbin])
17
    if test -z "$PROGRESS_MONITOR" ; then
18
        AC_MSG_FAILURE([Could not find snf-progress-monitor.])
19
    fi
20
   else
21
       PROGRESS_MONITOR="$withval"
22
   fi],
33
         AC_PATH_PROG(PROGRESS_MONITOR, [snf-progress-monitor], [], [$PATH:/usr/sbin:/sbin])
34
         if test -z "$PROGRESS_MONITOR" ; then
35
             AC_MSG_FAILURE([Could not find snf-progress-monitor.])
36
         fi
37
     else
38
         PROGRESS_MONITOR="$withval"
39
    fi],
23 40
   [AC_MSG_NOTICE(progress-monitor support not enabled)]
24 41
)
25 42

  
......
117 134
  AC_MSG_ERROR([timelimit not found in $PATH:/usr/sbin:/sbin])
118 135
fi
119 136

  
120
AC_PATH_PROG(CURL, [curl], [], [$PATH:/usr/sbin:/sbin])
121
if test -z "$CURL" ; then
122
  AC_MSG_ERROR([curl not found in $PATH:/usr/sbin:/sbin])
137
if test "x$enable_network_backend" = "xyes" ; then
138
  AC_PATH_PROG(CURL, [curl], [], [$PATH:/usr/sbin:/sbin])
139
    if test -z "$CURL" ; then
140
      AC_MSG_ERROR([curl is needed for network backend support but was not \
141
      found in $PATH:/usr/sbin:/sbin]
142
      [To disable network backend support ommit --enable-network-backend])
143
    fi
123 144
fi
124 145

  
125 146
AC_CONFIG_FILES([
b/snf-image-host/create
24 24

  
25 25
ganeti_os_main
26 26

  
27
if [ "$IMAGE_TYPE" = custom ]; then
28
    image_file=/dev/null
29
    image_size=\
30
        $($CURL -sI "$IMAGE_NAME" | grep ^Content-Length: | cut -d" " -f2)
31
else
32
    image_file="$IMAGE_DIR/$IMAGE_NAME.$IMAGE_TYPE"
33
    image_size="$(stat -L -c %s "$image_file")"
34
fi
35

  
36
if [ ! -e "$image_file" ]; then
37
    log_error "Image file \`$image_file' does not exit."
38
    exit 1
39
fi
27
case $BACKEND_TYPE in
28
    local)
29
        image_file="$IMAGE_DIR/$(echo "$IMAGE_NAME" | sed 's/^file://').$IMAGE_TYPE"
30
        if [ ! -e "$image_file" ]; then
31
            log_error "Image file \`$image_file' does not exit."
32
            exit 1
33
        fi
34
        image_size="$(stat -L -c %s "$image_file")"
35
        ;;
36
    network)
37
        image_cmd="$CURL $(printf "%q" "$IMAGE_NAME") 2> /dev/null"
38
        image_size=$($CURL -sI "$IMAGE_NAME" | grep ^Content-Length: | cut -d" " -f2)
39
        ;;
40
    pithos)
41
        cmd_args= "--db $(printf "%q" "${PITHOS_DB}") \
42
                   --data $(printf "%q" "${PITHOS_DATA}") \
43
                        $(printf "%q" "${IMAGE_NAME}")"
44
        image_cmd="./pithcat $cmd_args"
45
        image_size=$(./pithcat -s  $cmd_args)
46
        ;;
47
esac
40 48

  
41 49
monitor="" #Empty if progress monitor support is disabled
42 50
if [ "$progress_monitor_support" = "yes" ]; then
......
69 77
            snf_export_PROPERTY_OSFAMILY="linux"
70 78
        fi
71 79
        ;;
72
    diskdump|custom)
80
    diskdump)
73 81
        target="$blockdev"
74 82
        ;;
75 83
esac
76 84

  
77
if [ "$IMAGE_TYPE" = "custom" ]; then
78
    "$CURL" "$IMAGE_NAME" 2>/dev/null |\
79
        $monitor dd bs=4M of="$target" oflag=direct
80
else
85
if [ "$BACKEND_TYPE" = "local" ]; then
81 86
    # dd the dump to its new home :-)
82 87
    # Deploying an image file on a target block device is a streaming copy
83 88
    # operation. Enable the direct I/O flag on the output fd to avoid polluting
84 89
    # the host cache with useless data.
85 90
    $monitor dd bs=4M if="$image_file" of="$target" oflag=direct
91
else
92
    $image_cmd | $monitor dd bs=4M of="$target" oflag=direct
86 93
fi
87 94

  
88 95
# Create a floppy image
b/snf-image-host/defaults
54 54
# define a mirror. Debootstrap will use it's default debian URL.
55 55
# HELPER_MIRROR="http://ftp.debian.org/debian"
56 56

  
57
# PITHOS_DB: Pithos database in SQLAlchemy format
58
# PITHOS_DB="sqlite:////var/lib/pithos/backend.db"
59

  
60
# PITHOS_DATA: Directory where pithos data are hosted
61
# PITHOS_DATA="/var/lib/pithos/"
62

  
57 63
# Paths for needed programs. Uncommend and change the variables below, if you
58 64
# don't want to use the default one.
59 65
# LOSETUP="losetup"

Also available in: Unified diff