From 8366523dedf9197d58c2c7030d98f2b7d470d06c Mon Sep 17 00:00:00 2001 From: Dirk von Suchodoletz Date: Thu, 11 Feb 2010 00:45:43 +0100 Subject: Cleaning up the runlevel mess of vmware plugin ... Not finished yet. --- .../plugins/vmware/OpenSLX/OSPlugin/vmware.pm | 136 ++++++++++++++++++--- 1 file changed, 122 insertions(+), 14 deletions(-) (limited to 'os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm') diff --git a/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm b/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm index 1a4540f0..8cf1c7ab 100644 --- a/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm +++ b/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm @@ -1,4 +1,4 @@ -# Copyright (c) 2008, 2009 - OpenSLX GmbH +# Copyright (c) 2008..2010 - OpenSLX GmbH # # This program is free software distributed under the GPL version 2. # See http://openslx.org/COPYING @@ -23,6 +23,7 @@ use File::Path; use OpenSLX::Basics; use OpenSLX::Utils; +use OpenSLX::DistroUtils; sub new { @@ -131,12 +132,12 @@ sub getAttrInfo applies_to_clients => 1, description => unshiftHereDoc(<<' End-of-Here'), Which set of VMware binaries to use: installed (local) or provided by the - plugin itself (vmpl1.0, vmpl2.0, vmpl2.5)? + plugin itself (vmpl1.0, vmpl2.0, vmpl2.5, vmpl3.0)? End-of-Here # only allow the supported once... # TODO: modify if we know which of them work #content_regex => qr{^(local|vmws(5\.5|6.0)|vmpl(1\.0|2\.0))$}, - content_regex => qr{^(local|vmpl2\.0|vmpl1\.0|vmpl2\.5)$}, + content_regex => qr{^(local|vmpl3\.0||vmpl2\.0|vmpl1\.0|vmpl2\.5)$}, content_descr => 'Allowed values: local, vmpl2.0', #TODO: what if we don't have a local installation. default # is still local. Someone has a clue how to test @@ -300,6 +301,8 @@ sub installationPhase if (-e "/usr/bin/vmware" && ! -e "/usr/bin/vmware.slx-bak") { rename("/usr/bin/vmware", "/usr/bin/vmware.slx-bak"); } + # write the runlevel script + $self->_writeRunlevelScript(); } sub removalPhase @@ -374,21 +377,126 @@ sub checkStage3AttrValues ## local, non-general OpenSLX functions ####################################### -# write the runlevelscript depending on the version +# Write the runlevelscript sub _writeRunlevelScript { my $self = shift; - my $location = shift; - my $file = shift; - my $kind = shift; - - # $location points to the path where vmware helpers are installed - # call the distrospecific fillup - # 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); + my $kind = $self->{attrs}->{'vmware::kind'} || 'local'; + my $initfile = newInitFile(); + my %versionhash = (vmversion => "", vmbuildversion => ""); + my $vmversion = ""; - spitFile($file, $runlevelScript); + my $script = ""; + my $vmpath = ""; + my $modpath = ""; + my $modlist = ""; + if ($kind =~ /local*/) { + $vmpath = "/"; + $modpath = "/lib/modules/\$(uname -r)/misc"; + } elsif ($kind =~ /vmpl*/) { + $vmpath = "/opt/openslx/plugin-repo/vmware/${kind}"; + $modpath = "${vmpath}/vmroot/modules"; + } + + %versionhash = _getVersion("${vmpath}/usr/bin"); + $vmversion = $versionhash{vmversion}; + $initfile->setName("vmware-slx"); + $initfile->setDesc("Setup environment for VMware Workstation or Player ($vmversion)."); + + # functions ... + $modlist = "vmnet vmmon"; + $script = unshiftHereDoc(<<" End-of-Here"); + # VMplayer common stuff + insmod ${modpath}/vmmon.ko || return 1 + insmod ${modpath}/vmnet.ko || return 1 + End-of-Here + if ($kind eq 'local30' || $kind eq 'vmpl3.0') { + $script .= unshiftHereDoc(<<" End-of-Here"); + # VMplayer 3.0 specific stuff + insmod ${modpath}/vsock.ko || return 1 + insmod ${modpath}/vmci.ko || return 1 + insmod ${modpath}/vmblock.ko || return 1 + End-of-Here + $modlist .= "vsock vmci vmblock"; + } elsif ($kind eq 'local20' || $kind eq 'vmpl2.0' || $kind eq 'vmpl2.5') { + $script .= unshiftHereDoc(<<" End-of-Here"); + # VMplayer 2.X specific stuff + insmod ${modpath}/vmblock.ko + End-of-Here + $modlist .= "vmblock"; + } + $initfile->addFunction( + "load_modules", + "$script" + ); + $initfile->addFunction( + "unload_modules", + "rmmod $modlist 2>/dev/null" + ); + # vmnet interface definition + $script = unshiftHereDoc(<<" End-of-Here"); + if [ -n "\$vmnet1" ] ; then + # the path might be directly point to the plugin dir + location=$vmpath + \$location/usr/bin/vmnet-netifup -d /var/run/vmnet-netifup-vmnet1.pid \\ + /dev/vmnet1 vmnet1 + dhcpif="\$dhcpif vmnet1" + ip addr add \$vmnet1 dev vmnet1 + ip link set vmnet1 up + if [ -n "\$vmnet1nat" ] ; then + echo "1" > /proc/sys/net/ipv4/conf/vmnet1/forwarding 2>/dev/null + echo "1" > /proc/sys/net/ipv4/conf/br0/forwarding 2>/dev/null + #iptables -A -s vmnet1 -d br0 + fi + \$location/vmnet-dhcpd -cf /etc/vmware/dhcpd-vmnet1.conf \\ + -lf /var/run/vmware/dhcpd-vmnet1.leases \\ + -pf /var/run/vmnet-dhcpd-vmnet1.pid vmnet1 2>/dev/null # or logfile + fi + End-of-Here + $initfile->addFunction( + "vmnetif", + "$script" + ); + $script = unshiftHereDoc(<<" End-of-Here"); + # include default directories + . /etc/opt/openslx/openslx.conf + # load the configuration file + . \${OPENSLX_DEFAULT_CONFDIR}/plugins/vmware/vmware.conf + # hack to access the first serial/parallel port + chmod a+rw /dev/ttyS0 + chmod a+rw /dev/parport0 + load_modules + vmnetif + End-of-Here + $initfile->addToCase( + "start", + "$script" + ); + $script = unshiftHereDoc(<<" End-of-Here"); + killall vmnet-netifup vmnet-natd vmnet-bridge vmware vmplayer \\ + vmware-tray vmnet-dhcpd 2>/dev/null + # might take a while until all services are shut down + sleep 1 + unload_modules + End-of-Here + $initfile->addToCase( + "stop", + "$script" + ); + $initfile->addToCase( + 'status', + 'vmstatus' + ); + $initfile->addToCase( + 'restart', + 'stop && start' + ); + + my $distro = (split('-',$self->{'os-plugin-engine'}->distroName()))[0]; + my $runlevelscript = getInitFileForDistro($initfile, $distro); + # todo: because we dont have distribution or version dependend + # init scripts we could put it directly into /etc/init.d... + spitFile("$self->{'pluginRepositoryPath'}/vmware-slx", $runlevelscript); } -- cgit v1.2.3-55-g7522