Make helper_ip and monitor_port configurable
[snf-image] / snf-image-host / xen-common.sh
1 get_img_dev() {
2         echo /dev/xvdb
3 }
4
5 #create_mac() {
6 #    # MAC address inside the range 00:16:3e:xx:xx:xx are reserved for Xen
7 #    echo  "aa:$(cat /proc/interrupts | md5sum | sed -r 's/^(.{10}).*$/\1/; s/([0-9a-f]{2})/\1:/g; s/:$//;')"
8 #}
9
10 launch_helper() {
11     local name helperid rc blockdev floppy host_mac helper_mac
12
13     blockdev="$1"
14     floppy="$2"
15
16         name=$(uuid)
17
18     report_info "Starting customization VM..."
19     echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM START" >&2
20
21     xm create /dev/null \
22       kernel="$HELPER_DIR/kernel-xen" ramdisk="$HELPER_DIR/initrd-xen" \
23           root="/dev/xvda1" memory="256" boot="c" vcpus=1 name="$name" \
24       extra="console=hvc0 hypervisor=$HYPERVISOR snf_image_activate_helper \
25           ipv6.disable=1 rules_dev=/dev/xvdc ro boot=local helper_ip=10.0.0.1 \
26           monitor_port=48888 init=/usr/bin/snf-image-helper" \
27       disk="file:$HELPER_DIR/image,xvda,r" disk="phy:$blockdev,xvdb,w" \
28       disk="file:$floppy,xvdc,r" vif="script=${XEN_SCRIPTS_DIR}/vif-snf-image"
29     add_cleanup suppress_errors xm destroy "$name"
30
31     if ! xenstore-exists snf-image-helper; then
32         xenstore-write snf-image-helper ""
33         #add_cleanup xenstore-rm snf-image-helper
34     fi
35
36     helperid=$(xm domid "$name")
37     xenstore-write snf-image-helper/${helperid} ""
38     add_cleanup xenstore-rm snf-image-helper/${helperid}
39     xenstore-chmod snf-image-helper/${helperid} r0 w${helperid}
40
41     filter='udp and dst port 48888 and dst host 10.0.0.255 and src host 10.0.0.1'
42     $TIMEOUT -k $HELPER_HARD_TIMEOUT $HELPER_SOFT_TIMEOUT \
43       ./helper-monitor.py -i "vif${helperid}.0" -f "$filter" ${MONITOR_FD} &
44     monitor_pid=$!
45
46     set +e
47     $TIMEOUT -k $HELPER_HARD_TIMEOUT $HELPER_SOFT_TIMEOUT \
48       socat EXEC:"xm console $name",pty STDOUT | sed -u 's|^|HELPER: |g'
49     rc=$?
50     set -e
51
52     echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM STOP" >&2
53
54     check_helper_rc "$rc"
55
56     set +e
57     wait "$monitor_pid"
58     monitor_rc=$?
59     set -e
60
61     if [ $monitor_rc -ne 0 ]; then
62        log_error "Helper VM monitoring failed"
63        report_error "Helper VM monitoring failed"
64        exit 1
65     fi
66
67     report_info "Checking customization status..."
68     result=$(xenstore-read snf-image-helper/$helperid)
69     report_info "Customization status is: $result"
70
71     check_helper_result "$result"
72 }
73
74 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :