summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Janczyk2010-04-09 22:07:25 +0200
committerMichael Janczyk2010-04-09 22:07:25 +0200
commite530a41bf4ef1b84917cd1295d5aaf30051e42c9 (patch)
tree70c4a122edf9590e4aa0ca1b71845099800ab4e6
parentMerge branch 'master' of git@openslx.org:openslx/core (diff)
downloadcore-e530a41bf4ef1b84917cd1295d5aaf30051e42c9.tar.gz
core-e530a41bf4ef1b84917cd1295d5aaf30051e42c9.tar.xz
core-e530a41bf4ef1b84917cd1295d5aaf30051e42c9.zip
qemukvm network configuration
-rw-r--r--os-plugins/plugins/qemukvm/XX_qemukvm.sh19
-rw-r--r--os-plugins/plugins/qemukvm/files/ifdown19
-rw-r--r--os-plugins/plugins/qemukvm/files/ifup32
-rw-r--r--os-plugins/plugins/qemukvm/files/run-virt.include25
-rw-r--r--os-plugins/plugins/vmchooser/init-hooks/80-after-plugins/virtualization.sh9
-rw-r--r--os-plugins/plugins/vmgrid/files/run-vmgrid.sh20
-rw-r--r--os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh9
7 files changed, 69 insertions, 64 deletions
diff --git a/os-plugins/plugins/qemukvm/XX_qemukvm.sh b/os-plugins/plugins/qemukvm/XX_qemukvm.sh
index ac97b52f..36ff4f59 100644
--- a/os-plugins/plugins/qemukvm/XX_qemukvm.sh
+++ b/os-plugins/plugins/qemukvm/XX_qemukvm.sh
@@ -94,25 +94,16 @@ ${qemukvm_imagesrc}." nonfatal
ln -sf ${PLUGINDIR}/ifup ${PLUGINCONFDIR}/ifup
ln -sf ${PLUGINDIR}/ifdown ${PLUGINCONFDIR}/ifdown
- for qemubin in qemu-kvm kvm qemu ; do
- qemu=$(binfinder ${qemubin})
- [ -n "${qemu}" ] && echo "ALL ALL=NOPASSWD: ${qemu}" >>/mnt/etc/sudoers
- done
- #killall=$(binfinder killall)
- #ippath=$(binfinder ip)
cat >> /mnt/etc/sudoers << EOF
# allow to start and stop kvm services / load-/unload kvm modules
-ALL ALL=NOPASSWD: /etc/init.d/qemukvm
+#ALL ALL=NOPASSWD: /etc/init.d/qemukvm
ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/sbin/tunctl -t tap*
ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/usr/sbin/brctl addif br0 tap*
-
-# TODO: check if kvm / qemu sufficient
+ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/bin/ip link set dev tap* up
+ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/bin/ip addr add * dev tap*
+ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/usr/sbin/udhcpd -S /tmp/qemukvm/*/udhcpd.conf
+ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/bin/cp /tmp/qemukvm/*/forwarding /proc/sys/net/ipv4/conf/tap*/forwarding
#ALL ALL=NOPASSWD: ${killall} udhcpd
-#ALL ALL=NOPASSWD: ${PLUGINDIR}/ifup
-#ALL ALL=NOPASSWD: ${PLUGINDIR}/ifdown
-#ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/usr/sbin/udhcpd -S /tmp/qemukvm/if*
-#ALL ALL=NOPASSWD: ${ippath} link set dev tap*
-#ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/sbin/ip addr add * dev tap*
EOF
fi
else
diff --git a/os-plugins/plugins/qemukvm/files/ifdown b/os-plugins/plugins/qemukvm/files/ifdown
index be6ec913..e741d9ca 100644
--- a/os-plugins/plugins/qemukvm/files/ifdown
+++ b/os-plugins/plugins/qemukvm/files/ifdown
@@ -13,17 +13,20 @@
# - Script used for network cleanup of qemukvm in stage4
# -----------------------------------------------------------------------------
-# Clean up script
+# get VM_ID through tap name
+VM_ID=$(echo $1 | grep -oE "0[0-4]$")
+QKTMPDIR=/tmp/qemukvm/${USER}/${VM_ID}
+touch /tmp/qemukvm/udhcpd.pids
+chmod 666 tmp/qemukvm/udhcpd.pids
case "$1" in
- tap1)
- # Bringing down the dhcp server
- killall udhcpd 2>/dev/null
- #iptables -t nat -D POSTROUTING -o br0 -j MASQUERADE 2>/dev/null
+ tapnat0*)
+ # kill udhcpd
+ cat ${QKTMPDIR}/udhcpd.pid >> /tmp/qemukvm/udhcpd-unused.pid
;;
- tap2)
- # Bringing down the dhcp server
- killall udhcpd 2>/dev/null
+ taphost0*)
+ # kill udhcpd
+ cat ${QKTMPDIR}/udhcpd.pid >> /tmp/qemukvm/udhcpd-unused.pid
;;
esac
diff --git a/os-plugins/plugins/qemukvm/files/ifup b/os-plugins/plugins/qemukvm/files/ifup
index 9d94ac64..b3218798 100644
--- a/os-plugins/plugins/qemukvm/files/ifup
+++ b/os-plugins/plugins/qemukvm/files/ifup
@@ -29,21 +29,20 @@ QKTMPDIR=/tmp/qemukvm/${USER}/${VM_ID}
# should be set up (passed in $1): tap0 = bridge, tap1 = nat, tap2 = hostonly.
case "$1" in
tapbridge0*)
- # Adding the tap0 interface to the existing bridge configured in stage3
- #sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t $1 >/dev/null 2>&1
sudo ip link set dev $1 up
- #sudo /opt/openslx/uclib-rootfs/usr/sbin/brctl addif br0 $1
- echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding
- echo "1" >/proc/sys/net/ipv4/conf/$1/forwarding
+ # TODO: forwarding?, where needed
+ echo "1" >${QKTMPDIR}/forwarding
+ sudo cp ${QKTMPDIR}/forwarding /proc/sys/net/ipv4/conf/br0/forwarding
+ sudo cp ${QKTMPDIR}/forwarding /proc/sys/net/ipv4/conf/$1/forwarding
;;
tapnat0*)
- # Configuring DHCP on host tap1 interface and enable IP masquerading
- #sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t $1 >/dev/null 2>&1
+ # Configuring DHCP on host tapnat interface and enable IP masquerading
sudo ip addr add ${nataddress} dev $1
sudo ip link set dev $1 up
- # not necessary since already done by run-virt.include
- #[ -d ${QKTMPDIR} ] || mkdir -p ${QKTMPDIR}
- # cut the last .NNN/MM from nataddress ${natnetwork%.*}
+ # TODO: forwarding?, where needed
+ echo "1" >${QKTMPDIR}/forwarding
+ sudo cp ${QKTMPDIR}/forwarding /proc/sys/net/ipv4/conf/br0/forwarding
+ sudo cp ${QKTMPDIR}/forwarding /proc/sys/net/ipv4/conf/$1/forwarding
# TODO: we use here atatic address, maybe change later
sed -e "s,NWIF,$1,;s,CNETWORK,192.168.1${VM_ID}," \
-e "s,PIDFILE,${QKTMPDIR}/udhcpd.pid," \
@@ -51,29 +50,26 @@ case "$1" in
${OPENSLX_DEFAULT_CONFDIR}/udhcpd.conf \
>${QKTMPDIR}/udhcpd.conf
touch ${QKTMPDIR}/udhcpd.leases
- # ip link set $1 up
- # ip addr add 192.168.101.254/24 dev $1
sudo /opt/openslx/uclib-rootfs/usr/sbin/udhcpd \
-S ${QKTMPDIR}/udhcpd.conf
# iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE
;;
taphost0*)
- # Configuring DHCP on host tap2 interface
- #sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t $1 >/dev/null 2>&1
+ # Configuring DHCP on host taphost interface
sudo ip addr add ${hoaddress} dev $1
sudo ip link set dev $1 up
- #[ -d ${QKTMPDIR} ] || mkdir -p ${QKTMPDIR}
+ # TODO: forwarding?, where needed
+ echo "1" >${QKTMPDIR}/forwarding
+ sudo cp ${QKTMPDIR}/forwarding /proc/sys/net/ipv4/conf/br0/forwarding
+ sudo cp ${QKTMPDIR}/forwarding /proc/sys/net/ipv4/conf/$1/forwarding
sed -e "s,NWIF,$1,;s,USER,${USER},;s,CNETWORK,192.168.1${VM_ID}," \
-e "s,PIDFILE,${QKTMPDIR}/udhcpd.pid," \
-e "s,LEASEFILE,${QKTMPDIR}/udhcpd.leases," \
${OPENSLX_DEFAULT_CONFDIR}/udhcpd.conf >${QKTMPDIR}/udhcpd.conf
touch ${QKTMPDIR}/udhcpd.leases
- # ip link set $1 up
- # ip addr add 192.168.102.254/24 dev $1
sudo /opt/openslx/uclib-rootfs/usr/sbin/udhcpd \
-S ${QKTMPDIR}/udhcpd.conf
;;
esac
-# Produce a clean exit status
exit 0
diff --git a/os-plugins/plugins/qemukvm/files/run-virt.include b/os-plugins/plugins/qemukvm/files/run-virt.include
index 08a8b4f1..02c70469 100644
--- a/os-plugins/plugins/qemukvm/files/run-virt.include
+++ b/os-plugins/plugins/qemukvm/files/run-virt.include
@@ -40,7 +40,7 @@ QKTMPDIR="/tmp/${self}/${USER}/${VM_ID}"
# define dirs and files which can be removed after exit, be carefull!
RMDIRS="${QKTMPDIR}"
rm -rf ${RMDIRS} 2>/dev/null
-mkdir -p ${QKTMPDIR} 2>/dev/null
+mkdir -m 1777 -p ${QKTMPDIR} 2>/dev/null
# vmpath is the path to the vm, here an image (img|qcow*|vmdk)
diskfile=${vmpath}
@@ -118,22 +118,28 @@ network_card=${network_card:=pcnet}
VIRTCMDOPTS="${VIRTCMDOPTS} -net nic,macaddr=${macaddr},model=${network_card}"
# define net kind and apply script
-qemu_ifscr="script=${PLUGINDIRQK}/ifup,downscript=${PLUGINDIRQK}/ifdown"
+qemu_ifscr="script=${PLUGINCONFQK}/ifup,downscript=${PLUGINCONFQK}/ifdown"
case "${network_kind}" in
bridge*)
VIRTCMDOPTS="${VIRTCMDOPTS} -net tap,ifname=tapbridge${VM_ID},${qemu_ifscr}"
- sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t tapbridge${VM_ID} #2>/dev/null
+ sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t tapbridge${VM_ID} -u ${USER} \
+ >/dev/null 2>&1
sudo /opt/openslx/uclib-rootfs/usr/sbin/brctl addif br0 tapbridge${VM_ID}
+ POSTRUN="/opt/openslx/uclib-rootfs/sbin/tunctl -d tapbridge${VM_ID}"
;;
- NAT|nat)
+ nat)
VIRTCMDOPTS="${VIRTCMDOPTS} -net tap,ifname=tapnat${VM_ID},${qemu_ifscr}"
- sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t tapnat${VM_ID}
+ sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t tapnat${VM_ID} -u ${USER} \
+ >/dev/null 2>&1
sudo /opt/openslx/uclib-rootfs/usr/sbin/brctl addif br0 tapnat${VM_ID}
+ POSTRUN="/opt/openslx/uclib-rootfs/sbin/tunctl -d tapnat${VM_ID}"
;;
- hostonly|host-only)
+ host*)
VIRTCMDOPTS="${VIRTCMDOPTS} -net tap,ifname=taphost${VM_ID},${qemu_ifscr}"
- sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t taphost${VM_ID}
+ sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t taphost${VM_ID} -u ${USER} \
+ >/dev/null 2>&1
sudo /opt/openslx/uclib-rootfs/usr/sbin/brctl addif br0 taphost${VM_ID}
+ POSTRUN="/opt/openslx/uclib-rootfs/sbin/tunctl -d taphost${VM_ID}"
;;
*)
network_kind="user"
@@ -278,11 +284,9 @@ if [ -z "${VIRTCMD}" ]; then
rm -rf ${RMDIRS}
exit 1
elif [ "${VIRTCMD##*/}" = "qemu" ]; then
- writelog "No user space KVM found. Using slow QEMU emulation"
writelog "User space emulation:\t\t${VIRTCMD}"
else
writelog "User space virtualization:\t${VIRTCMD}"
- VIRTCMD="sudo $VIRTCMD"
fi
# using snapshots
@@ -293,11 +297,10 @@ VIRTCMDOPTS="${VIRTCMDOPTS} -boot c"
# set headless mode
# define first, you do not want VIRTCMDOPTS from graphical start
-VIRTCMDHL="$VIRTCMD"
+VIRTCMDHL=${VIRTCMD}
VIRTCMDOPTSHL="${VIRTCMDOPTS} -nographic ${diskfile}"
# graphical start
-VIRTCMD="$VIRTCMD"
# vga std/cirrus/vmware?
#VIRTCMDOPTS="${VIRTCMDOPTS} -vga std -full-screen ${diskfile}"
VIRTCMDOPTS="${VIRTCMDOPTS} ${diskfile}"
diff --git a/os-plugins/plugins/vmchooser/init-hooks/80-after-plugins/virtualization.sh b/os-plugins/plugins/vmchooser/init-hooks/80-after-plugins/virtualization.sh
index 8c241b8b..5fa046d9 100644
--- a/os-plugins/plugins/vmchooser/init-hooks/80-after-plugins/virtualization.sh
+++ b/os-plugins/plugins/vmchooser/init-hooks/80-after-plugins/virtualization.sh
@@ -30,7 +30,7 @@ active=0
[ -n "${CONFFILEVMGRID}" ] && active=1
[ $DEBUGLEVEL -gt 0 ] \
- && echo "Executing the virtual 'virtualization' plugin ..."
+ && echo -e "Executing the virtual 'virtualization' plugin ... \c"
if [ ${active} -ne 0 ] ; then
@@ -90,6 +90,9 @@ fi
echo "vtflag=0" >> ${PLUGINCONFDIR}/virtualization.conf
fi
+ # write mac
+ echo "machostaddr=${macaddr}" >> ${PLUGINCONFDIR}/virtualization.conf
+
# get further hw information
waitfor /etc/hwinfo.cdrom
j=0
@@ -107,8 +110,8 @@ fi
# finished ...
[ $DEBUGLEVEL -gt 0 ] \
- && echo " ok"
+ && echo "ok"
else
[ $DEBUGLEVEL -gt 0 ] \
- && echo " failed"
+ && echo "failed"
fi
diff --git a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh
index bf10dc36..5e64b4cd 100644
--- a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh
+++ b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh
@@ -39,11 +39,12 @@ RWSHARE=/var/opt/openslx/plugins/vmgrid/share
################################################################################
# function to write to stdout and logfile
+LOGFILE=${OPENSLX_DEFAULT_LOGDIR}/run-vmgrid.${USER}.$$.log
writelog () {
# write to stdout
echo -e "$1"
# log into file
- echo -e "$1" >> ${OPENSLX_DEFAULT_LOGDIR}/run-vmgrid.${USER}.$$.log
+ echo -e "$1" >> ${LOGFILE}
# log into share dir, so that log is available in vm as well
echo -e "$1" >> ${vmgrid_rwmnt}/logs/run-vmgrid.${USER}.$$.log
}
@@ -66,7 +67,8 @@ while [ $# -gt 0 ]; do
;;
--forcemem)
# get a result which can be divided through 4
- forcemem=$(expr $2 / 4 \* 4)
+ forcemem=$2
+ echo $2 | grep -q '[1-9][0-9]\{2,3\}$' && forcemem=$(expr $2 / 4 \* 4)
shift
;;
*)
@@ -113,7 +115,7 @@ if [ "${vmgrid_virt}" = "xen" ]; then
runningvms=$(expr ${runningvms} + 1)
fi
# check value
-if [ $runningvms -le 0 ]; then
+if [ ${runningvms} -le 0 ]; then
writelog "Error in value: Running VMs: ${runningvms}. Exit!"
exit 1
fi
@@ -288,9 +290,9 @@ vmostype=$(grep -io '<os param=.*"' ${xmlfile} | awk -F '"' '{ print $2 }' \
# definition of the networking the client system is connected to
network_kind=$(grep -io 'network param=.*"' ${xmlfile} \
- | awk -F '"' '{ print $2 }')
+ | awk -F '"' '{ print $2 }' | tr [A-Z] [a-z])
network_card=$(grep -io 'netcard param=.*"' ${xmlfile} \
- | awk -F '"' '{ print $2 }')
+ | awk -F '"' '{ print $2 }'| tr [A-Z] [a-z])
writelog "\tVirtualization:\t\t$xmlvirt"
writelog "\tVM name:\t\t$vm_name"
@@ -320,8 +322,7 @@ mem=$(expr ${totalmem} / 100 \* ${permem} / 4 \* 4)
# last two bytes are taken from the bridge of the host
# define one MAC per guest
macguestpart="00:50:56:${VM_ID}"
-machostpart=$($(which ifconfig) br0 | grep br0 | sed -e "s/ //g" \
- | awk -F ":" '{print $(NF-1)":"$NF}')
+machostpart=$(echo ${machostaddr} | awk -F ":" '{print $(NF-1)":"$NF}')
macaddr=$(echo "${macguestpart}:${machostpart}" | tr [a-z] [A-Z])
# ide is expected default, test for the virtual disk image type should
@@ -378,6 +379,11 @@ else
exit 1
fi
+# postrun for scripts after virtualization finishes
+if [ -n "${POSTRUN}" ]; then
+ eval ${POSTRUN} >/dev/null 2>&1
+fi
+
# remove config dirs when finished
if echo "${RMDIRS}" 2>/dev/null | grep -q ${vmgrid_virt}; then
writelog "${vmgrid_virt} exited. Cleanning up... \c"
diff --git a/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh b/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh
index 8c241b8b..5fa046d9 100644
--- a/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh
+++ b/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh
@@ -30,7 +30,7 @@ active=0
[ -n "${CONFFILEVMGRID}" ] && active=1
[ $DEBUGLEVEL -gt 0 ] \
- && echo "Executing the virtual 'virtualization' plugin ..."
+ && echo -e "Executing the virtual 'virtualization' plugin ... \c"
if [ ${active} -ne 0 ] ; then
@@ -90,6 +90,9 @@ fi
echo "vtflag=0" >> ${PLUGINCONFDIR}/virtualization.conf
fi
+ # write mac
+ echo "machostaddr=${macaddr}" >> ${PLUGINCONFDIR}/virtualization.conf
+
# get further hw information
waitfor /etc/hwinfo.cdrom
j=0
@@ -107,8 +110,8 @@ fi
# finished ...
[ $DEBUGLEVEL -gt 0 ] \
- && echo " ok"
+ && echo "ok"
else
[ $DEBUGLEVEL -gt 0 ] \
- && echo " failed"
+ && echo "failed"
fi