exec {fd}>&-
}
+send_result_kvm() {
+ echo "$@" > /dev/ttyS1
+}
+
+send_monitor_message_kvm() {
+ echo "$@" > /dev/ttyS2
+}
+
+send_result_xen() {
+ xenstore-write /local/domain/0/snf-image-helper/$DOMID "$*"
+}
+
+send_monitor_message_xen() {
+ echo "$@" | socat STDIN INTERFACE:eth0
+}
+
prepare_helper() {
local cmdline item key val hypervisor domid
case "$hypervisor" in
kvm)
- exec {RESULT_FD}> /dev/ttyS1
- add_cleanup close_fd ${RESULT_FD}
- exec {MONITOR_FD}> /dev/ttyS2
- add_cleanup close_fd ${MONITOR_FD}
+ HYPERVISOR=kvm
;;
xen-hvm|xen-pvm)
- $MOUNT -t xenfs xenfs /proc/xen
- iptables -P OUTPUT DROP
- ip6tables -P OUTPUT DROP
- ip link set eth0 up
- domid=$(xenstore-read domid)
- exec {RESULT_FD}> >(xargs -l1 xenstore-write /local/domain/0/snf-image-helper/$domid)
- add_cleanup close_fd ${RESULT_FD}
- exec {MONITOR_FD}> >(socat STDIN INTERFACE:eth0)
- add_cleanup close_fd ${MONITOR_FD}
+ $MOUNT -t xenfs xenfs /proc/xen
+ iptables -P OUTPUT DROP
+ ip link set eth0 arp off
+ ip link set eth0 up
+ export DOMID=$(xenstore-read domid)
+ HYPERVISOR=xen
;;
*)
echo "ERROR: Unknown hypervisor: \`$hypervisor'" >&2
;;
esac
- export RESULT_FD MONITOR_FD
+ export HYPERVISOR
}
report_error() {
+ msg=""
if [ ${#ERRORS[*]} -eq 0 ]; then
# No error message. Print stderr
local lines
lines=$(tail --lines=${STDERR_LINE_SIZE} "$STDERR_FILE" | wc -l)
- echo -n "STDERR:${lines}:" >&${MONITOR_FD}
- tail --lines=$lines "$STDERR_FILE" >&${MONITOR_FD}
+ msg="STDERR:${lines}"
+ msg+=$(tail --lines=$lines "$STDERR_FILE")
else
for line in "${ERRORS[@]}"; do
- echo "ERROR:$line" >&${MONITOR_FD}
+ msg+="ERROR:$line"$'\n'
done
fi
+
+ send_monitor_message_${HYPERVISOR} "$msg"
}
log_error() {
ERRORS+=("$*")
- echo "ERROR: $@" >&2
- echo "ERROR: $@" >&${MONITOR_FD}
- echo "ERROR" >&${RUSULT_FD}
+ send_monitor_message_${HYPERVISOR} "ERROR: $@"
+ send_result_${HYPERVISOR} "ERROR: $@"
# Use return instead of exit. The set -x options will terminate the script
# but will also trigger ERR traps if defined.
warn() {
echo "Warning: $@" >&2
- echo "WARNING: $@" >&${MONITOR_FD}
+ send_monitor_message_${HYPERVISOR} "WARNING: $@"
}
report_task_start() {
- echo "$MSG_TYPE_TASK_START:${PROGNAME:2}" >&${MONITOR_FD}
+ send_monitor_message_${HYPERVISOR} "$MSG_TYPE_TASK_START:${PROGNAME:2}"
}
report_task_end() {
- echo "$MSG_TYPE_TASK_END:${PROGNAME:2}" >&${MONITOR_FD}
+ send_monitor_message_${HYPERVISOR} "$MSG_TYPE_TASK_END:${PROGNAME:2}"
}
system_poweroff() {
return_success() {
- echo SUCCESS >&${RESULT_FD}
+ send_result_${HYPERVISOR} "SUCCESS"
}
trap cleanup EXIT
defaultdir=$(DEFAULT_DIR)
exampledir = $(datarootdir)/doc/$(PACKAGE)
variantsdir=${sysconfdir}/ganeti/snf-image/variants
+xenscriptsdir=${sysconfdir}/xen/scripts
dist_os_SCRIPTS = ${srcdir}/create ${srcdir}/import ${srcdir}/export \
${srcdir}/rename ${srcdir}/verify ${srcdir}/pithcat \
dist_os_DATA = ${srcdir}/ganeti_api_version ${srcdir}/parameters.list \
${srcdir}/variants.list
+dist_xenscripts_SCRIPTS = ${srcdir}/vif-snf-image
+
dist_bin_SCRIPTS = snf-image-update-helper
os_DATA = common.sh
: ${PITHOS_DATA:="@localstatedir@/lib/pithos/data/"}
: ${PROGRESS_MONITOR:="@PROGRESS_MONITOR@"}
: ${UNATTEND:="@UNATTEND@"}
-: ${XEN_BRIDGE:="xenbr"}
+: ${XEN_SCRIPTS_DIR="@sysconfdir@/xen/scripts"}
: ${MULTISTRAP_CONFIG:="@MULTISTRAP_CONFIG@"}
: ${MULTISTRAP_APTPREFDIR:="@MULTISTRAP_APTPREFDIR@"}
# files will be injected to the helper image before multistrap is called.
# MULTISTRAP_APTPREFDIR="@MULTISTRAP_APTPREFDIR@"
+# XEN_SCRIPTS_DIR: Directory where the Xen scripts are stored
+# XEN_SCRIPTS_DIR=="@sysconfdir@/xen/scripts"
+
# PITHOS_DB: Pithos database in SQLAlchemy format
# PITHOS_DB="sqlite:////@localstatedir@/lib/pithos/backend.db"
import json
import re
-# add HELPER_MONITOR_
-LINESIZE = 512+16
-BUFSIZE = 512+16
+LINESIZE = 512
+BUFSIZE = 512
PROGNAME = os.path.basename(sys.argv[0])
STDERR_MAXLINES = 10
MAXLINES = 100
MSG_TYPE = 'image-helper'
PROTOCOL = {
- 'HELPER_MONITOR_TASK_START': ('task-start', 'task'),
- 'HELPER_MONITOR_TASK_END': ('task-end', 'task'),
- 'HELPER_MONITOR_WARNING': ('warning', 'messages'),
- 'HELPER_MONITOR_STDERR': ('error', 'stderr'),
- 'HELPER_MONITOR_ERROR': ('error', 'messages')}
+ 'TASK_START': ('task-start', 'task'),
+ 'TASK_END': ('task-end', 'task'),
+ 'WARNING': ('warning', 'messages'),
+ 'STDERR': ('error', 'stderr'),
+ 'ERROR': ('error', 'messages')}
def error(msg):
stderr += "%s\n" % line
lines_left -= 1
if lines_left == 0:
- send(fd, "HELPER_MONITROR_STDERR", stderr)
+ send(fd, "STDERR", stderr)
stderr = ""
line = ""
continue
if len(line) == 0:
continue
- if line.startswith("HELPER_MONITOR_STDERR:"):
- m = re.match("HELPER_MONITOR_STDERR:(\d+):(.*)", line)
+ if line.startswith("STDERR:"):
+ m = re.match("STDERR:(\d+):(.*)", line)
if not m:
error("Invalid syntax for STDERR line")
try:
lines_left -= 1
if lines_left == 0:
- send(fd, "HELPER_MONITOR_STDERR", stderr)
+ send(fd, "STDERR", stderr)
stderr = ""
- elif line.startswith("HELPER_MONITOR_TASK_START:") \
- or line.startswith("HELPER_MONITOR_TASK_END:") \
- or line.startswith("HELPER_MONITOR_WARNING:") \
- or line.startswith("HELPER_MONITOR_ERROR:"):
+ elif line.startswith("TASK_START:") \
+ or line.startswith("TASK_END:") \
+ or line.startswith("WARNING:") \
+ or line.startswith("ERROR:"):
(msg_type, _, value) = line.partition(':')
- if line.startswith("HELPER_MONITOR_WARNING:") \
- or line.startswith("HELPER_MONITOR_ERROR:"):
+ if line.startswith("WARNING:") or line.startswith("ERROR:"):
value = [value]
send(fd, msg_type, value)
else:
--- /dev/null
+#!/bin/bash
+
+dir=$(dirname "$0")
+. "$dir"/vif-common.sh
+
+echo 0 > /proc/sys/net/ipv6/conf/$vif/autoconf
+echo 1 > /proc/sys/net/ipv6/conf/$vif/disable_ipv6
+
+ip link set $vif up
+
+success
+
echo /dev/xvdb
}
+#create_mac() {
+# # MAC address inside the range 00:16:3e:xx:xx:xx are reserved for Xen
+# echo "aa:$(cat /proc/interrupts | md5sum | sed -r 's/^(.{10}).*$/\1/; s/([0-9a-f]{2})/\1:/g; s/:$//;')"
+#}
+
launch_helper() {
- local name helperid rc blockdev floppy
+ local name helperid rc blockdev floppy host_mac helper_mac
- blockdev="$1"
- floppy="$2"
+ blockdev="$1"
+ floppy="$2"
name=$(uuid)
- report_info "Starting customization VM..."
- echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM START" >&2
+ report_info "Starting customization VM..."
+ echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM START" >&2
xm create /dev/null \
kernel="$HELPER_DIR/kernel-xen" ramdisk="$HELPER_DIR/initrd-xen" \
root="/dev/xvda1" memory="256" boot="c" vcpus=1 name="$name" \
extra="console=hvc0 hypervisor=$HYPERVISOR snf_image_activate_helper \
- rules_dev=/dev/xvdc quiet ro boot=local init=/usr/bin/snf-image-helper" \
+ ipv6.disable=1 rules_dev=/dev/xvdc ro boot=local init=/usr/bin/snf-image-helper" \
disk="file:$HELPER_DIR/image,xvda,r" disk="phy:$blockdev,xvdb,w" \
- disk="file:$floppy,xvdc,r" vif="mac=aa:00:00:00:00:11,bridge=$XEN_BRIDGE" \
+ disk="file:$floppy,xvdc,r" vif="script=${XEN_SCRIPTS_DIR}/vif-snf-image"
if ! xenstore-exists snf-image-helper; then
xenstore-write snf-image-helper ""
helperid=$(xm domid "$name")
xenstore-write snf-image-helper/${helperid} ""
- add_cleanup xenstore-rm snf-image-helper/${helperid}
+ add_cleanup xenstore-rm snf-image-helper/${helperid}
xenstore-chmod snf-image-helper/${helperid} r0 w${helperid}
- brctl delif xenbr "vif${helperid}.0"
-
socat EXEC:"./helper-monitor.py ${MONITOR_FD}" INTERFACE:vif${helperid}.0 &
- set +e
+ set +e
$TIMEOUT -k $HELPER_HARD_TIMEOUT $HELPER_SOFT_TIMEOUT \
socat EXEC:"xm console $name",pty STDOUT | sed -u 's|^|HELPER: |g'
- rc=$?
- set -e
+ rc=$?
+ set -e
echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM STOP" >&2
if [ $rc -ne 0 ]; then
fi
}
+# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :