From 60bee60e6acbe08dfce92a9160a77860c00856ab Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sun, 17 Feb 2008 15:55:22 +0000 Subject: * added support to listing the plugins that have been installed into a specific vendor-OS * several small fixes and improvements git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1558 95ad53e4-c205-0410-b2fa-d234c58c8868 --- os-plugins/OpenSLX/OSPlugin/Engine.pm | 142 ++++++++++++++++++++-------------- os-plugins/slxos-plugin | 56 +++++++++++--- 2 files changed, 130 insertions(+), 68 deletions(-) (limited to 'os-plugins') diff --git a/os-plugins/OpenSLX/OSPlugin/Engine.pm b/os-plugins/OpenSLX/OSPlugin/Engine.pm index b96673fb..fe9efd8f 100644 --- a/os-plugins/OpenSLX/OSPlugin/Engine.pm +++ b/os-plugins/OpenSLX/OSPlugin/Engine.pm @@ -42,20 +42,22 @@ sub initialize my $pluginName = shift; my $vendorOSName = shift; - $self->{'plugin-name'} = $pluginName; - $self->{'vendor-os-name'} = $vendorOSName; + $self->{'vendor-os-name'} = $vendorOSName; $self->{'vendor-os-path'} = "$openslxConfig{'private-path'}/stage1/$vendorOSName"; vlog(1, "vendor-OS path is '$self->{'vendor-os-path'}'"); - $self->{'plugin-path'} - = "$openslxConfig{'base-path'}/lib/plugins/$pluginName"; - vlog(1, "plugin path is '$self->{'plugin-path'}'"); - - $self->{'plugin'} = $self->_loadPlugin(); - return if !$self->{'plugin'}; + if ($pluginName) { + $self->{'plugin-name'} = $pluginName; + $self->{'plugin-path'} + = "$openslxConfig{'base-path'}/lib/plugins/$pluginName"; + vlog(1, "plugin path is '$self->{'plugin-path'}'"); + $self->{'plugin'} = $self->_loadPlugin(); + return if !$self->{'plugin'}; + } + return 1; } @@ -63,34 +65,35 @@ sub installPlugin { my $self = shift; - # create ossetup-engine for given vendor-OS: - my $osSetupEngine = OpenSLX::OSSetup::Engine->new; - $osSetupEngine->initialize($self->{'vendor-os-name'}, 'plugin'); - $self->{'os-setup-engine'} = $osSetupEngine; - $self->{'distro-name'} = $osSetupEngine->{'distro-name'}; - - my $chrootedPluginRepoPath - = "$openslxConfig{'base-path'}/plugin-repo/$self->{'plugin-name'}"; - my $pluginRepoPath = "$self->{'vendor-os-path'}/$chrootedPluginRepoPath"; - my $chrootedPluginTempPath = "/tmp/slx-plugin/$self->{'plugin-name'}"; - my $pluginTempPath = "$self->{'vendor-os-path'}/$chrootedPluginTempPath"; - foreach my $path ($pluginRepoPath, $pluginTempPath) { - if (slxsystem("mkdir -p $path")) { - croak(_tr("unable to create path '%s'! (%s)", $path, $!)); + if ($self->{'vendor-os-name'} ne '<<>>') { + # create ossetup-engine for given vendor-OS: + my $osSetupEngine = OpenSLX::OSSetup::Engine->new; + $osSetupEngine->initialize($self->{'vendor-os-name'}, 'plugin'); + $self->{'os-setup-engine'} = $osSetupEngine; + + my $chrootedPluginRepoPath + = "$openslxConfig{'base-path'}/plugin-repo/$self->{'plugin-name'}"; + my $pluginRepoPath = "$self->{'vendor-os-path'}/$chrootedPluginRepoPath"; + my $chrootedPluginTempPath = "/tmp/slx-plugin/$self->{'plugin-name'}"; + my $pluginTempPath = "$self->{'vendor-os-path'}/$chrootedPluginTempPath"; + foreach my $path ($pluginRepoPath, $pluginTempPath) { + if (slxsystem("mkdir -p $path")) { + croak(_tr("unable to create path '%s'! (%s)", $path, $!)); + } } - } - - $self->{plugin}->preInstallationPhase($pluginRepoPath, $pluginTempPath); - $self->{'os-setup-engine'}->callChrootedFunctionForVendorOS( - sub { - $self->{plugin}->installationPhase( - $chrootedPluginRepoPath, $chrootedPluginTempPath - ); - } - ); - - $self->{plugin}->postInstallationPhase($pluginRepoPath, $pluginTempPath); + $self->{plugin}->preInstallationPhase($pluginRepoPath, $pluginTempPath); + + $self->{'os-setup-engine'}->callChrootedFunctionForVendorOS( + sub { + $self->{plugin}->installationPhase( + $chrootedPluginRepoPath, $chrootedPluginTempPath + ); + } + ); + + $self->{plugin}->postInstallationPhase($pluginRepoPath, $pluginTempPath); + } $self->_addInstalledPluginToDB(); @@ -108,40 +111,61 @@ sub removePlugin { my $self = shift; - # create ossetup-engine for given vendor-OS: - my $osSetupEngine = OpenSLX::OSSetup::Engine->new; - $osSetupEngine->initialize($self->{'vendor-os-name'}, 'plugin'); - $self->{'os-setup-engine'} = $osSetupEngine; - $self->{'distro-name'} = $osSetupEngine->{'distro-name'}; - - my $chrootedPluginRepoPath - = "$openslxConfig{'base-path'}/plugin-repo/$self->{'plugin-name'}"; - my $pluginRepoPath = "$self->{'vendor-os-path'}/$chrootedPluginRepoPath"; - my $chrootedPluginTempPath = "/tmp/slx-plugin/$self->{'plugin-name'}"; - my $pluginTempPath = "$self->{'vendor-os-path'}/$chrootedPluginTempPath"; - foreach my $path ($pluginRepoPath, $pluginTempPath) { - if (slxsystem("mkdir -p $path")) { - croak(_tr("unable to create path '%s'! (%s)", $path, $!)); - } - } - - $self->{plugin}->preRemovalPhase($pluginRepoPath, $pluginTempPath); + if ($self->{'vendor-os-name'} ne '<<>>') { + # create ossetup-engine for given vendor-OS: + my $osSetupEngine = OpenSLX::OSSetup::Engine->new; + $osSetupEngine->initialize($self->{'vendor-os-name'}, 'plugin'); + $self->{'os-setup-engine'} = $osSetupEngine; - $self->{'os-setup-engine'}->callChrootedFunctionForVendorOS( - sub { - $self->{plugin}->removalPhase( - $chrootedPluginRepoPath, $chrootedPluginTempPath - ); + my $chrootedPluginRepoPath + = "$openslxConfig{'base-path'}/plugin-repo/$self->{'plugin-name'}"; + my $pluginRepoPath = "$self->{'vendor-os-path'}/$chrootedPluginRepoPath"; + my $chrootedPluginTempPath = "/tmp/slx-plugin/$self->{'plugin-name'}"; + my $pluginTempPath = "$self->{'vendor-os-path'}/$chrootedPluginTempPath"; + foreach my $path ($pluginRepoPath, $pluginTempPath) { + if (slxsystem("mkdir -p $path")) { + croak(_tr("unable to create path '%s'! (%s)", $path, $!)); + } } - ); - $self->{plugin}->postRemovalPhase($pluginRepoPath, $pluginTempPath); + $self->{plugin}->preRemovalPhase($pluginRepoPath, $pluginTempPath); + + $self->{'os-setup-engine'}->callChrootedFunctionForVendorOS( + sub { + $self->{plugin}->removalPhase( + $chrootedPluginRepoPath, $chrootedPluginTempPath + ); + } + ); + + $self->{plugin}->postRemovalPhase($pluginRepoPath, $pluginTempPath); + } $self->_removeInstalledPluginFromDB(); return 1; } +sub getInstalledPlugins +{ + 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 @installedPlugins = $openslxDB->fetchInstalledPlugins($vendorOS->{id}); + $openslxDB->disconnect(); + + return @installedPlugins; +} + sub _loadPlugin { my $self = shift; diff --git a/os-plugins/slxos-plugin b/os-plugins/slxos-plugin index ba407994..8400ecf7 100755 --- a/os-plugins/slxos-plugin +++ b/os-plugins/slxos-plugin @@ -59,8 +59,9 @@ openslxInit(); my $action = shift @ARGV || ''; -if ($action =~ m[^list]i) { - my @pluginFolders = glob("$openslxConfig{'base-path'}/lib/plugins/*"); +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(); @@ -84,10 +85,34 @@ if ($action =~ m[^list]i) { } sort keys %$pluginInfo ); +} elsif ($action =~ m[^list-i]i) { + if (scalar(@ARGV) != 1) { + print STDERR _tr( + "You need to specify exactly one vendor-OS!\n" + ); + pod2usage(2); + } + my $vendorOSName = shift @ARGV; + + # 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 vendor-OS and ask it for the installed + # plugins: + my $engine = OpenSLX::OSPlugin::Engine->new; + $engine->initialize(undef, $vendorOSName); + my @installedPlugins = $engine->getInstalledPlugins(); + if (!@installedPlugins) { + push @installedPlugins, ''; + } + print _tr("List of plugins installed in vendor-OS '$vendorOSName':\n"); + print join('', map { "\t$_\n" } sort @installedPlugins); } elsif ($action =~ m[^install]i) { if (scalar(@ARGV) != 2) { print STDERR _tr( - "You need to specify exactly one plugin-name and one vendor-os!\n" + "You need to specify exactly one plugin-name and one vendor-OS!\n" ); pod2usage(2); } @@ -106,15 +131,19 @@ if ($action =~ m[^list]i) { die _tr("plugin '%s' doesn't exist, giving up!\n", $engine->{'plugin-path'}); } - if (!-e $engine->{'vendor-os-path'}) { + if ($vendorOSName ne '<<>>' && !-e $engine->{'vendor-os-path'}) { die _tr("vendor-OS '%s' doesn't exist, giving up!\n", $engine->{'vendor-os-path'}); } - $engine->installPlugin(); + if ($engine->installPlugin()) { + print _tr( + "Plugin $pluginName has been installed into vendor-OS '$vendorOSName'.\n" + ); + } } elsif ($action =~ m[^remove]i) { if (scalar(@ARGV) != 2) { print STDERR _tr( - "You need to specify exactly one plugin-name and one vendor-os!\n" + "You need to specify exactly one plugin-name and one vendor-OS!\n" ); pod2usage(2); } @@ -133,16 +162,21 @@ if ($action =~ m[^list]i) { die _tr("plugin '%s' doesn't exist, giving up!\n", $engine->{'plugin-path'}); } - if (!-e $engine->{'vendor-os-path'}) { + if ($vendorOSName ne '<<>>' && !-e $engine->{'vendor-os-path'}) { die _tr("vendor-OS '%s' doesn't exist, giving up!\n", $engine->{'vendor-os-path'}); } - $engine->removePlugin(); + 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: - list-available install + list-available + list-installed remove Try '%s --help' for more info. END-OF-HERE @@ -176,6 +210,10 @@ installs the OS-plugin with the given name into the specified vendor-OS list all available OS-plugins +=item B<< list-installed >> + +list all the plugins installed into the specified vendor-OS + =item B<< remove >> removes the OS-plugin with the given name from the specified vendor-OS -- cgit v1.2.3-55-g7522