From 431e6e2f2811dc277feaca90f52466d623a74b0b Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Fri, 14 Mar 2008 22:49:57 +0000 Subject: * added support for stage1 attributes that are stored along each plugin installed into a vendor-OS. * an update of the slxos-plugin documentation is still missing (coming soon ;-) git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1633 95ad53e4-c205-0410-b2fa-d234c58c8868 --- os-plugins/OpenSLX/OSPlugin/Engine.pm | 50 +++++- os-plugins/OpenSLX/OSPlugin/Roster.pm | 8 +- .../plugins/vmware/OpenSLX/OSPlugin/vmware.pm | 18 ++- os-plugins/slxos-plugin | 169 +++++++++++++++------ 4 files changed, 189 insertions(+), 56 deletions(-) (limited to 'os-plugins') diff --git a/os-plugins/OpenSLX/OSPlugin/Engine.pm b/os-plugins/OpenSLX/OSPlugin/Engine.pm index 23d3d953..d42141a7 100644 --- a/os-plugins/OpenSLX/OSPlugin/Engine.pm +++ b/os-plugins/OpenSLX/OSPlugin/Engine.pm @@ -67,6 +67,7 @@ sub initialize my $self = shift; my $pluginName = shift; my $vendorOSName = shift; + my $givenAttrs = shift || {}; $self->{'vendor-os-name'} = $vendorOSName; @@ -92,6 +93,27 @@ sub initialize $self->{'plugin-temp-path'} = "$self->{'vendor-os-path'}/$self->{'chrooted-plugin-temp-path'}"; $self->{'chrooted-openslx-base-path'} = '/mnt/openslx'; + + # check and store given attribute set + my $knownAttrs = $self->{plugin}->getAttrInfo(); + my @unknownAttrs + = grep { !exists $knownAttrs->{$_} } keys %$givenAttrs; + if (@unknownAttrs) { + die _tr( + "The plugin '%s' does not support these attributes:\n\t%s", + $pluginName, join(',', @unknownAttrs) + ); + } + $self->{'plugin-attrs'} = $givenAttrs; + my $defaultAttrs = $self->{plugin}->getAttrInfo(); + my $dbAttrs = $self->_fetchInstalledPluginAttrs($vendorOSName); + for my $attrName (keys %$defaultAttrs) { + next if exists $givenAttrs->{$attrName}; + $self->{'plugin-attrs'}->{$attrName} + = exists $dbAttrs->{$attrName} + ? $dbAttrs->{$attrName} + : $defaultAttrs->{$attrName}->{default}; + } } return 1; @@ -124,6 +146,7 @@ sub installPlugin $self->{'chrooted-plugin-repo-path'}, $self->{'chrooted-plugin-temp-path'}, $self->{'chrooted-openslx-base-path'}, + $self->{'plugin-attrs'}, ); } ); @@ -426,12 +449,37 @@ sub _addInstalledPluginToDB 'unable to find vendor-OS "%s" in DB!', $self->{'vendor-os-name'} ); } - $openslxDB->addInstalledPlugin($vendorOS->{id}, $self->{'plugin-name'}); + $openslxDB->addInstalledPlugin( + $vendorOS->{id}, $self->{'plugin-name'}, $self->{'plugin-attrs'} + ); $openslxDB->disconnect(); return 1; } +sub _fetchInstalledPluginAttrs +{ + my $self = shift; + + my $openslxDB = instantiateClass("OpenSLX::ConfigDB"); + $openslxDB->connect(); + my $vendorOS = $openslxDB->fetchVendorOSByFilter( { + name => $self->{'vendor-os-name'}, + } ); + if (!$vendorOS) { + die _tr( + 'unable to find vendor-OS "%s" in DB!', $self->{'vendor-os-name'} + ); + } + my $installedPlugin = $openslxDB->fetchInstalledPlugins( + $vendorOS->{id}, $self->{'plugin-name'} + ); + $openslxDB->disconnect(); + + return {} if !$installedPlugin; + return $installedPlugin->{attrs}; +} + sub _removeInstalledPluginFromDB { my $self = shift; diff --git a/os-plugins/OpenSLX/OSPlugin/Roster.pm b/os-plugins/OpenSLX/OSPlugin/Roster.pm index 8bc2c305..bacbd183 100644 --- a/os-plugins/OpenSLX/OSPlugin/Roster.pm +++ b/os-plugins/OpenSLX/OSPlugin/Roster.pm @@ -78,10 +78,10 @@ sub getPluginAttrInfo return $plugins{$pluginName}->getAttrInfo(); } -=item C +=item C -Fetches attribute info from all available plugins and adds it to the given -hash-ref. +Fetches attribute info relevant for stage3 (i.e. system- or client-attributes) +from all available plugins and adds it to the given hash-ref. =over @@ -93,7 +93,7 @@ hash-ref. =cut -sub addAllDefaultAttributesToHash +sub addAllStage3AttributesToHash { my $class = shift; my $attrInfo = shift; diff --git a/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm b/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm index af4df603..7a9a57cb 100644 --- a/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm +++ b/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm @@ -75,7 +75,7 @@ sub getAttrInfo End-of-Here content_regex => qr{^\d\d$}, content_descr => 'allowed range is from 01-99', - default => 70, + default => '70', }, # attribute 'imagesrc' defines where we can find vmware images 'vmware::imagessrc' => { @@ -84,9 +84,21 @@ sub getAttrInfo description => unshiftHereDoc(<<' End-of-Here'), Where do we store our vmware images? NFS? Filesystem? End-of-Here - content_regex => qr{^\d\d$}, content_descr => 'Allowed values: path or URI', - default => "", + default => '', + }, + # attribute 'binaries' defines whether or not VMware binaries shall + # be provided (by downloading them). + 'vmware::binaries' => { + applies_to_vendor_os => 1, + applies_to_systems => 0, + applies_to_clients => 0, + description => unshiftHereDoc(<<' End-of-Here'), + Shall VMware binaries be downloaded and installed? + End-of-Here + content_regex => qr{^(0|1)$}, + content_descr => 'Allowed values: 0 or 1', + default => '1', }, }; diff --git a/os-plugins/slxos-plugin b/os-plugins/slxos-plugin index 8400ecf7..db7767a0 100755 --- a/os-plugins/slxos-plugin +++ b/os-plugins/slxos-plugin @@ -60,8 +60,6 @@ openslxInit(); my $action = shift @ARGV || ''; if ($action =~ m[^list-a]i) { - my @pluginFolders - = grep { -d $_ } glob("$openslxConfig{'base-path'}/lib/plugins/*"); print _tr("List of available plugins:\n"); require OpenSLX::OSPlugin::Roster; my $pluginInfo = OpenSLX::OSPlugin::Roster->getAvailablePlugins(); @@ -104,77 +102,117 @@ if ($action =~ m[^list-a]i) { my $engine = OpenSLX::OSPlugin::Engine->new; $engine->initialize(undef, $vendorOSName); my @installedPlugins = $engine->getInstalledPlugins(); + if (!@installedPlugins) { - push @installedPlugins, ''; + push @installedPlugins, { plugin_name => '' }; } print _tr("List of plugins installed in vendor-OS '$vendorOSName':\n"); - print join('', map { "\t$_\n" } sort @installedPlugins); + print join( + '', + map { + if ($option{verbose}) { + my $attributes + = _tr("The following attributes were applied:") + . "\n\t "; + my $pluginAttrs = $_->{attrs}; + $attributes .= join( + "\n\t ", + map { + $_ . '=' + . ( + defined $pluginAttrs->{$_} + ? $pluginAttrs->{$_} + : '-' + ) + } + sort keys %$pluginAttrs + ); + "\n\t$_->{plugin_name}\n\t $attributes\n"; + } + else { + "\t$_->{plugin_name}\n"; + } + } + sort @installedPlugins + ); } elsif ($action =~ m[^install]i) { - if (scalar(@ARGV) != 2) { + if (scalar(@ARGV) < 2) { print STDERR _tr( - "You need to specify exactly one plugin-name and one vendor-OS!\n" + "You need to specify a vendor-OS and at least one plugin-name!\n" ); pod2usage(2); } - my $pluginName = shift @ARGV; my $vendorOSName = shift @ARGV; + my $pluginAttrs = parsePluginAttrs(1); # we chdir into the script's folder such that all relative paths have # a known starting point: chdir($FindBin::RealBin) or die _tr("can't chdir to script-path <%> (%s)", $FindBin::RealBin, $!); - # create OSPlugin-engine for given plugin and vendor-OS and start it: - my $engine = OpenSLX::OSPlugin::Engine->new; - $engine->initialize($pluginName, $vendorOSName); - if (!-e $engine->{'plugin-path'}) { - die _tr("plugin '%s' doesn't exist, giving up!\n", - $engine->{'plugin-path'}); - } - if ($vendorOSName ne '<<>>' && !-e $engine->{'vendor-os-path'}) { - die _tr("vendor-OS '%s' doesn't exist, giving up!\n", - $engine->{'vendor-os-path'}); - } - if ($engine->installPlugin()) { - print _tr( - "Plugin $pluginName has been installed into vendor-OS '$vendorOSName'.\n" + for my $pluginName (keys %$pluginAttrs) { + # create & start OSPlugin-engine for vendor-OS and current plugin: + my $engine = OpenSLX::OSPlugin::Engine->new; + $engine->initialize( + $pluginName, $vendorOSName, $pluginAttrs->{$pluginName} ); + if (!-e $engine->{'plugin-path'}) { + die _tr("plugin '%s' doesn't exist, giving up!\n", + $engine->{'plugin-path'}); + } + if ($vendorOSName ne '<<>>' + && !-e $engine->{'vendor-os-path'}) { + die _tr( + "vendor-OS '%s' doesn't exist, giving up!\n", + $engine->{'vendor-os-path'} + ); + } + if ($engine->installPlugin()) { + print _tr( + "Plugin $pluginName has been installed into vendor-OS '$vendorOSName'.\n" + ); + } } } elsif ($action =~ m[^remove]i) { - if (scalar(@ARGV) != 2) { + if (scalar(@ARGV) < 2) { print STDERR _tr( - "You need to specify exactly one plugin-name and one vendor-OS!\n" + "You need to specify a vendor-OS and at least one plugin-name!\n" ); pod2usage(2); } - my $pluginName = shift @ARGV; my $vendorOSName = shift @ARGV; + my $pluginAttrs = parsePluginAttrs(0); # we chdir into the script's folder such that all relative paths have # a known starting point: chdir($FindBin::RealBin) or die _tr("can't chdir to script-path <%> (%s)", $FindBin::RealBin, $!); - # create OSPlugin-engine for given plugin and vendor-OS and start it: - my $engine = OpenSLX::OSPlugin::Engine->new; - $engine->initialize($pluginName, $vendorOSName); - if (!-e $engine->{'plugin-path'}) { - die _tr("plugin '%s' doesn't exist, giving up!\n", - $engine->{'plugin-path'}); - } - if ($vendorOSName ne '<<>>' && !-e $engine->{'vendor-os-path'}) { - die _tr("vendor-OS '%s' doesn't exist, giving up!\n", - $engine->{'vendor-os-path'}); - } - if ($engine->removePlugin()) { - print _tr( - "Plugin $pluginName has been removed from vendor-OS '$vendorOSName'.\n" + for my $pluginName (keys %$pluginAttrs) { + # create & start OSPlugin-engine for vendor-OS and current plugin: + my $engine = OpenSLX::OSPlugin::Engine->new; + $engine->initialize( + $pluginName, $vendorOSName, $pluginAttrs->{$pluginName} ); + if (!-e $engine->{'plugin-path'}) { + die _tr("plugin '%s' doesn't exist, giving up!\n", + $engine->{'plugin-path'}); + } + if ($vendorOSName ne '<<>>' && !-e $engine->{'vendor-os-path'}) { + die _tr("vendor-OS '%s' doesn't exist, giving up!\n", + $engine->{'vendor-os-path'}); + } + if ($engine->removePlugin()) { + print _tr( + "Plugin $pluginName has been removed from vendor-OS '$vendorOSName'.\n" + ); + } } } else { vlog(0, _tr(unshiftHereDoc(<<' END-OF-HERE'), $0)); You need to specify exactly one action: install + list-attributes list-available list-installed remove @@ -182,6 +220,38 @@ if ($action =~ m[^list-a]i) { END-OF-HERE } +sub parsePluginAttrs +{ + my $acceptAttributes = shift; + + my (%pluginAttrs, $pluginName, @attrSpecs); + for my $arg (@ARGV) { + if ($arg =~ m{^(.+)=(.*)$}) { + next if !$acceptAttributes; + my $attr = $1; + my $value = $2; + if ($value =~ m{^(-|undef)$}) { + $value = undef; + } + if ($attr =~ m{^(.+)::}) { + $pluginName = $1; + } + else { + if (!defined $pluginName) { + die _tr('You have to give a plugin-name before you can specify unscoped attributes!'); + } + $attr = $pluginName . '::' . $attr; + } + $pluginAttrs{$pluginName}->{$attr} = $value; + } + else { + $pluginName = $arg; + $pluginAttrs{$pluginName} = {}; + } + } + return \%pluginAttrs; +} + =head1 NAME slxos-plugin - OpenSLX-script to install/remove an OS-plugin into/from an @@ -202,21 +272,24 @@ slxos-plugin [options] =over 8 -=item B<< install >> +=item B<< install [= ...] [] ... >> -installs the OS-plugin with the given name into the specified vendor-OS +installs the OS-plugin(s) with the given name(s) into the specified +vendor-OS, using any attribute values as specified =item B<< list-available >> -list all available OS-plugins +list all available OS-plugins, in verbose mode all the supported attributes +are shown, too. =item B<< list-installed >> -list all the plugins installed into the specified vendor-OS +list all the plugins installed into the specified vendor-OS, in verbose mode +all applied attributes are shown, too. -=item B<< remove >> +=item B<< remove [] ... >> -removes the OS-plugin with the given name from the specified vendor-OS +removes the OS-plugin(s) with the given name(s) from the specified vendor-OS =back @@ -261,9 +334,9 @@ Prints the version and exits. =head3 Installing a Plugin -=item B<< slxos-plugin install Example suse-10.2 >> +=item B<< slxos-plugin install suse-10.2 example >> -installs the plugin named 'Example' into the installed vendor-OS 'suse-10.2'. +installs the plugin named 'example' into the installed vendor-OS 'suse-10.2'. =back @@ -271,9 +344,9 @@ installs the plugin named 'Example' into the installed vendor-OS 'suse-10.2'. =over 8 -=item B<< slxos-plugin remove Example suse-10.2 >> +=item B<< slxos-plugin remove suse-10.2 example >> -removes the plugin named 'Example' from the installed vendor-OS 'suse-10.2'. +removes the plugin named 'example' from the installed vendor-OS 'suse-10.2'. =back -- cgit v1.2.3-55-g7522