root / snf-image-host / kvm-common.sh @ master
History | View | Annotate | Download (2.2 kB)
1 |
# Copyright (C) 2013 GRNET S.A. |
---|---|
2 |
# |
3 |
# This program is free software; you can redistribute it and/or modify |
4 |
# it under the terms of the GNU General Public License as published by |
5 |
# the Free Software Foundation; either version 2 of the License, or |
6 |
# (at your option) any later version. |
7 |
# |
8 |
# This program is distributed in the hope that it will be useful, but |
9 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 |
# General Public License for more details. |
12 |
# |
13 |
# You should have received a copy of the GNU General Public License |
14 |
# along with this program; if not, write to the Free Software |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
16 |
# 02110-1301, USA. |
17 |
|
18 |
get_img_dev() { |
19 |
echo /dev/vdb |
20 |
} |
21 |
|
22 |
launch_helper() { |
23 |
local result_file result snapshot rc floppy blockdev |
24 |
|
25 |
blockdev="$1" |
26 |
floppy="$2" |
27 |
|
28 |
result_file=$(mktemp result.XXXXXX) |
29 |
add_cleanup rm "$result_file" |
30 |
|
31 |
report_info "Starting customization VM..." |
32 |
echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM START" >&2 |
33 |
|
34 |
set +e |
35 |
|
36 |
$TIMEOUT -k "$HELPER_HARD_TIMEOUT" "$HELPER_SOFT_TIMEOUT" \ |
37 |
kvm -runas "$HELPER_USER" -drive file="$HELPER_DIR/image",format=raw,if=virtio,readonly \ |
38 |
-drive file="$blockdev",format=raw,if=virtio,cache=none -m "$HELPER_MEMORY" \ |
39 |
-boot c -serial stdio -serial "file:$(printf "%q" "$result_file")" \ |
40 |
-serial file:>(./helper-monitor.py ${MONITOR_FD}) \ |
41 |
-fda "$floppy" -vga none -nographic -parallel none -monitor null \ |
42 |
-kernel "$HELPER_DIR/kernel" -initrd "$HELPER_DIR/initrd" \ |
43 |
-append "quiet ro root=/dev/vda1 console=ttyS0,9600n8 \ |
44 |
hypervisor=$HYPERVISOR snf_image_activate_helper \ |
45 |
rules_dev=/dev/fd0 init=/usr/bin/snf-image-helper" \ |
46 |
2>&1 | sed -u 's|^|HELPER: |g' |
47 |
|
48 |
rc=$? |
49 |
set -e |
50 |
echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM STOP" >&2 |
51 |
|
52 |
check_helper_rc "$rc" |
53 |
|
54 |
report_info "Checking customization status..." |
55 |
# Read the first line. This will remove \r and \n chars |
56 |
result=$(sed 's|\r||g' "$result_file" | head -1) |
57 |
report_info "Customization status is: $result" |
58 |
|
59 |
check_helper_result "$result" |
60 |
} |
61 |
|
62 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |