From bc8dfbba0983cb320bfaa5c1b294bb6923ac48c0 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Wed, 19 Mar 2008 00:03:17 +0000 Subject: * added separate class methods for adding stage1-, stage3- or all attributes to a given hash and simplified the implementation git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1654 95ad53e4-c205-0410-b2fa-d234c58c8868 --- os-plugins/OpenSLX/OSPlugin/Roster.pm | 84 ++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 5 deletions(-) (limited to 'os-plugins') diff --git a/os-plugins/OpenSLX/OSPlugin/Roster.pm b/os-plugins/OpenSLX/OSPlugin/Roster.pm index 991bb64d..a8df3b38 100644 --- a/os-plugins/OpenSLX/OSPlugin/Roster.pm +++ b/os-plugins/OpenSLX/OSPlugin/Roster.pm @@ -78,11 +78,71 @@ sub getPluginAttrInfo return $plugins{$pluginName}->getAttrInfo(); } +=item C + +Fetches attribute info from all available plugins and adds it to the given +hash-ref. + +If a plugin name has been given, only the attributes of that plugin will be +added. + +=over + +=item Return Value + +1 + +=back + +=cut + +sub addAllAttributesToHash +{ + my $class = shift; + my $attrInfo = shift; + my $pluginName = shift; + + return $class->_addAttributesToHash($attrInfo, $pluginName, sub { 1 } ); +} + +=item C + +Fetches attribute info relevant for stage1 (i.e. vendor-OS-attributes) +from all available plugins and adds it to the given hash-ref. + +If a plugin name has been given, only the attributes of that plugin will be +added. + +=over + +=item Return Value + +1 + +=back + +=cut + +sub addAllStage1AttributesToHash +{ + my $class = shift; + my $attrInfo = shift; + my $pluginName = shift; + + return $class->_addAttributesToHash($attrInfo, $pluginName, sub { + my $attr = shift; + return $attr->{applies_to_vendor_os}; + } ); +} + =item C Fetches attribute info relevant for stage3 (i.e. system- or client-attributes) from all available plugins and adds it to the given hash-ref. +If a plugin name has been given, only the attributes of that plugin will be +added. + =over =item Return Value @@ -95,17 +155,31 @@ from all available plugins and adds it to the given hash-ref. sub addAllStage3AttributesToHash { - my $class = shift; - my $attrInfo = shift; + my $class = shift; + my $attrInfo = shift; + my $pluginName = shift; + + return $class->_addAttributesToHash($attrInfo, $pluginName, sub { + my $attr = shift; + return $attr->{applies_to_systems} || $attr->{applies_to_clients}; + } ); +} + +sub _addAttributesToHash +{ + my $class = shift; + my $attrInfo = shift; + my $pluginName = shift; + my $testFunc = shift; $class->_init() if !%plugins; foreach my $plugin (values %plugins) { + next if $pluginName && $plugin->{name} ne $pluginName; my $pluginAttrInfo = $plugin->getAttrInfo(); foreach my $attr (keys %$pluginAttrInfo) { - next if !$pluginAttrInfo->{$attr}->{applies_to_systems} - && !$pluginAttrInfo->{$attr}->{applies_to_clients}; - $attrInfo->{$attr} = $pluginAttrInfo->{$attr}; + next if !$testFunc->($pluginAttrInfo->{$attr}); + $attrInfo->{$attr} = dclone($pluginAttrInfo->{$attr}); } } return 1; -- cgit v1.2.3-55-g7522