Revision f4bd39d8

b/AUTHORS
1
Nikos Skalkotos <skalkoto@grnet.gr>
2
Constantinos Venetsanopoulos <cven@grnet.gr>
b/Makefile.am
1
if PROGMONSUPPORT
2
progress_monitor_support=yes
3
else
4
progress_monitor_support=no
5
endif
6

  
7
osdir=$(OS_DIR)/$(osname)
8
defaultdir=$(DEFAULT_DIR)
9
variantsdir=$(DESTDIR)${sysconfdir}/ganeti/snf-image/variants
10

  
11
dist_os_SCRIPTS = host/create
12
dist_os_DATA = ${srcdir}/host/ganeti_api_version ${srcdir}/host/parameters.list \
13
               ${srcdir}/host/variants.list
14

  
15
os_DATA = host/common.sh
16

  
17
edit = sed \
18
	   -e 's|@sysconfdir[@]|$(sysconfdir)|g' \
19
	   -e 's|@localstatedir[@]|$(localstatedir)|g' \
20
	   -e 's|@osdir[@]|$(osdir)|g' \
21
	   -e 's|@osname[@]|$(osname)|g' \
22
	   -e 's|@defaultdir[@]|$(defaultdir)|g' \
23
	   -e 's|@AWK[@]|$(AWK)|g' \
24
	   -e 's|@MKDIR_P[@]|$(MKDIR_P)|g' \
25
	   -e 's|@DUMP[@]|$(DUMP)|g' \
26
	   -e 's|@LOSETUP[@]|$(LOSETUP)|g' \
27
	   -e 's|@KPARTX[@]|$(KPARTX)|g' \
28
	   -e 's|@SFDISK[@]|$(SFDISK)|g' \
29
	   -e 's|@RESIZE2FS[@]|$(RESIZE2FS)|g' \
30
	   -e 's|@progress_monitor_support[@]|$(progress_monitor_support)|g' \
31
	   -e 's|@XMLSTARLET[@]|$(XMLSTARLET)|g' \
32
	   -e 's|@INSTALL_MBR[@]|$(INSTALL_MBR)|g' \
33
	   -e 's|@PROGRESS_MONITOR[@]|$(PROGRESS_MONITOR)|g'
34

  
35
host/common.sh: Makefile
36
	@mkdir_p@ host
37
	rm -f $@ $@.tmp
38
	srcdir=''; \
39
		   test -f ./$@.in || srcdir=$(srcdir)/; \
40
		   $(edit) $${srcdir}$@.in >$@.tmp
41
	mv $@.tmp $@
42

  
43
CLEANFILES = $(os_DATA)
b/autogen.sh
1
#!/bin/sh
2

  
3
if test ! -f configure.ac ; then
4
  echo "You must execute this script from the top level directory."
5
  exit 1
6
fi
7

  
8
set -e
9

  
10
rm -rf config.cache autom4te.cache
11
mkdir -p autotools
12

  
13
${ACLOCAL:-aclocal} -I autotools
14
${AUTOCONF:-autoconf}
15
${AUTOMAKE:-automake} --add-missing
16

  
17
rm -rf autom4te.cache
b/configure.ac
1
AC_PREREQ(2.59)
2
AC_INIT(snf-image, 0.1, synnefo@lists.grnet.gr)
3

  
4
AC_CONFIG_AUX_DIR(autotools)
5
AC_CONFIG_SRCDIR(configure)
6

  
7
AM_INIT_AUTOMAKE([1.9 foreign tar-ustar -Wall -Wno-portability])
8
AM_INIT_AUTOMAKE([subdir-objects])
9

  
10
# --with-progress-monitor
11
AC_ARG_WITH([progress-monitor],
12
  [AS_HELP_STRING([--with-progress-monitor=PRGRM_PATH],
13
    [path to progress-monitor program]
14
    [[snf-progress-monitor]])],
15
    [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],
23
   [AC_MSG_NOTICE(progress-monitor support not enabled)]
24
)
25

  
26
AM_CONDITIONAL(PROGMONSUPPORT, [test -n "$PROGRESS_MONITOR"])
27

  
28

  
29
# --with-os-dir=...
30
AC_ARG_WITH([os-dir],
31
    [AS_HELP_STRING([--with-os-dir=DIR],
32
        [top-level OS directory under which to install]
33
        [ (default is $datadir/ganeti/os)]
34
    )],
35
    [os_dir="$withval"],
36
    [os_dir="$datadir/ganeti/os"])
37
AC_SUBST(OS_DIR, $os_dir)
38

  
39
# --with-default-dir=...
40
AC_ARG_WITH([default-dir],
41
    [AS_HELP_STRING([--with-default-dir=DIR],
42
        [top-level default config directory under which to install]
43
        [ (default is $sysconfdir/default)]
44
    )],
45
    [default_dir="$withval"],
46
    [default_dir="$sysconfdir/default"])
47
AC_SUBST(DEFAULT_DIR, $default_dir)
48

  
49
# Check common programs
50
AC_PROG_INSTALL
51
AC_PROG_LN_S
52
AC_PROG_AWK
53
AC_PROG_MKDIR_P
54

  
55
AC_PATH_PROG(LOSETUP, [losetup], [], [$PATH:/usr/sbin:/sbin])
56
if test -z "$LOSETUP" ; then
57
  AC_MSG_ERROR([losetup not found in $PATH])
58
fi
59

  
60
AC_PATH_PROG(KPARTX, [kpartx], [], [$PATH:/usr/sbin:/sbin])
61
if test -z "$KPARTX" ; then
62
  AC_MSG_ERROR([kpartx not found in $PATH])
63
fi
64

  
65
AC_PATH_PROG(SFDISK, [sfdisk], [], [$PATH:/usr/sbin:/sbin])
66
if test -z "$SFDISK" ; then
67
  AC_MSG_ERROR([sfdisk not found in $PATH])
68
fi
69

  
70
AC_CONFIG_FILES([
71
    Makefile
72
])
73

  
74
AC_OUTPUT
75

  
76
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
77

  
b/host/common.sh.in
1
# Copyright 2011 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or without
4
# modification, are permitted provided that the following conditions
5
# are met:
6
#
7
#   1. Redistributions of source code must retain the above copyright
8
#      notice, this list of conditions and the following disclaimer.
9
#
10
#  2. Redistributions in binary form must reproduce the above copyright
11
#     notice, this list of conditions and the following disclaimer in the
12
#     documentation and/or other materials provided with the distribution.
13
#
14
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
# SUCH DAMAGE.
25
#
26
# The views and conclusions contained in the software and documentation are
27
# those of the authors and should not be interpreted as representing official
28
# policies, either expressed or implied, of GRNET S.A.
29

  
30
AWK="awk"
31
KPARTX="kpartx"
32
LOSETUP="losetup"
33
SFDISK="sfdisk"
34
PROGRESS_MONITOR="snf-progress-monitor"
35

  
36
progress_monitor_support="@progress_monitor_support@"
37

  
38
CLEANUP=( )
39

  
40
log_error() {
41
    echo "$@" >&2
42
}
43

  
44
get_api5_arguments() {
45
    GETOPT_RESULT=$*
46
    # Note the quotes around `$TEMP': they are essential!
47
    eval set -- "$GETOPT_RESULT"
48
    while true; do
49
        case "$1" in
50
            -i|-n) instance=$2; shift 2;;
51

  
52
            -o) old_name=$2; shift 2;;
53

  
54
            -b) blockdev=$2; shift 2;;
55

  
56
            -s) swapdev=$2; shift 2;;
57

  
58
            --) shift; break;;
59

  
60
            *)  log_error "Internal error!" >&2; exit 1;;
61
        esac
62
    done
63
    if [ -z "$instance" -o -z "$blockdev" ]; then
64
        log_error "Missing OS API Argument (-i, -n, or -b)"
65
        exit 1
66
    fi
67
    if [ "$SCRIPT_NAME" != "export" -a -z "$swapdev"  ]; then
68
        log_error "Missing OS API Argument -s (swapdev)"
69
        exit 1
70
    fi
71
    if [ "$SCRIPT_NAME" = "rename" -a -z "$old_name"  ]; then
72
        log_error "Missing OS API Argument -o (old_name)"
73
        exit 1
74
    fi
