summaryrefslogtreecommitdiffstats
path: root/os-plugins/OpenSLX
diff options
context:
space:
mode:
authorOliver Tappe2008-01-08 16:50:42 +0100
committerOliver Tappe2008-01-08 16:50:42 +0100
commit530745cf3fd1c50be2c89a0f101ea8fc5bac2e9a (patch)
treec6a7f3c0a2b47296e169bceabbc088ed9b76f136 /os-plugins/OpenSLX
parent* minor fix (VERSION) (diff)
downloadcore-530745cf3fd1c50be2c89a0f101ea8fc5bac2e9a.tar.gz
core-530745cf3fd1c50be2c89a0f101ea8fc5bac2e9a.tar.xz
core-530745cf3fd1c50be2c89a0f101ea8fc5bac2e9a.zip
* implemented automatic synchronization of new/changed attributes (either
from core or plugins) into the default system * reworked the way plugins pass out their attribute info git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1451 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'os-plugins/OpenSLX')
-rw-r--r--os-plugins/OpenSLX/OSPlugin/Base.pm130
-rw-r--r--os-plugins/OpenSLX/OSPlugin/Engine.pm52
-rw-r--r--os-plugins/OpenSLX/OSPlugin/Roster.pm56
3 files changed, 238 insertions, 0 deletions
diff --git a/os-plugins/OpenSLX/OSPlugin/Base.pm b/os-plugins/OpenSLX/OSPlugin/Base.pm
new file mode 100644
index 00000000..0f2123d7
--- /dev/null
+++ b/os-plugins/OpenSLX/OSPlugin/Base.pm
@@ -0,0 +1,130 @@
+# Copyright (c) 2006, 2007 - OpenSLX GmbH
+#
+# This program is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your suggestions, praise, or complaints to feedback@openslx.org
+#
+# General information about OpenSLX can be found at http://openslx.org/
+# -----------------------------------------------------------------------------
+# Base.pm
+# - provides empty base of the OpenSLX OSPlugin API.
+# -----------------------------------------------------------------------------
+package OpenSLX::OSPlugin::Base;
+
+use strict;
+use warnings;
+
+our $VERSION = 1.01; # API-version . implementation-version
+
+use OpenSLX::Basics;
+
+################################################################################
+# if you have any questions regarding the concept of OS-plugins and their
+# implementation, please drop a mail to: ot@openslx.com, or join the IRC-channel
+# '#openslx' (on freenode).
+################################################################################
+
+sub new
+{
+ confess "Creating OpenSLX::OSPlugin::Base-objects directly makes no sense!";
+}
+
+sub initialize
+{
+ my $self = shift;
+
+ # The os-plugin-engine drives us, it provides some useful services relevant
+ # to installing stuff into the vendor-OS, like downloading functionality,
+ # access to meta-packager, ...
+ $self->{'os-plugin-engine'} = shift;
+}
+
+sub getInfo
+{ # returns a hash-ref with administrative information about this plugin
+ # (what does it do and how does it relate to other plugins)
+ my $self = shift;
+
+ return {
+ # a short (one-liner) description of this plugin
+ description => '',
+ # a list of plugins that must have completed before this plugin can
+ # be executed
+ mustRunAfter => [],
+ };
+}
+
+sub getAttrInfo
+{ # returns a hash-ref with information about all attributes supported
+ # by this specific plugin
+ my $self = shift;
+
+ # This default configuration will be added as attributes to the default
+ # system, such that it can be overruled for any specific system & client
+ # by means of slxconfig.
+ return {
+ # attribute 'active' is mandatory for all plugins
+ # attribute 'precedence' is mandatory for all plugins
+ };
+}
+
+sub preInstallationPhase
+{ # called before chrooting into vendor-OS root, should be used if any files
+ # have to be downloaded outside of the chroot (which might be necessary
+ # if the required files can't be installed via the meta-packager)
+ my $self = shift;
+ my $pluginRepositoryPath = shift;
+ # the folder where the stage1-plugin should store all files
+ # required by the corresponding stage3 runlevel script
+ my $pluginTempPath = shift;
+ # a temporary playground that will be cleaned up automatically
+}
+
+sub installationPhase
+{ # called while chrooted to the vendor-OS root, most plugins will do all
+ # their installation work here
+ my $self = shift;
+ my $pluginRepositoryPath = shift;
+ # the repository folder, this time from inside the chroot
+ my $pluginTempPath = shift;
+ # the temporary folder, this time from inside the chroot
+}
+
+sub postInstallationPhase
+{ # called after having returned from chrooted environment, should be used
+ # to cleanup any leftovers, if any such thing is necessary
+ my $self = shift;
+ my $pluginRepositoryPath = shift;
+ my $pluginTempPath = shift;
+}
+
+sub preRemovalPhase
+{ # called before chrooting into vendor-OS root, should be used if any
+ # preparations outside of the chroot have to be made before the plugin
+ # can be removed
+ my $self = shift;
+ my $pluginRepositoryPath = shift;
+ # the folder where the stage1-plugin has stored all files
+ # required by the corresponding stage3 runlevel script
+ my $pluginTempPath = shift;
+ # a temporary playground that will be cleaned up automatically
+}
+
+sub removalPhase
+{ # called while chrooted to the vendor-OS root, most plugins will do all
+ # their uninstallation work here
+ my $self = shift;
+ my $pluginRepositoryPath = shift;
+ # the repository folder, this time from inside the chroot
+ my $pluginTempPath = shift;
+ # the temporary folder, this time from inside the chroot
+}
+
+sub postRemovalPhase
+{ # called after having returned from chrooted environment, should be used
+ # to cleanup any leftovers, if any such thing is necessary
+ my $self = shift;
+ my $pluginRepositoryPath = shift;
+ my $pluginTempPath = shift;
+}
diff --git a/os-plugins/OpenSLX/OSPlugin/Engine.pm b/os-plugins/OpenSLX/OSPlugin/Engine.pm
index 57850229..bdf259f4 100644
--- a/os-plugins/OpenSLX/OSPlugin/Engine.pm
+++ b/os-plugins/OpenSLX/OSPlugin/Engine.pm
@@ -64,6 +64,9 @@ sub initialize
vlog(1, "plugin path is '$self->{'plugin-path'}'");
$self->{'plugin'} = $self->_loadPlugin();
+ return if !$self->{'plugin'};
+
+ return 1;
}
sub installPlugin
@@ -98,6 +101,10 @@ sub installPlugin
);
$self->{plugin}->postInstallationPhase($pluginRepoPath, $pluginTempPath);
+
+ $self->_addInstalledPluginToDB();
+
+ return 1;
}
sub getPlugin
@@ -119,6 +126,51 @@ sub _loadPlugin
my $plugin = instantiateClass(
$pluginModule, { pathToClass => $self->{'plugin-path'} }
);
+ return if !$plugin;
+
$plugin->initialize($self);
+
return $plugin;
}
+
+sub _addInstalledPluginToDB
+{
+ 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'}
+ );
+ }
+ $openslxDB->addInstalledPlugin($vendorOS->{id}, $self->{'plugin-name'});
+ $openslxDB->disconnect();
+
+ return 1;
+}
+
+sub _removeInstalledPluginFromDB
+{
+ 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'}
+ );
+ }
+ $openslxDB->removeInstalledPlugin($vendorOS->{id}, $self->{'plugin-name'});
+ $openslxDB->disconnect();
+
+ return 1;
+}
+
+1;
diff --git a/os-plugins/OpenSLX/OSPlugin/Roster.pm b/os-plugins/OpenSLX/OSPlugin/Roster.pm
new file mode 100644
index 00000000..776907e4
--- /dev/null
+++ b/os-plugins/OpenSLX/OSPlugin/Roster.pm
@@ -0,0 +1,56 @@
+# Copyright (c) 2006, 2007 - OpenSLX GmbH
+#
+# This program is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your suggestions, praise, or complaints to feedback@openslx.org
+#
+# General information about OpenSLX can be found at http://openslx.org/
+# -----------------------------------------------------------------------------
+# OSPlugin::Roster.pm
+# - provides information about all available plugins
+# -----------------------------------------------------------------------------
+package OpenSLX::OSPlugin::Roster;
+
+use strict;
+use warnings;
+
+use OpenSLX::Basics;
+
+=item C<addAllDefaultAttributesToHash()>
+
+Fetches attribute info from all available plugins and adds it to the given
+hash-ref.
+
+=over
+
+=item Return Value
+
+1
+
+=back
+
+=cut
+
+sub addAllDefaultAttributesToHash
+{
+ my $class = shift;
+ my $attrInfo = shift;
+
+ my $pluginPath = "$openslxConfig{'base-path'}/lib/plugins";
+ foreach my $modulePath (glob("$pluginPath/*")) {
+ next if $modulePath !~ m{/([^/]+)$};
+ my $pluginName = $1;
+ my $class = "OpenSLX::OSPlugin::$pluginName";
+ vlog(2, "loading plugin $class from path '$modulePath'");
+ my $plugin = instantiateClass($class, { pathToClass => $modulePath });
+ my $pluginAttrInfo = $plugin->getAttrInfo();
+ foreach my $attr (keys %$pluginAttrInfo) {
+ $attrInfo->{$attr} = $pluginAttrInfo->{$attr};
+ }
+ }
+ return 1;
+}
+
+1;