summaryrefslogtreecommitdiffstats
path: root/config-db/OpenSLX/AttributeRoster.pm
diff options
context:
space:
mode:
authorOliver Tappe2008-01-07 15:58:13 +0100
committerOliver Tappe2008-01-07 15:58:13 +0100
commit175275655abd8a7a3db3c3a1dfc5ee49a6488307 (patch)
treec0ce7654c9d9228e8bb7ff472cd99364f3d40176 /config-db/OpenSLX/AttributeRoster.pm
parentmore refactoring (not limited to attribute handling) (diff)
downloadcore-175275655abd8a7a3db3c3a1dfc5ee49a6488307.tar.gz
core-175275655abd8a7a3db3c3a1dfc5ee49a6488307.tar.xz
core-175275655abd8a7a3db3c3a1dfc5ee49a6488307.zip
* finished refactoring of attribute handling code, especially the
merging of attributes, such that all tests are passed * tested and finished implementation of group support in slxconfig * added new class AttributeRoster which keeps track of the known attributes (the ones provided by the openslx core and any other ones that may have been added by some plugin). * added new option --list-attributes to slxconfig which shows information about all known attributes git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1444 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'config-db/OpenSLX/AttributeRoster.pm')
-rw-r--r--config-db/OpenSLX/AttributeRoster.pm126
1 files changed, 126 insertions, 0 deletions
diff --git a/config-db/OpenSLX/AttributeRoster.pm b/config-db/OpenSLX/AttributeRoster.pm
new file mode 100644
index 00000000..46b90f74
--- /dev/null
+++ b/config-db/OpenSLX/AttributeRoster.pm
@@ -0,0 +1,126 @@
+# 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/
+# -----------------------------------------------------------------------------
+# AttributeRoster.pm
+# - provides information about all available attributes
+# -----------------------------------------------------------------------------
+package OpenSLX::AttributeRoster;
+
+use strict;
+use warnings;
+
+our (@ISA, @EXPORT, $VERSION);
+
+use Exporter;
+$VERSION = 0.2;
+@ISA = qw(Exporter);
+
+@EXPORT = qw(
+ $%AttributeInfo
+);
+
+use OpenSLX::Basics;
+
+################################################################################
+###
+### Load the available AttrInfo-modules and build a hash containing info about
+### all known attributes from the data contained in those modules.
+###
+################################################################################
+
+my %AttributeInfo = ();
+
+my $libPath = "$openslxConfig{'base-path'}/lib";
+foreach my $module (glob("$libPath/OpenSLX/AttrInfo/*.pm")) {
+ next if $module !~ m{/([^/]+)\.pm$};
+ my $class = "OpenSLX::AttrInfo::$1";
+ vlog(2, "loading attr-info from module '$module'");
+ my $instance = instantiateClass($class);
+ my $attrInfo = $instance->AttrInfo();
+ foreach my $attr (keys %$attrInfo) {
+ $AttributeInfo{$attr} = $attrInfo->{$attr};
+ }
+}
+
+=item C<getAttrInfo()>
+
+Returns info about all attributes.
+
+=over
+
+=item Return Value
+
+An hash-ref with info about all known attributes.
+
+=back
+
+=cut
+
+sub getAttrInfo
+{
+ my $class = shift;
+ my $name = shift;
+
+ if (defined $name) {
+ my $attrInfo = $AttributeInfo{$name};
+ return if !defined $attrInfo;
+ return { $name => $AttributeInfo{$name} };
+ }
+
+ return \%AttributeInfo;
+}
+
+=item C<getSystemAttrs()>
+
+Returns the attribute names that apply to systems.
+
+=over
+
+=item Return Value
+
+An array of attribute names.
+
+=back
+
+=cut
+
+sub getSystemAttrs
+{
+ my $class = shift;
+
+ return
+ grep { $AttributeInfo{$_}->{"applies_to_systems"} }
+ keys %AttributeInfo
+}
+
+=item C<getClientAttrs()>
+
+Returns the attribute names that apply to clients.
+
+=over
+
+=item Return Value
+
+An array of attribute names.
+
+=back
+
+=cut
+
+sub getClientAttrs
+{
+ my $class = shift;
+
+ return
+ grep { $AttributeInfo{$_}->{"applies_to_clients"} }
+ keys %AttributeInfo
+}
+
+1;