75
}
76

  
77
get_api10_arguments() {
78
    if [ -z "$INSTANCE_NAME" -o -z "$HYPERVISOR" -o -z "$DISK_COUNT" ]; then
79
        log_error "Missing OS API Variable:"
80
        log_error "(INSTANCE_NAME HYPERVISOR or DISK_COUNT)"
81
        exit 1
82
    fi
83
    instance=$INSTANCE_NAME
84
    if [ $DISK_COUNT -lt 1 -o -z "$DISK_0_PATH" ]; then
85
        log_error "At least one disk is needed"
86
        exit 1
87
    fi
88
    if [ "$SCRIPT_NAME" = "export" ]; then
89
        if [ -z "$EXPORT_DEVICE" ]; then
90
        log_error "Missing OS API Variable EXPORT_DEVICE"
91
    fi
92
    blockdev=$EXPORT_DEVICE
93
    elif [ "$SCRIPT_NAME" = "import" ]; then
94
        if [ -z "$IMPORT_DEVICE" ]; then
95
        log_error "Missing OS API Variable IMPORT_DEVICE"
96
        fi
97
        blockdev=$IMPORT_DEVICE
98
    else
99
        blockdev=$DISK_0_PATH
100
    fi
101
    if [ "$SCRIPT_NAME" = "rename" -a -z "$OLD_INSTANCE_NAME" ]; then
102
        log_error "Missing OS API Variable OLD_INSTANCE_NAME"
103
    fi
104
    old_name=$OLD_INSTANCE_NAME
105
}
106

  
107
get_api20_arguments() {
108
    get_api_10_arguments
109
    if [ -z "$OSP_IMG_ID"]; then
110
        log_error "Missing OS API Parameter: OSP_IMG_ID"
111
        exit 1
112
    fi
113
    if [ -z "$OSP_IMG_FORMAT"]; then
114
        log_error "Missing OS API Parameter: OSP_IMG_FORMAT"
115
        exit 1
116
    fi
117
    if [ -z "$OSP_IMG_PASSWD"]; then
118
        log_error "Missing OS API Parameter: OSP_IMG_PASSWD"
119
        exit 1
120
    fi
121

  
122
    IMG_ID=$OSP_IMG_ID
123
    IMG_FORMAT=$OSP_IMG_FORMAT
124
    IMG_PASSWD=$OSP_IMG_PASSWD
125
}
126

  
127
map_disk0() {
128
    blockdev="$1"
129
    filesystem_dev_base=`$KPARTX -l -p- $blockdev | \
130
                            grep -m 1 -- "-1.*$blockdev" | \
131
                            $AWK '{print $1}'`
132
    if [ -z "$filesystem_dev_base" ]; then
133
        log_error "Cannot interpret kpartx output and get partition mapping"
134
        exit 1
135
    fi
136
    $KPARTX -a -p- $blockdev > /dev/null
137
    filesystem_dev="/dev/mapper/${filesystem_dev_base/%-1/}"
138
    if [ ! -b "/dev/mapper/$filesystem_dev_base" ]; then
139
        log_error "Can't find kpartx mapped partition:" \
140
                                            "/dev/mapper/$filesystem_dev_base"
141
        exit 1
142
    fi
143
    echo "$filesystem_dev"
144
}
145

  
146
unmap_disk0() {
147
    $KPARTX -d -p- $1
148
}
149

  
150
format_disk0() {
151
    local device="$1"
152
    local image_type="$2"
153
    
154
    declare -A part_id=( ['extdump']="83" ["ntfsdump"]="7" )
155

  
156
    # The -f is needed, because we use an optimal alignment and sfdisk complains
157
    # about partitions not ending on clylinder boundary.
158
    local sfdisk_cmd="$SFDISK -uS -H 255 -S 63 -f --quiet --Linux --DOS $device"
159

  
160
    $sfdisk_cmd > /dev/null <<EOF
161
2048,,${part_id["$image_type"]},*
162
EOF
163
}
164

  
165
cleanup() {
166
    if [ ${#CLEANUP[*]} -gt 0 ]; then
167
        LAST_ELEMENT=$((${#CLEANUP[*]}-1))
168
        REVERSE_INDEXES=$(seq ${LAST_ELEMENT} -1 0)
169
        for i in $REVERSE_INDEXES; do
170
            ${CLEANUP[$i]}
171
        done
172
    fi
173
}
174

  
175
trap cleanup EXIT
176

  
177
DEFAULT_FILE="@sysconfdir@/default/snf-image"
178
if [ -f "$DEFAULT_FILE" ]; then
179
    . "$DEFAULT_FILE"
180
fi
181

  
182
: ${ARCH:="x86_64}
183
: ${CUSTOMIZE_DIR:="@sysconfdir@/ganeti/snf-image/hooks"}
184
: ${VARIANTS_DIR:="@sysconfdir@/ganeti/snf-image/variants"}
185
: ${IMAGE_DIR:="@localstatedir@/lib/snf-image"}
186

  
187
SCRIPT_NAME=$(basename $0)
188

  
189
if [ -f /sbin/blkid -a -x /sbin/blkid ]; then
190
    VOL_ID="/sbin/blkid -c /dev/null -o value -s UUID"
191
    VOL_TYPE="/sbin/blkid -c /dev/null -o value -s TYPE"
192
else
193
    for dir in /lib/udev /sbin; do
194
        if [ -f $dir/vol_id -a -x $dir/vol_id ]; then
195
            VOL_ID="$dir/vol_id -u"
196
            VOL_TYPE="$dir/vol_id -t"
197
        fi
198
    done
199
fi
200

  
201
if [ -z "$VOL_ID" ]; then
202
    log_error "vol_id or blkid not found, please install udev or util-linux"
203
    exit 1
204
fi
205

  
206

  
207
if [ -z "$OS_API_VERSION" -o "$OS_API_VERSION" = "5" ]; then
208
    OS_API_VERSION=5
209
    GETOPT_RESULT=`getopt -o o:n:i:b:s: -n '$0' -- "$@"`
210
    if [ $? != 0 ] ; then log_error "Terminating..."; exit 1 ; fi
211
    get_api5_arguments $GETOPT_RESULT
212
elif [ "$OS_API_VERSION" = "10" -o "$OS_API_VERSION" = "15" ]; then
213
    get_api10_arguments
214
elif [ "$OS_API_VERSION" = "20" ]; then
215
    get_api20_arguments
216
    IMAGE_NAME=$IMG_ID
217
    IMAGE_TYPE=$IMG_FORMAT
218
else
219
    log_error "Unknown OS API VERSION $OS_API_VERSION"
220
    exit 1
221
fi
222

  
223
if [ -n "$OS_VARIANT" ]; then
224
    if [ ! -d "$VARIANTS_DIR" ]; then
225
        log_error "OS Variants directory $VARIANTS_DIR doesn't exist"
226
        exit 1
227
    fi
228
    VARIANT_CONFIG="$VARIANTS_DIR/$OS_VARIANT.conf"
229
    if [ -f "$VARIANT_CONFIG" ]; then
230
        . "$VARIANT_CONFIG"
231
    else
232
        if grep -qxF "$OS_VARIANT" variants.list; then
233
            log_error "ERROR: instance-image configuration error"
234
            log_error "  Published variant $OS_VARIANT is missing its config" \
235
                      "file"
236
            log_error "  Please create $VARIANT_CONFIG or unpublish the variant"
237
            log_error "  (by removing $OS_VARIANT from variants.list)"
238
        else
239
            log_error "Unofficial variant $OS_VARIANT is unsupported"
240
            log_error "Most probably this is a user error, forcing a wrong name"
241
            log_error "To support this variant please create file" \
242
                        "$VARIANT_CONFIG"
243
        fi
244
        exit 1
245
    fi
246
fi
247

  
248
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
b/host/create
1
#!/bin/bash
2

  
3
# Copyright 2011 GRNET S.A. All rights reserved.
4
#
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions
7
# are met:
8
#
9
#   1. Redistributions of source code must retain the above copyright
10
#      notice, this list of conditions and the following disclaimer.
11
#
12
#  2. Redistributions in binary form must reproduce the above copyright
13
#     notice, this list of conditions and the following disclaimer in the
14
#     documentation and/or other materials provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
# SUCH DAMAGE.
27
#
28
# The views and conclusions contained in the software and documentation are
29
# those of the authors and should not be interpreted as representing official
30
# policies, either expressed or implied, of GRNET S.A.
31

  
32
set -e
33

  
34
. common.sh
35

  
36
case "$IMAGE_TYPE" in
37
    extdump)
38
	IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}-root.extdump";;
39
    ntfsdump)
40
        IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}-root.ntfsdump";;
41
    *)
42
        log_error "Unknown image type: \`$IMAGE_TYPE'.";
43
        exit 1
44
esac
45

  
46
if [ ! -e "$IMAGE_FILE" ]; then
47
    log_error "Image file \`$IMAGE_FILE' does not exit."
48
    exit 1
49
fi
50

  
51
MONITOR="" #Empty if progress monitor support is disabled
52
if [ "$progress_monitor_support" = "yes" ]; then
53
    IMAGE_SIZE="$(stat -L -c %s ${IMAGE_FILE})"
54
    MONITOR="$PROGRESS_MONITOR -i ${INSTANCE_NAME} -r ${IMAGE_SIZE}"
55
fi
56

  
57
# If the target device is not a real block device we'll first losetup it.
58
# This is needed for file disks.
59
if [ ! -b $blockdev ]; then
60
    ORIGINAL_BLOCKDEV=$blockdev
61
    blockdev=$($LOSETUP -sf $blockdev)
62
    CLEANUP+=("$LOSETUP -d $blockdev")
63
fi
64

  
65
${IMAGE_TYPE}_format_disk0 $blockdev
66

  
67
filesystem_dev=$(map_disk0 $blockdev)
68
CLEANUP+=("unmap_disk0 $blockdev")
69

  
70
root_dev="${filesystem_dev}-1"
71

  
72
# dd the dump to its new home :-)
73
# Deploying an image file on a target block device is a streaming
74
# copy operation. Enable the direct I/O flag on the output fd to 
75
# avoid polluting the host cache with useless data.
76
$MONITOR dd bs=4M if=$IMAGE_FILE of=$root_dev oflag=direct
77

  
78
#Invoke the helper vm to do the dirty job...
79

  
80
# Execute cleanups
81
cleanup
82
trap - EXIT
83

  
84
exit 0
85

  
86
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
b/host/ganeti_api_version
1
20
2
15
3
10
4
5
b/host/parameters.list
1
img_id The id of the image to be installed (the id will be the image's file name prefix)
2
img_format The format of the image to be installed
3
img_passwd The root password which will be injected into the image 
b/host/variants.list
1
default

Also available in: Unified diff