SFDISK="sfdisk"
QEMU_IMG="qemu-img"
INSTALL_MBR="install-mbr"
-TIMELIMIT="timelimit"
+TIMEOUT="timeout"
CURL="curl"
+DATE="date -u" # Time in UTC
-network_backend_support="@network_backend_support@"
+# Temporary use stderr as monitoring file descriptor.
+# `create' will overwrite this
+MONITOR_FD="2"
-# Use file descriptors in the range 3-9. File descriptors below 3 are used for
-# standard input, output, and error, the ones above 9 may be used by the shell
-# internally.
-MONITOR_FD=9
+MSG_TYPE_ERROR="image-error"
+MSG_TYPE_INFO="image-info"
CLEANUP=( )
+ERROR_MSGS=( )
add_cleanup() {
local cmd=""
}
log_error() {
- echo "$@" >&2
+ echo "[ERROR] $*" >&2
}
+report_error() {
+ ERROR_MSGS+=("$@")
+}
+
+report_info() {
+ local report
+ echo "[INFO] $*" >&2
+ report="$(./host-monitor.py info <<< "$*")"
+ eval "echo $(printf "%q" "$report") >&${MONITOR_FD}"
+}
+
+
close_fd() {
local fd="$1"
- eval "exec $fd>&-"
+ exec {fd}>&-
+}
+
+send_errors() {
+ local report=""
+ if [ ${#ERROR_MSGS[@]} -gt 0 ]; then
+ local msg=""
+ for err in "${ERROR_MSGS[@]}"; do
+ msg+="$(echo "$err")"
+ done
+ report="$(./host-monitor.py error <<< "$msg")"
+ else
+ report=$(./host-monitor.py error <<< "Internal Error: Image deployment failed.")
+ fi
+
+ eval "echo $(printf "%q" "$report") >&${MONITOR_FD}"
}
get_api5_arguments() {
fi
if [ "$SCRIPT_NAME" = "export" ]; then
if [ -z "$EXPORT_DEVICE" ]; then
- log_error "Missing OS API Variable EXPORT_DEVICE"
- fi
- blockdev=$EXPORT_DEVICE
+ log_error "Missing OS API Variable EXPORT_DEVICE"
+ fi
+ blockdev=$EXPORT_DEVICE
elif [ "$SCRIPT_NAME" = "import" ]; then
if [ -z "$IMPORT_DEVICE" ]; then
log_error "Missing OS API Variable IMPORT_DEVICE"
get_api20_arguments() {
get_api10_arguments
- if [ -z "$OSP_IMG_ID" ]; then
- log_error "Missing OS API Parameter: OSP_IMG_ID"
- exit 1
- fi
- if [ -z "$OSP_IMG_FORMAT" ]; then
- log_error "Missing OS API Parameter: OSP_IMG_FORMAT"
- exit 1
- fi
- if [ -z "$OSP_IMG_PASSWD" ]; then
- log_error "Missing OS API Parameter: OSP_IMG_PASSWD"
- exit 1
- fi
- IMG_ID=$OSP_IMG_ID
- IMG_FORMAT=$OSP_IMG_FORMAT
- IMG_PASSWD=$OSP_IMG_PASSWD
- if [ -n "$OSP_IMG_PROPERTIES" ]; then
- IMG_PROPERTIES="$OSP_IMG_PROPERTIES"
- fi
- if [ -n "$OSP_IMG_PERSONALITY" ]; then
- IMG_PERSONALITY="$OSP_IMG_PERSONALITY"
+ local required_osparams="IMG_ID IMG_FORMAT IMG_PASSWD"
+ local osparams="$required_osparams IMG_PROPERTIES IMG_PERSONALITY CONFIG_URL"
+
+ # Store OSP_VAR in VAR
+ for param in $osparams; do
+ eval $param=\"\$OSP_$param\"
+ done
+
+ if [ -n "$CONFIG_URL" ]; then
+ local config config_params
+ config=$($CURL -f "$CONFIG_URL")
+ config_params=$(./decode-config.py $osparams <<< "$config")
+ eval "$config_params"
fi
+
+ for var in $required_osparams; do
+ if [ -z "${!var}" ]; then
+ log_error "Missing OS API Parameter: ${var}"
+ exit 1
+ fi
+ done
}
map_disk0() {
}
create_floppy() {
- local img=$1
+ local img target
+
+ img=$1
- local target=$(mktemp -d)
+ target=$(mktemp -d)
add_cleanup rmdir "$target"
dd bs=512 count=2880 if=/dev/zero of="$img"
if [[ "$id" =~ ^pithos: ]]; then
echo "pithos"
+ elif [[ "$id" =~ ^pithosmap: ]]; then
+ echo "pithos"
elif [[ "$id" =~ ^(http|ftp)s?: ]]; then
if [ "$network_backend_support" = "yes" ]; then
echo "network";
log_error "Retrieving images from the network is not supported."
exit 1
fi
+ elif [ "$id" = "null" ]; then
+ echo "null"
else
- echo "local";
+ echo "local"
fi
}
}
-do_debootstrap() {
- local target="$1"
+do_multistrap() {
+ local target="$1"
+ local cache="$2"
+ local pkgs="$3"
- echo "Debootstraping to create a new root filesystem:"
+ # Create preferences.d for apt
+ mkdir -p "$target/etc/apt/preferences.d"
+ if [ -d "$MULTISTRAP_APTPREFDIR" ]; then
+ find "$MULTISTRAP_APTPREFDIR" -maxdepth 1 -type f -exec cp {} "$target/etc/apt/preferences.d" \;
+ fi
# Create a policy-rc.d file to deny init script execution
mkdir -p "$target/usr/sbin"
EOF
chmod +x "$target/usr/sbin/policy-rc.d"
- debootstrap --arch $(dpkg --print-architecture) \
- --include "$HELPER_EXTRA_PKGS" --variant=minbase stable "$target" \
- "$HELPER_MIRROR" 2>&1 | sed -e 's/^/DEBOOTSTRAP: /g'
-
- # Save the package list
- chroot "$target" dpkg-query -W -f "\${Package}\n" > "$HELPER_CACHE_PKGS"
+ multistrap -d "$target" -f "$MULTISTRAP_CONFIG" 2>&1 | sed -u -e 's/^/MULTISTRAP: /g'
- rm "$target/usr/sbin/policy-rc.d"
-
- # remove the downloaded debs, as they are no longer needed
- find "$target/var/cache/apt/archives" -type f -name '*.deb' -print0 | \
- xargs -r0 rm -f
+ rm "$target/usr/sbin/policy-rc.d"
+ rm -rf "$target/etc/apt/preferences.d"
+}
- local tmp_cache=$(mktemp "$CACHE_FILE.XXXXXX")
- tar cf "$tmp_cache" --one-file-system -C "$target" . || \
- { rm "$tmp_cache"; false; }
- # Overwrite the default cache file. Not the user specified if present.
- mv -f "$tmp_cache" "$HELPER_CACHE_FILE"
+report_and_cleanup(){
+ send_errors
+ cleanup
}
cleanup() {
-# if something fails here, it souldn't call cleanup again...
+ # if something fails here, it souldn't call cleanup again...
trap - EXIT
+
if [ ${#CLEANUP[*]} -gt 0 ]; then
LAST_ELEMENT=$((${#CLEANUP[*]}-1))
REVERSE_INDEXES=$(seq ${LAST_ELEMENT} -1 0)
: ${VARIANTS_DIR:="@sysconfdir@/ganeti/snf-image/variants"}
: ${IMAGE_DIR:="@localstatedir@/lib/snf-image"}
+: ${IMAGE_DEBUG:="no"}
+: ${VERSION_CHECK:="@VERSION_CHECK@"}
: ${HELPER_DIR:="@HELPER_DIR@"}
: ${HELPER_IMG:="@HELPER_IMG@"}
: ${HELPER_KERNEL:="@HELPER_KERNEL@"}
: ${HELPER_INITRD:="@HELPER_INITRD@"}
-: ${HELPER_PKG:="@HELPER_DIR@/snf-image-helper.deb"}
-: ${HELPER_SOFT_TIMEOUT:=15}
+: ${HELPER_SOFT_TIMEOUT:=20}
: ${HELPER_HARD_TIMEOUT:=5}
: ${HELPER_USER:="nobody"}
-: ${HELPER_CACHE_FILE:="@HELPER_DIR@/cache.tar"}
-: ${HELPER_CACHE_PKGS:="@HELPER_DIR@/packages"}
: ${HELPER_EXTRA_PKGS:="linux-image-amd64,e2fsprogs,ntfs-3g,ntfsprogs,xmlstarlet,python,parted,reglookup,chntpw,util-linux"}
: ${HELPER_MIRROR:=""}
: ${PITHOS_DB:="sqlite:////@localstatedir@/lib/pithos/backend.db"}
: ${PITHOS_DATA:="@localstatedir@/lib/pithos/data/"}
: ${PROGRESS_MONITOR:="@PROGRESS_MONITOR@"}
: ${UNATTEND:="@UNATTEND@"}
+: ${MULTISTRAP_CONFIG:="@MULTISTRAP_CONFIG@"}
+: ${MULTISTRAP_APTPREFDIR:="@MULTISTRAP_APTPREFDIR@"}
SCRIPT_NAME=$(basename $0)
-if [ -f /sbin/blkid -a -x /sbin/blkid ]; then
- VOL_ID="/sbin/blkid -c /dev/null -o value -s UUID"
- VOL_TYPE="/sbin/blkid -c /dev/null -o value -s TYPE"
-else
- for dir in /lib/udev /sbin; do
- if [ -f $dir/vol_id -a -x $dir/vol_id ]; then
- VOL_ID="$dir/vol_id -u"
- VOL_TYPE="$dir/vol_id -t"
- fi
- done
-fi
-
-if [ -z "$VOL_ID" ]; then
- log_error "vol_id or blkid not found, please install udev or util-linux"
- exit 1
-fi
-
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :