Statistics
| Branch: | Tag: | Revision:

root / snf-image-host / kvm-common.sh @ master

History | View | Annotate | Download (2.2 kB)

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