diff options
author | Michael Janczyk | 2010-04-02 20:50:29 +0200 |
---|---|---|
committer | Michael Janczyk | 2010-04-02 20:50:29 +0200 |
commit | 5dd09617cd77f2a616c770152c4cd8319803a05f (patch) | |
tree | 09f9a8d21be95907c0ce8cebeb2d47456a291778 /os-plugins/plugins | |
parent | xen nfs boot, xen boot (diff) | |
download | core-5dd09617cd77f2a616c770152c4cd8319803a05f.tar.gz core-5dd09617cd77f2a616c770152c4cd8319803a05f.tar.xz core-5dd09617cd77f2a616c770152c4cd8319803a05f.zip |
qemu tap coniguration hell
Diffstat (limited to 'os-plugins/plugins')
-rw-r--r-- | os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm | 35 | ||||
-rw-r--r-- | os-plugins/plugins/qemukvm/files/ifup | 47 | ||||
-rw-r--r-- | os-plugins/plugins/qemukvm/files/run-virt.include | 34 | ||||
-rwxr-xr-x | os-plugins/plugins/qemukvm/init-hooks/60-have-servconfig/vm-dhcpd.sh | 10 | ||||
-rw-r--r-- | os-plugins/plugins/virtualbox/files/run-virt.include | 42 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/files/run-vmgrid.sh | 12 | ||||
-rw-r--r-- | os-plugins/plugins/xen/files/machine.include | 2 | ||||
-rw-r--r-- | os-plugins/plugins/xen/files/run-virt.include | 59 |
8 files changed, 133 insertions, 108 deletions
diff --git a/os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm b/os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm index 203a7ed3..e4ef657f 100644 --- a/os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm +++ b/os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm @@ -150,38 +150,42 @@ sub installationPhase elif grep -q ^flags.*\\\<svm\\\> /proc/cpuinfo; then module=kvm_amd else - unset module + module=kqemu fi End-of-Here my $do_start = unshiftHereDoc(<<' End-of-Here'); # loading kvm module + kvm_module [ -n "${module}" ] && modprobe -q ${module} # load the tunnel device module modprobe -q tun + # TODO: maybe in the ifup-script better solution? # configuring the tap0 interface to the existing bridge configured in stage3 - for i in 0 1 2; do - /opt/openslx/uclib-rootfs/sbin/tunctl -t tap${i} >/dev/null 2>&1 - ip link set dev tap${i} up - done - /opt/openslx/uclib-rootfs/usr/sbin/brctl addif br0 tap0 - ip addr add ${nataddress} dev tap1 - ip addr add ${hoaddress} dev tap2 - echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding - echo "1" >/proc/sys/net/ipv4/conf/tap0/forwarding + #for i in 0 1 2; do + # /opt/openslx/uclib-rootfs/sbin/tunctl -t tap${i} >/dev/null 2>&1 + # ip link set dev tap${i} up + #done + #/opt/openslx/uclib-rootfs/usr/sbin/brctl addif br0 tap0 + #ip addr add ${nataddress} dev tap1 + #ip addr add ${hoaddress} dev tap2 + #echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding + #echo "1" >/proc/sys/net/ipv4/conf/tap0/forwarding # make /dev/fb0 writable for all # TODO: maybe solve via group or udev, etc... chmod 766 /dev/fb* End-of-Here my $do_stop = unshiftHereDoc(<<' End-of-Here'); + kvm_module [ -n "${module}" ] && modprobe -q -r ${module} modprobe -q -r tun - /opt/openslx/uclib-rootfs/usr/sbin/brctl delif br0 tap0 - ip addr del ${nataddress} dev tap1 - ip addr del ${hoaddress} dev tap2 - echo "0" >/proc/sys/net/ipv4/conf/br0/forwarding - echo "0" >/proc/sys/net/ipv4/conf/tap0/forwarding + # TODO: tun removed, so this is not necessary + #/opt/openslx/uclib-rootfs/usr/sbin/brctl delif br0 tap0 + #ip addr del ${nataddress} dev tap1 + #ip addr del ${hoaddress} dev tap2 + #echo "0" >/proc/sys/net/ipv4/conf/br0/forwarding + #echo "0" >/proc/sys/net/ipv4/conf/tap0/forwarding chmod 760 /dev/fb* End-of-Here @@ -192,6 +196,7 @@ sub installationPhase # add helper functions to initfile # first parameter name of the function # second parameter content of the function + $initFile->addFunction('kvm_module', $kvm_module); $initFile->addFunction('do_start', $do_start); $initFile->addFunction('do_stop', $do_stop); $initFile->addFunction('do_restart', $do_restart); diff --git a/os-plugins/plugins/qemukvm/files/ifup b/os-plugins/plugins/qemukvm/files/ifup index ed4a277d..ee5fdecf 100644 --- a/os-plugins/plugins/qemukvm/files/ifup +++ b/os-plugins/plugins/qemukvm/files/ifup @@ -16,7 +16,10 @@ . /etc/opt/openslx/openslx.conf PLUGINCONFDIR=${OPENSLX_DEFAULT_CONFDIR}/plugins/qemukvm -QKTMPDIR=/tmp/qemukvm/$USER/$$ + +# get VM_ID through tap name +VM_ID=$(echo $1 | grep -oE "0[0-4]$") +QKTMPDIR=/tmp/qemukvm/${USER}/${VM_ID} # Use the udhcpcd as DHCP server and brctl as provided by default in OpenSLX # environments via uclibc-wrapper. @@ -25,34 +28,44 @@ QKTMPDIR=/tmp/qemukvm/$USER/$$ # Just decide by the virtual network device used which kind of connection # should be set up (passed in $1): tap0 = bridge, tap1 = nat, tap2 = hostonly. case "$1" in - tap0) + tapbridge0*) # Adding the tap0 interface to the existing bridge configured in stage3 - # brctl addif br0 tap0 + 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 ;; - tap1) + tapnat0*) # Configuring DHCP on host tap1 interface and enable IP masquerading - [ -d ${QKTMPDIR} ] || mkdir -p ${QKTMPDIR} - # cut the last .NNN/MM from nataddress - sed -e "s,NWIF,tap1,;s,/misc/,/qemu/," \ - -e "s,CNETWORK,${nataddress%.*},;s,PIDFILE,${QKTMPDIR}/udhcpd.pid," \ + sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t $1 >/dev/null 2>&1 + sudo ip addr add ${nataddress} dev $1 + # not necessary since already done by run-virt.include + #[ -d ${QKTMPDIR} ] || mkdir -p ${QKTMPDIR} + # cut the last .NNN/MM from nataddress ${natnetwork%.*} + # TODO: we use here atatic address, maybe change later + sed -e "s,NWIF,$1,;s,/misc/,/qemu/," \ + -e "s,CNETWORK,192.168.1${VM_ID}.254,;s,PIDFILE,${QKTMPDIR}/udhcpd.pid," \ -e "s,LEASEFILE,${QKTMPDIR}/udhcpd.leases," \ - ${OPENSLX_DEFAULT_CONFDIR}/udhcpd.conf \ - >${QKTMPDIR}/udhcpd.conf + ${OPENSLX_DEFAULT_CONFDIR}/udhcpd.conf \ + >${QKTMPDIR}/udhcpd.conf touch ${QKTMPDIR}/udhcpd.leases - # ip link set tap1 up - # ip addr add 192.168.101.254/24 dev tap1 + # 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 ;; - tap2) + taphost0*) # Configuring DHCP on host tap2 interface - [ -d ${QKTMPDIR} ] || mkdir -p /tmp/qemu-$USER - sed "s,NWIF,tap2,;s,/misc/,/qemu/,;s,USER,$USER,;s,CNETWORK,$hoaddress," \ + sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t $1 >/dev/null 2>&1 + sudo ip addr add ${hoaddress} dev $1 + [ -d ${QKTMPDIR} ] || mkdir -p ${QKTMPDIR} + sed "s,NWIF,$1,;s,/misc/,/qemu/,;s,USER,$USER,;s,CNETWORK,192.168.1${VM_ID}.254," \ ${OPENSLX_DEFAULT_CONFDIR}/udhcpd.conf >${QKTMPDIR}/udhcpd.conf touch ${QKTMPDIR}/udhcpd.leases - # ip link set tap2 up - # ip addr add 192.168.101.254/24 dev tap2 + # 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 ;; diff --git a/os-plugins/plugins/qemukvm/files/run-virt.include b/os-plugins/plugins/qemukvm/files/run-virt.include index 7db2bfc9..69c5dad4 100644 --- a/os-plugins/plugins/qemukvm/files/run-virt.include +++ b/os-plugins/plugins/qemukvm/files/run-virt.include @@ -74,10 +74,10 @@ writelog "\tDisk file:\t\t$diskfile" if [ -n "${forcemem}" ]; then mem="${forcemem}" else -# permem=30 -# if [ "${totalmem}" -ge "1600" ]; then -# permem=40 -# fi + permem=30 + if [ "${totalmem}" -ge "1600" ]; then + permem=40 + fi # # check if /tmp is on harddisk # if grep -qe "/dev/.* /tmp " /proc/mounts ; then # permem=60 @@ -95,12 +95,12 @@ else # #ln -sf ${snapshotdir} ${snapshotdirold} # #fi # fi -# mem=$(expr ${totalmem} / 100 \* ${permem}) -# if [ "${id44}" = "1" ]; then -# memhost=$(expr ${totalmem} - ${mem}) -# else -# memhost=$(expr ${totalmem} - ${mem} - ${mem}) -# fi + mem=$(expr ${totalmem} / 100 \* ${permem}) + if [ "${id44}" = "1" ]; then + memhost=$(expr ${totalmem} - ${mem}) + else + memhost=$(expr ${totalmem} - ${mem} - ${mem}) + fi # static first permem=50 mem=$(expr ${totalmem} / 100 \* ${permem}) @@ -118,16 +118,22 @@ network_card=${network_card:=pcnet} VIRTCMDOPTS="${VIRTCMDOPTS} -net nic,macaddr=${macaddr},model=${network_card}" # define net kind and apply script -qemu_ifscripts="script=${PLUGINDIRQK}/ifup,downscript=${PLUGINDIRQK}/ifdown" +qemu_ifscr="script=${PLUGINDIRQK}/ifup,downscript=${PLUGINDIRQK}/ifdown" case "${network_kind}" in bridge*) - VIRTCMDOPTS="${VIRTCMDOPTS} -net tap,ifname=tap0,${qemu_ifscripts}" + VIRTCMDOPTS="${VIRTCMDOPTS} -net tap,ifname=tapbridge${VM_ID},${qemu_ifscr}" + #sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t tapbridge${VM_ID} 2>/tmp/asdf + #sudo /opt/openslx/uclib-rootfs/usr/sbin/brctl addif br0 tapbridge${VM_ID} 2>>/tmp/asdf ;; NAT|nat) - VIRTCMDOPTS="${VIRTCMDOPTS} -net tap,ifname=tap1,${qemu_ifscripts}" + VIRTCMDOPTS="${VIRTCMDOPTS} -net tap,ifname=tapnat${VM_ID},${qemu_ifscr}" + #sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t tapbnat${VM_ID} 2>/tmp/asdf + #sudo /opt/openslx/uclib-rootfs/usr/sbin/brctl addif br0 tapnat${VM_ID} 2>>/tmp/asdf ;; hostonly|host-only) - VIRTCMDOPTS="${VIRTCMDOPTS} -net tap,ifname=tap2,${qemu_ifscripts}" + VIRTCMDOPTS="${VIRTCMDOPTS} -net tap,ifname=taphost${VM_ID},${qemu_ifscr}" + #sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t tapbhost${VM_ID} 2>/tmp/asdf + #sudo /opt/openslx/uclib-rootfs/usr/sbin/brctl addif br0 taphost${VM_ID} 2>>/tmp/asdf ;; *) network_kind="user" diff --git a/os-plugins/plugins/qemukvm/init-hooks/60-have-servconfig/vm-dhcpd.sh b/os-plugins/plugins/qemukvm/init-hooks/60-have-servconfig/vm-dhcpd.sh index 13771a43..396631c1 100755 --- a/os-plugins/plugins/qemukvm/init-hooks/60-have-servconfig/vm-dhcpd.sh +++ b/os-plugins/plugins/qemukvm/init-hooks/60-have-servconfig/vm-dhcpd.sh @@ -34,15 +34,15 @@ interface NWIF offer_time 6000 # location of the leases file -lease_file LEASEDIR/udhcpd.leases +lease_file LEASEFILE # location of the pid file -pidfile PIDFILE/udhcpd.pid +pidfile PIDFILE -opt dns ${domain_name_servers} +option dns ${domain_name_servers} option subnet 255.255.255.0 -opt router CNETWORK.254 -opt wins CNETWORK.10 +option router CNETWORK.254 +option wins CNETWORK.10 option domain virtual.site ${domain_name} # additional options known to udhcpd diff --git a/os-plugins/plugins/virtualbox/files/run-virt.include b/os-plugins/plugins/virtualbox/files/run-virt.include index abf1e0be..2a0b84a2 100644 --- a/os-plugins/plugins/virtualbox/files/run-virt.include +++ b/os-plugins/plugins/virtualbox/files/run-virt.include @@ -212,29 +212,25 @@ esac # translate boot, use if set else set to HardDisk # usually support for a,c,d,n, stands for Floppy, HD, CD-ROM, Network # support nfs and tftp as well -if [ -n "${boot}" ]; then - case ${boot} in - n*|tftp) - boot="Network" - if [ "${network_kind}" = "NAT" ] && [ -n "${virtualbox_tftpdir}" ]; then - # remove spaces from VM name to avoid Problems /w TFTP in NAT - vm_name=$(echo ${vm_name} | sed -e "s, ,-,g") - # link TFTP dir for NAT TFTP boots - mkdir -p ${confdir}/TFTP - cp ${virtualbox_tftpdir}/pxelinux.0 ${confdir}/TFTP/${vm_name}.pxe - for i in $(ls ${virtualbox_tftpdir}); do - ln -sf ${virtualbox_tftpdir}/${i} ${confdir}/TFTP/${i} - done - fi - ;; - # later maybe c|disk|hd*|sd*) for HD and d|cd*) for CD-ROM - *) - boot="HardDisk" - ;; - esac -else - boot="HardDisk" -fi +case ${boot} in + n*|tftp) + boot="Network" + if [ "${network_kind}" = "NAT" ] && [ -n "${virtualbox_tftpdir}" ]; then + # remove spaces from VM name to avoid Problems /w TFTP in NAT + vm_name=$(echo ${vm_name} | sed -e "s, ,-,g") + # link TFTP dir for NAT TFTP boots + mkdir -p ${confdir}/TFTP + cp ${virtualbox_tftpdir}/pxelinux.0 ${confdir}/TFTP/${vm_name}.pxe + for i in $(ls ${virtualbox_tftpdir}); do + ln -sf ${virtualbox_tftpdir}/${i} ${confdir}/TFTP/${i} + done + fi + ;; + # later maybe c|disk|hd*|sd*) for HD and d|cd*) for CD-ROM + *) + boot="HardDisk" + ;; +esac # external GUI vrdpport="590${VM_ID}" diff --git a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh index 716371d5..626dfcca 100644 --- a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh +++ b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh @@ -162,7 +162,7 @@ writelog "\tVM XML dir:\t\t$(dirname ${xmlfile})" if ! grep '<?xml' "${xmlfile}" >/dev/null 2>&1; then writelog \ - "\tSubmitted configuration file ${xmlfile} seems to have wrong XML format" + "Submitted configuration file ${xmlfile} seems to have wrong XML format" exit 1 fi @@ -208,7 +208,7 @@ fi # check if virtual machine container file exists, only if not rwimg if ! [ -e "${vmpath}" ] && [ "${imgmode}" != "rwimg" ] && [ ${diskless} -eq 0 ]; then - writelog "\tVirtual machine image or directory ${vmpath} not found!" + writelog "Virtual machine image or directory ${vmpath} not found!" exit 1 fi @@ -239,8 +239,8 @@ xmlvirt=$(grep -o 'virtualmachine param=.*"' ${xmlfile} \ # make a guess from the filename extension if ${xmlvirt} is empty # (not set within the XML file) if [ -z "${xmlvirt}" ] && [ -n "${additional_config}" ]; then - writelog "\tNo virtual machine parameter defined in ${xmlfile}" - writelog "\tTrying to guess VM...\c" + writelog "No virtual machine parameter defined in ${xmlfile}" + writelog "Trying to guess VM...\c" case "$(cat ${additional_config} | tr [A-Z] [a-z])" in *config.version*|*virtualhw.version*|*independent-nonpersistent*|*vmdk*) xmlvirt="vmware" @@ -275,8 +275,8 @@ fi # check for virt if [ "${vmgrid_virt}" != "${xmlvirt}" ]; then - writelog "\tThe virtual machine specified in ${xmlfile}" - writelog "\tdoes not match the virtualization used here (${vmgrid_virt})" + writelog "The virtual machine specified in ${xmlfile}" + writelog "does not match the virtualization used here (${vmgrid_virt})" exit 1 fi diff --git a/os-plugins/plugins/xen/files/machine.include b/os-plugins/plugins/xen/files/machine.include index a1573578..06848949 100644 --- a/os-plugins/plugins/xen/files/machine.include +++ b/os-plugins/plugins/xen/files/machine.include @@ -58,7 +58,7 @@ vif = [ '${xen_vif}' ] # where UNAME is the device, DEV is the device name the domain will see, # and MODE is r for read-only, w for read-write. # disk = [ 'phy:hda1,hda1,w' ] -disk = [ '${xen_disk}' ] +${xen_disk} #---------------------------------------------------------------------------- # Define frame buffer device. diff --git a/os-plugins/plugins/xen/files/run-virt.include b/os-plugins/plugins/xen/files/run-virt.include index 40cca17a..43213e34 100644 --- a/os-plugins/plugins/xen/files/run-virt.include +++ b/os-plugins/plugins/xen/files/run-virt.include @@ -43,13 +43,10 @@ conffile=${confdir}/${vm_name} rm -rf ${confdir} 2>/dev/null mkdir -p ${confdir} 2>/dev/null -# TODO: read from XML file xen_kernel=${kernel:-"/boot/vmlinuz-xen"} xen_ramdisk=${initramfs:-"/boot/initrd-xen"} xen_extra="xencons=tty 3" -xen_disk="file:${vmpath},hda1,r" -xen_vif="mac=$macaddr, bridge=br0" -xen_dhcp="dhcp" # off +[ -n "${imgname}" ] && xen_disk="disk = [ 'file:${vmpath},hda1,r' ]" writelog "Directories:" writelog "\tConfig dir:\t\t$confdir" @@ -99,33 +96,41 @@ else fi fi -xen::tftpdir +# translate network kinds (nat, bridged, host-only) +case "${network_kind}" in + bridge*) + xen_vif="mac=$macaddr, bridge=br0" + ;; + *) + xen_vif="mac=$macaddr" +esac +xen_dhcp="dhcp" # off + # translate boot, use if set else set to disk -if [ -n "${boot}" ]; then - case ${boot} in - n*|tftp) - if [ -n "${imgname}" ] && [ -n "${xen_tftpdir}" ]; then - root=/dev/nfs - tftp_label=$(grep -A 3 "^LABEL *${imgname}" \ - ${xen_tftpdir}/pxelinux.cfg/default 2>/dev/null \ - | grep "^ *KERNEL ") - xen_kernel="${xen_tftpdir}/$(echo ${tftp_label} \ +xen_root=/dev/hda1 +case ${boot} in + n*|tftp) + pxe_label=$(grep -o 'pxe_label param=.*"' ${xmlfile} \ + | sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') + pxe_label=$(grep -A 3 "^LABEL *${pxe_label}" \ + ${xen_tftpdir}/pxelinux.cfg/default 2>/dev/null \ + | grep "^ *KERNEL ") + if [ -n "${pxe_label}" ] && [ -n "${xen_tftpdir}" ]; then + xen_root=/dev/nfs + xen_kernel="${xen_tftpdir}/$(echo ${pxe_label} \ | awk -F " --- " '{print $2}' | awk '{print $1}')" - xen_ramdisk="${xen_tftpdir}/$(echo ${tftp_label} \ + xen_ramdisk="${xen_tftpdir}/$(echo ${pxe_label} \ | awk -F " --- " '{print $3}')" - fi - ;; - # later maybe c|disk|hd*|sd*) for HD and d|cd*) for CD-ROM - *) - xen_root=/dev/hda1 - ;; - esac -else - xen_root=/dev/hda1 -fi + fi + ;; + # later maybe c|disk|hd*|sd*) for HD and d|cd*) for CD-ROM + *) + xen_root=/dev/hda1 + ;; +esac -writelog "Diskimage:" -writelog "\tMachine diskfile:\t$vmpath" +[ ${diskless} -eq 0 ] && writelog "Diskimage:" +[ ${diskless} -eq 0 ] && writelog "\tMachine diskfile:\t$vmpath" writelog "Virtual Hardware:" writelog "\tGuest RAM:\t\t${mem} MB" # echo nur wenn memhost gesetzt |