diff options
| author | Oliver Tappe | 2008-05-22 22:01:34 +0200 |
|---|---|---|
| committer | Oliver Tappe | 2008-05-22 22:01:34 +0200 |
| commit | 2a614b1103699d60e7e2999030d64e2adc9a6955 (patch) | |
| tree | 0e0ffd2962e5835f08e3749d258cd36d9e3a7a79 /config-db | |
| parent | * supress lib error while giving vmware its own font config (diff) | |
| download | core-2a614b1103699d60e7e2999030d64e2adc9a6955.tar.gz core-2a614b1103699d60e7e2999030d64e2adc9a6955.tar.xz core-2a614b1103699d60e7e2999030d64e2adc9a6955.zip | |
* attributes set via slxconfig are now being checked not only against the respective
regex, but the corresponding plugin is being invoked to do a check of its own, too
(where it has the chance to look at the vendor-OS attributes and determine the
possible stage3-values from their state).
* listing a vendor-OS in verbose mode now shows the vendor-OS attributes (stage1 &
stage3), too
* used Clone::clone instead of Storable::dclone since the latter is not capable of
cloning compiled regexes
git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1783 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'config-db')
| -rw-r--r-- | config-db/OpenSLX/AttributeRoster.pm | 71 | ||||
| -rwxr-xr-x | config-db/slxconfig | 49 |
2 files changed, 79 insertions, 41 deletions
diff --git a/config-db/OpenSLX/AttributeRoster.pm b/config-db/OpenSLX/AttributeRoster.pm index 331ac70c..13c7640d 100644 --- a/config-db/OpenSLX/AttributeRoster.pm +++ b/config-db/OpenSLX/AttributeRoster.pm @@ -17,6 +17,7 @@ use strict; use warnings; use OpenSLX::Basics; +use OpenSLX::OSPlugin::Engine; use OpenSLX::OSPlugin::Roster; use OpenSLX::Utils; @@ -370,6 +371,8 @@ sub _init # and add all plugin attributes, too OpenSLX::OSPlugin::Roster->addAllStage3AttributesToHash(\%AttributeInfo); + + return 1; } =item C<getAttrInfo()> @@ -495,43 +498,57 @@ sub getClientAttrs keys %AttributeInfo } -=item C<checkValueForKey()> +=item C<checkValues()> -Checks if the given value is allowed (and makes sense) for the given key. -If the value is ok, this method returns 1 - if not, it dies with an appropriate -message. +Checks if the given stage3 attribute values are allowed (and make sense). +If all values are ok, this method returns 1 - if not, it dies with an +appropriate message. =cut -sub checkValueForKey +sub checkValues { - my $class = shift; - my $key = shift; - my $value = shift; + my $class = shift; + my $stage3Attrs = shift || {}; + my $vendorOSName = shift or die ('need vendor-OS-name!'); $class->_init() if !%AttributeInfo; - # undefined values are always allowed - return 1 if !defined $value; - - # check the value against the regex of the attribute (if any) - my $attrInfo = $AttributeInfo{$key} - || die _tr('attribute "%s" is unknown!', $key); - my $regex = $attrInfo->{content_regex}; - if ($regex && $value !~ m{$regex}) { - die _tr( - "value given for attribute %s is not allowed.\nAllowed values are: %s", - $key, $attrInfo->{content_descr} - ); + my %attrsByPlugin; + foreach my $key (sort keys %{$stage3Attrs}) { + my $value = $stage3Attrs->{$key}; + if ($key =~ m{^(.+)::.+?$}) { + my $pluginName = $1; + $attrsByPlugin{$pluginName} ||= {}; + $attrsByPlugin{$pluginName}->{$key} = $value; + } + + # undefined values are always allowed + next if !defined $value; + + # check the value against the regex of the attribute (if any) + my $attrInfo = $AttributeInfo{$key} + || die _tr('attribute "%s" is unknown!', $key); + my $regex = $attrInfo->{content_regex}; + if ($regex && $value !~ $regex) { + die _tr( + "the value '%s' for attribute %s is not allowed.\nAllowed values are: %s", + $value, $key, $attrInfo->{content_descr} + ); + } } - # let plugin check by itself - if ($key =~ m{^(.+)::.+?$}) { - my $pluginName = $1; - my $plugin - = OpenSLX::OSPlugin::Roster->getPlugin($pluginName) - || die _tr('unable to load plugin "%s"', $pluginName); - $plugin->checkValueForKey($key, $value); + # now give each plugin a chance to check it's own attributes by itself + foreach my $pluginName (sort keys %attrsByPlugin) { + # create & start OSPlugin-engine for vendor-OS and current plugin + my $engine = OpenSLX::OSPlugin::Engine->new; + $engine->initialize($pluginName, $vendorOSName); + if (!$engine->{'plugin-path'}) { + warn _tr('unable to create engine for plugin "%s"!', $pluginName); + next; + } + $engine->checkStage3AttrValues($attrsByPlugin{$pluginName}); } } + 1; diff --git a/config-db/slxconfig b/config-db/slxconfig index 4414d2db..5592e06d 100755 --- a/config-db/slxconfig +++ b/config-db/slxconfig @@ -20,10 +20,10 @@ slxconfig and you can create clients for these systems, too. ]; +use Clone qw(clone); use Getopt::Long qw(:config pass_through); use List::Util qw(max); use Pod::Usage; -use Storable qw(dclone); # add the folder this script lives in and the lib-folder to perl's # search path for modules: @@ -247,7 +247,6 @@ sub parseKeyValueArgsWithAttrs if (grep { $_ eq $key } @$allowedKeys) { $dataHash{$key} = $value; } elsif (grep { $_ eq $key } @$allowedAttrKeys) { - OpenSLX::AttributeRoster->checkValueForKey($key, $value); $attrHash{$key} = $value; } else { die _tr("unknown key '%s' specified for %s\n", $key, $table); @@ -265,6 +264,18 @@ sub parseKeyValueArgsWithAttrs } } +sub checkGivenStage3Attrs +{ + my $stage3Attrs = shift; + my $vendorOSID = shift; + + my $vendorOS = $openslxDB->fetchVendorOSByID($vendorOSID); + + OpenSLX::AttributeRoster->checkValues($stage3Attrs, $vendorOS->{name}); + + return 1; +} + sub mergeNonExistingAttributes { my $target = shift; @@ -359,7 +370,7 @@ sub listAttributes dumpElements( 'attribute', undef, map { - my $attr = dclone($attrInfo->{$_}); + my $attr = clone($attrInfo->{$_}); $attr->{name} = $_; delete $attr->{content_regex}; # no use for display purposes $attr; @@ -488,7 +499,14 @@ sub listVendorOSes dumpElements('vendor-OS', undef, map { my @plugins = $openslxDB->fetchInstalledPlugins($_->{id}); - $_->{plugins} + my %attrHash; + foreach my $plugin (@plugins) { + foreach my $attr (keys %{$plugin->{attrs}}) { + $attrHash{$attr} = $plugin->{attrs}->{$attr}; + } + } + $_->{ATTRIBUTES} = \%attrHash; + $_->{PLUGINS} = @plugins ? join(',', sort map { $_->{plugin_name} } @plugins) : '<none>'; @@ -844,6 +862,8 @@ sub addSystemToConfigDB } $systemData->{export_id} = $export->{id}; + checkGivenStage3Attrs($systemData->{attrs}, $export->{vendor_os_id}); + my @clientIDs; if (exists $systemData->{clients}) { @clientIDs = map { @@ -1118,6 +1138,11 @@ sub changeSystemInConfigDB ); } + my $system = $openslxDB->fetchSystemByFilter({'name' => $systemName}); + if (!defined $system) { + die _tr("the system '%s' doesn't exists in the DB, giving up!\n", + $systemName); + } my @systemKeys = $openslxDB->getColumnsOfTable('system'); push @systemKeys, 'clients', 'add-clients', 'remove-clients'; my @systemAttrKeys = OpenSLX::AttributeRoster->getSystemAttrs(); @@ -1125,11 +1150,8 @@ sub changeSystemInConfigDB \@systemKeys, \@systemAttrKeys, 'system', @_ ); - my $system = $openslxDB->fetchSystemByFilter({'name' => $systemName}); - if (!defined $system) { - die _tr("the system '%s' doesn't exists in the DB, giving up!\n", - $systemName); - } + my $export = $openslxDB->fetchExportByID($system->{export_id}); + checkGivenStage3Attrs($systemData->{attrs}, $export->{vendor_os_id}); mergeNonExistingAttributes($systemData, $system); @@ -1276,7 +1298,7 @@ sub _expandClients sort { $a->{name} cmp $b->{name} } $openslxDB->fetchSystemByID(\@sysIDs, 'name'); if ($option{inherited}) { - my $mergedClient = dclone($_); + my $mergedClient = clone($_); my $originInfo = {}; $openslxDB->mergeDefaultAndGroupAttributesIntoClient( $mergedClient, $originInfo @@ -1325,21 +1347,20 @@ sub _expandSystems map { my @clientIDs = $openslxDB->fetchClientIDsOfSystem($_->{id}); $_->{clients} - = join "\n", + = join "\n", map { $_->{name} } sort { $a->{name} cmp $b->{name} } $openslxDB->fetchClientByID(\@clientIDs, 'name'); my @activePlugins; my $export = $openslxDB->fetchExportByID($_->{export_id}); if (defined $export) { - $_->{export_id} - = "$export->{id} ($export->{name})"; + $_->{export_id} = "$export->{id} ($export->{name})"; # fetch detailed info about active plugins my @installedPlugins = $openslxDB->fetchInstalledPlugins( $export->{vendor_os_id} ); - my $mergedSystem = dclone($_); + my $mergedSystem = clone($_); my $originInfo = {}; $openslxDB->mergeDefaultAttributesIntoSystem( $mergedSystem, \@installedPlugins, $originInfo |
