blob: 791865f1a5104fb0815558b7a2e096be4fe2868e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# 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;
use Storable qw(dclone);
my %plugins;
=item C<getAvailablePlugins()>
Returns a hash that keys the names of available plugins to their info hash.
=cut
sub getAvailablePlugins
{
my $class = shift;
$class->_init() if !%plugins;
my %pluginInfo;
foreach my $pluginName (keys %plugins) {
$pluginInfo{$pluginName} = $plugins{$pluginName}->getInfo();
}
return \%pluginInfo;
}
=item C<getPlugin()>
Returns an instance of the plugin with the given name
=cut
sub getPlugin
{
my $class = shift;
my $pluginName = shift;
$class->_init() if !%plugins;
my $plugin = $plugins{$pluginName};
return if !$plugin;
return dclone($plugin);
}
=item C<getPluginAttrInfo()>
Returns a hash that contains info about the attributes support by the
given plugin
=cut
sub getPluginAttrInfo
{
my $class = shift;
my $pluginName = shift;
$class->_init() if !%plugins;
return if !$plugins{$pluginName};
return $plugins{$pluginName}->getAttrInfo();
}
=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;
$class->_init() if !%plugins;
foreach my $plugin (values %plugins) {
my $pluginAttrInfo = $plugin->getAttrInfo();
foreach my $attr (keys %$pluginAttrInfo) {
$attrInfo->{$attr} = $pluginAttrInfo->{$attr};
}
}
return 1;
}
sub _init
{
my $class = shift;
%plugins = ();
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 });
$plugins{$pluginName} = $plugin;
}
return;
}
1;
|