diff options
| author | Oliver Tappe | 2008-05-21 12:08:15 +0200 |
|---|---|---|
| committer | Oliver Tappe | 2008-05-21 12:08:15 +0200 |
| commit | 1ff2bd49589e9d2de9339d6c477f079de6475010 (patch) | |
| tree | a38d55f2c1b1f887599cb99ee4d10cbdd1f82fb8 | |
| parent | * added support to slxconfig for checking the given attribute values against (diff) | |
| download | core-1ff2bd49589e9d2de9339d6c477f079de6475010.tar.gz core-1ff2bd49589e9d2de9339d6c477f079de6475010.tar.xz core-1ff2bd49589e9d2de9339d6c477f079de6475010.zip | |
* fixed bug in slxconfig introduced yesterday that would not allow setting
any attribute that has not come from a plugin (reported by Reiner)
git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1779 95ad53e4-c205-0410-b2fa-d234c58c8868
| -rw-r--r-- | config-db/OpenSLX/AttributeRoster.pm | 43 | ||||
| -rwxr-xr-x | config-db/slxconfig | 8 | ||||
| -rw-r--r-- | os-plugins/OpenSLX/OSPlugin/Base.pm | 23 |
3 files changed, 46 insertions, 28 deletions
diff --git a/config-db/OpenSLX/AttributeRoster.pm b/config-db/OpenSLX/AttributeRoster.pm index c37421c8..331ac70c 100644 --- a/config-db/OpenSLX/AttributeRoster.pm +++ b/config-db/OpenSLX/AttributeRoster.pm @@ -162,8 +162,8 @@ sub _init description => unshiftHereDoc(<<' End-of-Here'), list of network card modules to load End-of-Here - content_regex => undef, - content_descr => undef, + content_regex => qr{^\s*([-\w]+\s*)*$}, + content_descr => 'a space-separated list of NIC modules', default => 'forcedeth e1000 e100 tg3 via-rhine r8169 pcnet32', }, 'sane_scanner' => { @@ -495,4 +495,43 @@ sub getClientAttrs keys %AttributeInfo } +=item C<checkValueForKey()> + +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. + +=cut + +sub checkValueForKey +{ + my $class = shift; + my $key = shift; + my $value = shift; + + $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} + ); + } + + # 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); + } +} 1; diff --git a/config-db/slxconfig b/config-db/slxconfig index c8c05093..4414d2db 100755 --- a/config-db/slxconfig +++ b/config-db/slxconfig @@ -39,7 +39,6 @@ use OpenSLX::AttributeRoster; use OpenSLX::Basics; use OpenSLX::ConfigDB; use OpenSLX::ConfigFolder; -use OpenSLX::OSPlugin::Roster; use OpenSLX::Utils; my %option; @@ -248,12 +247,7 @@ sub parseKeyValueArgsWithAttrs if (grep { $_ eq $key } @$allowedKeys) { $dataHash{$key} = $value; } elsif (grep { $_ eq $key } @$allowedAttrKeys) { - $key =~ m{^(.+)::.+?$}; - my $pluginName = $1; - my $plugin - = OpenSLX::OSPlugin::Roster->getPlugin($pluginName) - || die _tr('unable to load plugin "%s"', $pluginName); - $plugin->checkValueForKey($key, $value); + OpenSLX::AttributeRoster->checkValueForKey($key, $value); $attrHash{$key} = $value; } else { die _tr("unknown key '%s' specified for %s\n", $key, $table); diff --git a/os-plugins/OpenSLX/OSPlugin/Base.pm b/os-plugins/OpenSLX/OSPlugin/Base.pm index b4a3ad02..b89f73fa 100644 --- a/os-plugins/OpenSLX/OSPlugin/Base.pm +++ b/os-plugins/OpenSLX/OSPlugin/Base.pm @@ -188,7 +188,7 @@ 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. -Plugins may override this implementation to do additional checks that look +Plugins may override this implementation to do checks that for instance look at the vendor-OS (stage1-)attributes. =cut @@ -199,24 +199,9 @@ sub checkValueForKey my $key = shift; my $value = shift; - # undefined values are always allowed - return 1 if !defined $value; - - # the default implementation checks the value against the regex of the - # attribute (if any) - my $attrInfo - = $self->getAttrInfo()->{$key} - || die _tr('attribute "%s" is unknown!', $key); - - my $regex = $attrInfo->{content_regex}; - return 1 if !$regex; - - return 1 if $value =~ m{$regex}; - - die _tr( - "value given for attribute %s is not allowed.\nAllowed values are: %s", - $key, $attrInfo->{content_descr} - ); + # this default implementation does no further checks (thus relying on the + # attributte regex check that is done in the AttributeRoster) + return 1; } |
