diff options
author | Dirk von Suchodoletz | 2009-08-19 10:34:28 +0200 |
---|---|---|
committer | Dirk von Suchodoletz | 2009-08-19 10:34:28 +0200 |
commit | 4124137d36998c6aef7f73e6e9c756c288e673e2 (patch) | |
tree | a905e02dc7ebcdc973b0fecfc691d0381e75888b /os-plugins | |
parent | No need to use the uclib-wrapper any more (see r3099). (diff) | |
download | core-4124137d36998c6aef7f73e6e9c756c288e673e2.tar.gz core-4124137d36998c6aef7f73e6e9c756c288e673e2.tar.xz core-4124137d36998c6aef7f73e6e9c756c288e673e2.zip |
Heavily renovated qemukvm plugin (especially the networking part).
git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@3101 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'os-plugins')
-rw-r--r-- | os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm | 63 | ||||
-rw-r--r-- | os-plugins/plugins/qemukvm/XX_qemukvm.sh | 19 | ||||
-rw-r--r-- | os-plugins/plugins/qemukvm/files/qemu-ifdown | 6 | ||||
-rw-r--r-- | os-plugins/plugins/qemukvm/files/qemu-ifup | 36 |
4 files changed, 80 insertions, 44 deletions
diff --git a/os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm b/os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm index 54a91935..23a14924 100644 --- a/os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm +++ b/os-plugins/plugins/qemukvm/OpenSLX/OSPlugin/qemukvm.pm @@ -23,6 +23,7 @@ use File::Path; use OpenSLX::Basics; use OpenSLX::Utils; +use OpenSLX::DistroUtils; sub new { @@ -110,6 +111,7 @@ sub installationPhase $self->{attrs} = $info->{'plugin-attrs'}; my $engine = $self->{'os-plugin-engine'}; + my $pluginRepoPath = "$self->{pluginRepositoryPath}"; # Different names of the tool (should be unified somehow!?) if (!isInPath('qemu-kvm') || !isInPath('kvm')) { @@ -117,12 +119,56 @@ sub installationPhase $engine->getInstallablePackagesForSelection('qemu-kvm') ); } + # Sudo is needed to get access to certain system network commands + if (!isInPath('sudo')) { + $engine->installPackages($self->{distro}->getPackageName('sudo')); + } # Copy run-virt.include to the appropriate place for inclusion in stage4 copyFile("$self->{openslxBasePath}/lib/plugins/qemukvm/files/run-virt.include", "$self->{pluginRepositoryPath}/"); - # Copy the later /etc/qemu-ifup + # Copy the later /etc/qemu-ifup,down copyFile("$self->{openslxBasePath}/lib/plugins/qemukvm/files/qemu-if*", "$self->{pluginRepositoryPath}/"); + + my $initFile = newInitFile(); + $initfile->setDesc("Setup environment for QEMU/KVM"); + my $do_start = unshiftHereDoc(<<' End-of-Here'); + # Adding 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 + echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding + echo "1" >/proc/sys/net/ipv4/conf/tap0/forwarding + End-of-Here + my $do_stop = unshiftHereDoc(<<' End-of-Here'); + /opt/openslx/uclib-rootfs/usr/sbin/brctl delif br0 tap0 + echo "0" >/proc/sys/net/ipv4/conf/br0/forwarding + echo "0" >/proc/sys/net/ipv4/conf/tap0/forwarding + End-of-Here + + # add helper functions to initfile + # first parameter name of the function + # second parameter content of the function + $initFile->addFunction('do_start', $do_start); + $initFile->addFunction('do_stop', $do_stop); + $initFile->addFunction('do_restart', " : # do nothing here"); + + # place a call of the helper function in the stop block of the init file + # first parameter name of the function + # second parameter name of the block + $initFile->addFunctionCall('do_start', 'start'); + $initFile->addFunctionCall('do_stop', 'stop'); + $initFile->addFunctionCall('do_restart', 'restart'); + + my $distro = (split('-',$self->{'os-plugin-engine'}->distroName()))[0]; + + # write qemukvm initfile to plugin path + spitFile( + "$pluginRepoPath/qemukvm", + getInitFileForDistro($initFile, ucfirst($distro)) + ); return; } @@ -146,21 +192,6 @@ sub checkStage3AttrValues return; } -# Write the runlevelscript -sub _writeRunlevelScript -{ - my $self = shift; - my $location = shift; - my $file = shift; - my $kind = shift; - - # should use the abstract write runlevel script way, see - # http://lab.openslx.org/repositories/revision/openslx/2405 ff. - my $runlevelScript = $self->{distro}->fillRunlevelScript($location, $kind); - - spitFile($file, $runlevelScript); -} - # The bridge configuration needs the bridge module to be present in early # stage3 sub suggestAdditionalKernelModules diff --git a/os-plugins/plugins/qemukvm/XX_qemukvm.sh b/os-plugins/plugins/qemukvm/XX_qemukvm.sh index c5efd89b..be82be2c 100644 --- a/os-plugins/plugins/qemukvm/XX_qemukvm.sh +++ b/os-plugins/plugins/qemukvm/XX_qemukvm.sh @@ -28,10 +28,10 @@ interface NWIF offer_time 6000 # The location of the leases file -lease_file /var/lib/qemu/udhcpd.leases +lease_file /tmp/qemu-USER/udhcpd.leases # The location of the pid file -pidfile /var/run/udhcpd.pid +pidfile /tmp/qemu-USER/udhcpd.pid opt dns ${domain_name_servers} option subnet 255.255.255.0 @@ -111,19 +111,24 @@ ${qemukvm_imagesrc}." nonfatal # create a template udhcpd configuration file write_udhcpd_conf /mnt/etc/opt/openslx/udhcpd.qemukvm - # for the busybox dhcp server - testmkd /mnt/var/lib/qemu - touch /mnt/var/lib/qemu/udhcpd.leases + # copy the runlevel script (proper place for all distros??) + cp /mnt/opt/openslx/plugin-repo/qemukvm/qemukvm /mnt/etc/init.d + rllinker "qemukvm" 22 2 # copy the /etc/qemu-ifup script and enable extended rights for running - # the emulator via sudo + # the emulator and certain network commands via sudo cp /mnt/opt/openslx/plugin-repo/qemukvm/qemu-if* /mnt/etc - chmod u+x /mnt/etc/qemu-if* + chmod 0755 /mnt/etc/qemu-if* /mnt/etc/init.d/qemukvm for qemubin in qemu kvm ; do qemu="$(binfinder ${qemubin})" [ -n "${qemu}" ] && \ echo "ALL ALL=NOPASSWD: ${qemu}" >>/mnt/etc/sudoers done + echo -e "#ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/sbin/tunctl -t tap*\n\ +#ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/sbin/ip addr add * dev tap*\n\ +#ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/usr/sbin/brctl addif br0 tap*\n\ +ALL ALL=NOPASSWD: /opt/openslx/uclib-rootfs/usr/sbin/udhcpd -S /tmp/qemu*" \ + >>/mnt/etc/sudoers fi else [ $DEBUGLEVEL -gt 0 ] && echo " * Configuration of qemukvm plugin failed" diff --git a/os-plugins/plugins/qemukvm/files/qemu-ifdown b/os-plugins/plugins/qemukvm/files/qemu-ifdown index f146c2d9..8c52d76f 100644 --- a/os-plugins/plugins/qemukvm/files/qemu-ifdown +++ b/os-plugins/plugins/qemukvm/files/qemu-ifdown @@ -17,12 +17,12 @@ case "$1" in tap1) - # Bringing down the tap1 interface + # Bringing down the dhcp server killall udhcpd 2>/dev/null - iptables -t nat -D POSTROUTING -o br0 -j MASQUERADE 2>/dev/null + #iptables -t nat -D POSTROUTING -o br0 -j MASQUERADE 2>/dev/null ;; tap2) - # Bringing down the tap1 interface + # Bringing down the dhcp server killall udhcpd 2>/dev/null ;; esac diff --git a/os-plugins/plugins/qemukvm/files/qemu-ifup b/os-plugins/plugins/qemukvm/files/qemu-ifup index c51e6a9b..75ef3e4b 100644 --- a/os-plugins/plugins/qemukvm/files/qemu-ifup +++ b/os-plugins/plugins/qemukvm/files/qemu-ifup @@ -21,30 +21,30 @@ case "$1" in tap0) # Adding the tap0 interface to the existing bridge configured in stage3 - uclibc-wrapper brctl addif br0 tap0 + # brctl addif br0 tap0 ;; tap1) # Configuring DHCP on host tap1 interface and enable IP masquerading - [ -d /var/lib/qemu ] || mkdir -p /var/lib/qemu - sed "s,NWIF,tap1,;s,/misc/,/qemu/," /etc/opt/openslx/udhcpd.qemukvm \ - >/var/lib/qemu/udhcpd.conf - touch /var/lib/qemu/udhcpd.leases - uclibc-wrapper ip link set tap1 up - uclibc-wrapper ip addr add 192.168.101.254/24 dev tap1 - uclibc-wrapper udhcpd -S /var/lib/qemu/udhcpd.conf - echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding - echo "1" >/proc/sys/net/ipv4/conf/tap1/forwarding - iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE + [ -d /tmp/qemu-$USER ] || mkdir -p /tmp/qemu-$USER + sed "s,NWIF,tap1,;s,/misc/,/qemu/,;s,USER,$USER," \ + /etc/opt/openslx/udhcpd.qemukvm >/tmp/qemu-$USER/udhcpd.conf + touch /tmp/qemu-$USER/qemu/udhcpd.leases + # ip link set tap1 up + # ip addr add 192.168.101.254/24 dev tap1 + sudo /opt/openslx/uclib-rootfs/usr/sbin/udhcpd \ + -S /tmp/qemu-$USER/qemu/udhcpd.conf + # iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE ;; tap2) # Configuring DHCP on host tap2 interface - [ -d /var/lib/qemu ] || mkdir -p /var/lib/qemu - sed "s,NWIF,tap1,;s,/misc/,/qemu/," /etc/opt/openslx/udhcpd.qemukvm \ - >/var/lib/qemu/udhcpd.conf - touch /var/lib/qemu/udhcpd.leases - uclibc-wrapper ip link set tap2 up - uclibc-wrapper ip addr add 192.168.101.254/24 dev tap2 - uclibc-wrapper udhcpd -S /var/lib/qemu/udhcpd.conf + [ -d /tmp/qemu-$USER ] || mkdir -p /tmp/qemu-$USER + sed "s,NWIF,tap2,;s,/misc/,/qemu/,;s,USER,$USER," \ + /etc/opt/openslx/udhcpd.qemukvm >/tmp/qemu-$USER/udhcpd.conf + touch /tmp/qemu-$USER/qemu/udhcpd.leases + # ip link set tap2 up + # ip addr add 192.168.101.254/24 dev tap2 + sudo /opt/openslx/uclib-rootfs/usr/sbin/udhcpd \ + -S /tmp/qemu-$USER/qemu/udhcpd.conf ;; esac |