Commit 789fbcdd authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Merge branch 'master' into debian

parents 31298135 a27e4ee4
2011-12-15, v0.3
* Force a resize when the filesystem is clean, even if resize2fs
complains
* Make sure OSFAMILY image property is specified
2011-11-18, v0.2
* Add support for Image Properties
* Add new FixPartitionTable task
......
......@@ -24,6 +24,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
# Programs
XMLSTARLET=xmlstarlet
TUNE2FS=tune2fs
RESIZE2FS=resize2fs
PARTED=parted
REGLOOKUP=reglookup
......@@ -150,13 +151,10 @@ cleanup() {
fi
}
check_if_excluded() {
test "$PROGNAME" = "snf-image-helper" && return 0
eval local do_exclude=\$SNF_IMAGE_PROPERTY_EXCLUDE_${PROGNAME:2}_TASK
if [ -n "$do_exclude" ]; then
local exclude=SNF_IMAGE_PROPERTY_EXCLUDE_TASK_${PROGNAME:2}
if [ -n "${!exclude}" ]; then
warn "Task $PROGNAME was excluded and will not run."
exit 0
fi
......@@ -166,7 +164,4 @@ check_if_excluded() {
trap cleanup EXIT
# Check if the execution of a task should be ommited
check_if_excluded
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
AC_PREREQ(2.59)
AC_INIT(snf-image-helper, 0.2, synnefo@lists.grnet.gr)
AC_INIT(snf-image-helper, 0.3, synnefo@lists.grnet.gr)
AC_CONFIG_AUX_DIR(autotools)
AC_CONFIG_SRCDIR(configure)
......
......@@ -75,6 +75,11 @@ fi
trap '{ umount "$target"; }' ERR
if [ -z "$SNF_IMAGE_PROPERTY_EXCLUDE_ALL_TASKS" ]; then
if [[ ! "$SNF_IMAGE_PROPERTY_OSFAMILY" =~ ^(linux|windows)$ ]]; then
log_error "Supported values for OSFAMILY propertry are: linux|windows"
fi
# Redirect standard error to standard output,
# prepend a timestamp before each line of output.
echo "Execute all snf-image tasks...."
......
......@@ -26,6 +26,9 @@
set -e
. "@commondir@/common.sh"
# Check if the task should be prevented from running.
check_if_excluded
if [ ! -b "$SNF_IMAGE_DEV" ]; then
log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device"
fi
......
......@@ -27,6 +27,9 @@
set -e
. "@commondir@/common.sh"
# Check if the task should be prevented from running.
check_if_excluded
if [ ! -b "$SNF_IMAGE_DEV" ]; then
log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device"
fi
......@@ -37,7 +40,24 @@ ptype=$(echo "$last_partition" | cut -d: -f5)
if [[ "$ptype" == ext[234] ]]; then
device="${SNF_IMAGE_DEV}${id}"
"$RESIZE2FS" "$device"
state=$($TUNE2FS -l "$device" | grep ^Filesystem\ state: | cut -d: -f2);
state=$(echo $state) #trim the value
# We force a filesystem resize here if the file system is clean, even if
# resize2fs complains. By default resize2fs will refuse to resize a file
# system that has been mounted after the last fs check, but since we are
# sure the file system is clean it's safe enough to bypass this.
if [ "$state" = "clean" ]; then
$RESIZE2FS -f "$device"
else
log_error "The file system state of partition: \`$device' " \
" is not clean (state = $state)"
fi
else
warn "Last partition with id: \`$id' has an unsupported file system type:" \
" (ptype = $ptype)."
fi
exit 0
......
......@@ -27,6 +27,9 @@
set -e
. "@commondir@/common.sh"
# Check if the task should be prevented from running.
check_if_excluded
if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing."
fi
......@@ -60,8 +63,8 @@ done
config="$target/etc/ssh/sshd_config"
if [ ! -e "$config" ]; then
echo "Warning: Config file: \`$config' is missing."
echo "Warning: Can't check for non-default keys."
warn "Config file: \`$config' is missing."
warn "Can't check for non-default keys."
exit 0
fi
......
......@@ -34,6 +34,9 @@
set -e
. "@commondir@/common.sh"
# Check if the task should be prevented from running.
check_if_excluded
if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target directory \`$SNF_IMAGE_TARGET' is missing"
fi
......
......@@ -27,6 +27,9 @@
set -e
. "@commondir@/common.sh"
# Check if the task should be prevented from running.
check_if_excluded
if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
fi
......
......@@ -27,6 +27,9 @@
set -e
. "@commondir@/common.sh"
# Check if the task should be prevented from running.
check_if_excluded
windows_hostname() {
local target="$1"
local password="$2"
......@@ -56,14 +59,13 @@ linux_hostname() {
redhat)
sed -ie "s/HOSTNAME=.*$/HOSTNAME=$hostname/g" "$target/etc/sysconfig/network";;
slackware|suse)
#local domain=$(sed -e 's/^[^\.]*//g' < /etc/HOSTNAME)
# In slackware hostname and domain name are joined together. For now I
# will not retain the domain name.
echo "$hostname" > "${target}/etc/HOSTNAME";;
gentoo)
sed -ie "s/\(\(HOSTNAME\)\|\(hostname\)\)=.*$/\1=\"$hostname\"/" "$target/etc/conf.d/hostname";;
#local domain=$(sed -e 's/^[^\.]*//g' < /etc/HOSTNAME)
# In slackware hostname and domain name are joined together. For now
# I will not retain the domain name.
echo "$hostname" > "${target}/etc/HOSTNAME";;
gentoo)
sed -ie "s/\(\(HOSTNAME\)\|\(hostname\)\)=.*$/\1=\"$hostname\"/" "$target/etc/conf.d/hostname";;
esac
# Some Linux distributions assign the hostname to 127.0.1.1 in order to be
......
......@@ -27,6 +27,9 @@
set -e
. "@commondir@/common.sh"
# Check if the task should be prevented from running.
check_if_excluded
windows_password() {
local target="$1"
local password="$2"
......@@ -101,8 +104,6 @@ elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
linux_password "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
fi
echo "done"
exit 0
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
......
......@@ -29,6 +29,9 @@ set -o pipefail
. "@commondir@/common.sh"
# Check if the task should be prevented from running.
check_if_excluded
if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
fi
......
......@@ -27,6 +27,9 @@
set -e
. "@commondir@/common.sh"
# Check if the task should be prevented from running.
check_if_excluded
if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target directory \`$SNF_IMAGE_TARGET' is missing"
fi
......
Nikos Skalkotos <skalkoto@grnet.gr>
Constantinos Venetsanopoulos <cven@grnet.gr>
Vangelis Koukis <vkoukis@grnet.gr>
Giorgos Verigakis <verigak@grnet.gr>
2011-12-15, v0.3
* Put all helpers run-time created files in a tmpfs jail
* Remove the ARCH field from the image name
* Support remote (network accessable) and pithos hosted images
* Remove custom images format (remote images is a supergroup)
2011-11-18, v0.2
* Support diskdump format
* Support custom images format. Custom images are diskdump images
......
......@@ -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)
......@@ -11,6 +23,9 @@ variantsdir=${sysconfdir}/ganeti/snf-image/variants
dist_os_SCRIPTS = ${srcdir}/create ${srcdir}/import ${srcdir}/export \
${srcdir}/rename ${srcdir}/verify
if PITHOSIMGSUPPORT
dist_os_SCRIPTS += ${srcdir}/pithcat
endif
dist_os_DATA = ${srcdir}/ganeti_api_version ${srcdir}/parameters.list \
${srcdir}/variants.list
......@@ -38,7 +53,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
......@@ -266,7 +291,6 @@ if [ -f "$DEFAULT_FILE" ]; then
. "$DEFAULT_FILE"
fi
: ${ARCH:="x86_64"}
: ${VARIANTS_DIR:="@sysconfdir@/ganeti/snf-image/variants"}
: ${IMAGE_DIR:="@localstatedir@/lib/snf-image"}
: ${HELPER_DIR:="@HELPER_DIR@"}
......@@ -280,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/data/"}
SCRIPT_NAME=$(basename $0)
......
AC_PREREQ(2.59)
AC_INIT(snf-image, 0.2, synnefo@lists.grnet.gr)
AC_INIT(snf-image, 0.3, synnefo@lists.grnet.gr)
AC_CONFIG_AUX_DIR(autotools)
AC_CONFIG_SRCDIR(configure)
......@@ -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-$ARCH.$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,23 @@ case "$IMAGE_TYPE" in
snf_export_PROPERTY_OSFAMILY="linux"
fi
;;
diskdump|custom)
diskdump)
target="$blockdev"
;;
*)
log_error "Unknown Image format: \`$IMAGE_TYPE'"
exit 1
;;
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
......@@ -103,10 +114,16 @@ fi
create_floppy "$floppy"
# Invoke the helper vm to do the dirty job...
result_file=$(mktemp --tmpdir result.XXXXXX)
jail=$(mktemp -d --tmpdir tmpfsXXXXXXX)
add_cleanup rmdir "$jail"
mount tmpfs -t tmpfs "$jail" -o size=50M
add_cleanup umount "$jail"
result_file=$(mktemp --tmpdir="$jail" result.XXXXXX)
add_cleanup rm "$result_file"
snapshot=$(mktemp --tmpdir helperXXXXXX.img)
snapshot=$(mktemp --tmpdir="$jail" helperXXXXXX.img)
add_cleanup rm "$snapshot"
"$QEMU_IMG" create -f qcow2 -b "$HELPER_IMG" "$snapshot"
......
......@@ -9,10 +9,6 @@
# IMAGE_DIR: directory location for disk images
# IMAGE_DIR="/var/lib/snf-image"
# ARCH: Define the ARCH of the image to use
# Use either x86 or x86_64
# ARCH="x86_64"
# IMAGE_DEBUG: turn on debugging output for the scripts
# IMAGE_DEBUG=0
......@@ -58,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/data"
# 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