From aaa042a0cb0ba83d60d6b9479a42665f7b1eab54 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Wed, 2 May 2007 21:34:33 +0000 Subject: overhaul the settings concept: * now all settings live in the settings file, no more settings table in the DB * clearified slxsettings and its options * removed all references to db table 'settings' * added some new extended settings git-svn-id: http://svn.openslx.org/svn/openslx/trunk@988 95ad53e4-c205-0410-b2fa-d234c58c8868 --- config-db/OpenSLX/ConfigDB.pm | 16 ------ config-db/OpenSLX/DBSchema.pm | 16 ------ config-db/OpenSLX/MetaDB/Base.pm | 43 ---------------- config-db/OpenSLX/MetaDB/DBI.pm | 14 ------ config-db/slxconfig-demuxer | 2 - config-db/slxsettings | 103 ++++++++++++++++----------------------- lib/OpenSLX/Basics.pm | 12 ++++- 7 files changed, 52 insertions(+), 154 deletions(-) diff --git a/config-db/OpenSLX/ConfigDB.pm b/config-db/OpenSLX/ConfigDB.pm index 78a13e05..dc3850ba 100644 --- a/config-db/OpenSLX/ConfigDB.pm +++ b/config-db/OpenSLX/ConfigDB.pm @@ -364,14 +364,6 @@ sub fetchGroupIDsOfClient return $self->{'meta-db'}->fetchGroupIDsOfClient($clientID); } -sub fetchSettings -{ - my $self = shift; - - my @rows = $self->{'meta-db'}->fetchSettings(); - return shift @rows; -} - ################################################################################ ### data manipulation interface ################################################################################ @@ -805,14 +797,6 @@ sub emptyDatabase $self->removeVendorOS(\@vendorOSIDs); } -sub changeSettings -{ - my $self = shift; - my $settings = shift; - - return $self->{'meta-db'}->changeSettings($settings); -} - ################################################################################ ### data aggregation interface ################################################################################ diff --git a/config-db/OpenSLX/DBSchema.pm b/config-db/OpenSLX/DBSchema.pm index e1e6750b..a9424031 100644 --- a/config-db/OpenSLX/DBSchema.pm +++ b/config-db/OpenSLX/DBSchema.pm @@ -158,11 +158,6 @@ $DbSchema = { 'group_id:fk', # foreign key 'system_id:fk', # foreign key ], - 'settings' => [ - # system-wide settings - 'default_nicmods:s.256', - # list of default network modules - ], }, }; @@ -262,17 +257,6 @@ $DbSchema = { 'table' => 'group_system_ref', 'cols' => $DbSchema->{'tables'}->{'group_system_ref'}, }, - { - 'cmd' => 'add-table', - 'table' => 'settings', - 'cols' => $DbSchema->{'tables'}->{'settings'}, - 'vals' => [ - { # add default configuration - 'default_nicmods' - => 'forcedeth e1000 e100 tg3 via-rhine r8169 pcnet32', - }, - ], - }, ], ); diff --git a/config-db/OpenSLX/MetaDB/Base.pm b/config-db/OpenSLX/MetaDB/Base.pm index 2d6f0374..db1f2e7e 100644 --- a/config-db/OpenSLX/MetaDB/Base.pm +++ b/config-db/OpenSLX/MetaDB/Base.pm @@ -115,10 +115,6 @@ sub fetchGroupIDsOfSystem { } -sub fetchSettings -{ -} - ################################################################################ ### data manipulation interface ################################################################################ @@ -215,10 +211,6 @@ sub setSystemIDsOfGroup { } -sub changeSettings -{ -} - ################################################################################ ### schema related functions ################################################################################ @@ -786,21 +778,6 @@ An array of client-IDs. -=item C - -Fetches all entries of the settings table, where a single row holds the info -about all system wide configuration parameters. - -=over - -=item Return Value - -A hash containing all column values of the single row that lives -int the settings table. - -=back - - =head2 Data Manipulation Methods The following methods need to be implemented in a MetaDB driver in order to @@ -1234,26 +1211,6 @@ C<1> if the group/system references could be set, C if not. -=item C - -Changes one or more of the system-wide setting parameters. - -=over - -=item Param C - -A hash-ref containing the column-names you'd like to change with their new -values. - -=item Return Value - -C<1> if the settings could be changed, C if not. - -=back - - - - =head2 Schema Related Methods diff --git a/config-db/OpenSLX/MetaDB/DBI.pm b/config-db/OpenSLX/MetaDB/DBI.pm index 9678afe4..29e9bb41 100644 --- a/config-db/OpenSLX/MetaDB/DBI.pm +++ b/config-db/OpenSLX/MetaDB/DBI.pm @@ -323,13 +323,6 @@ sub fetchGroupIDsOfClient return $self->_doSelect($sql, 'group_id'); } -sub fetchSettings -{ - my $self = shift; - my $sql = "SELECT * FROM settings"; - return $self->_doSelect($sql); -} - ################################################################################ ### data manipulation functions ################################################################################ @@ -704,13 +697,6 @@ sub setSystemIDsOfGroup 'group_id', 'system_id', \@currSystems); } -sub changeSettings -{ - my $self = shift; - my $settings = shift; - return $self->_doUpdate('settings', undef, [ $settings ]); -} - ################################################################################ ### schema related functions ################################################################################ diff --git a/config-db/slxconfig-demuxer b/config-db/slxconfig-demuxer index 7acb0324..093a2920 100755 --- a/config-db/slxconfig-demuxer +++ b/config-db/slxconfig-demuxer @@ -102,8 +102,6 @@ openslxInit(); my $openslxDB = OpenSLX::ConfigDB->new(); $openslxDB->connect(); -my $settings = $openslxDB->fetchSettings(); - my $clientConfigPath = "$openslxConfig{'private-path'}/config"; if (!-d $clientConfigPath) { die _tr("Unable to access client-config-path '%s'!", $clientConfigPath); diff --git a/config-db/slxsettings b/config-db/slxsettings index 82b97585..b01d3f12 100755 --- a/config-db/slxsettings +++ b/config-db/slxsettings @@ -39,27 +39,24 @@ use lib "$FindBin::RealBin"; # development path to config-db stuff use OpenSLX::Basics; -use OpenSLX::ConfigDB; +use OpenSLX::Utils; my ( $quiet, - @remove, - %cmdlineSettings, + @reset, $helpReq, $manReq, - $verbose, $versionReq, ); GetOptions( 'quiet' => \$quiet, # will avoid printing anything - 'setting=s' => \%cmdlineSettings, - # accepts setting for db-table 'settings' + 'reset=s' => \@reset, + # resets given option to its default 'help|?' => \$helpReq, 'man' => \$manReq, - 'verbose' => \$verbose, 'version' => \$versionReq, ); pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq; @@ -71,35 +68,29 @@ if ($versionReq) { openslxInit() or pod2usage(2); -# if there are still arguments in the cmdline left, it must be 'remove'-actions: +my %givenSettings = %cmdlineConfig; + +# if there are still arguments in the cmdline left, it must be extended +# settings: while (scalar @ARGV) { - my $action = shift; - my $key = shift; - if ($action !~ m[^remove$]) { - print STDERR _tr("Action '%s' is not understood!\n\n", $action); - pod2usage(); + my $extSetting = shift; + if ($extSetting !~ m[^([-\w]+)=(.+)$]) { + die _tr("extended setting '%s' has unknown format, expected '=!'", + $extSetting); } - push @remove, $key; + $givenSettings{$1} = $2; } -# fetch slxconf entries... -my $openslxDB = OpenSLX::ConfigDB->new(); -$openslxDB->connect(); -my $currSettings = $openslxDB->fetchSettings(); - -# ...and fetch current content of local settings file... -open(SETTINGS, "< $openslxConfig{'config-path'}/settings.local"); -local $/ = undef; -my $settings = ; -close(SETTINGS); +# fetch current content of local settings file... +my $settings = slurpFile("$openslxConfig{'config-path'}/settings.local"); my $changeCount; # ...set new values... -foreach my $key (sort keys %cmdlineConfig) { +foreach my $key (keys %givenSettings) { next if $key eq 'config-path'; # config-path can't be changed, it is used to find settings.local - my $value = $cmdlineConfig{$key}; + my $value = $givenSettings{$key}; next if !defined $value; vlog 0, _tr("setting %s to '%s'", $key, $value) unless $quiet; my $externalKey = externalKeyFor($key); @@ -109,14 +100,10 @@ foreach my $key (sort keys %cmdlineConfig) { $changeCount++; } -# ...remove any keys we should do away with... -foreach my $key (@remove) { - if (!exists $cmdlineConfig{$key}) { - vlog 0, _tr("ignoring unknown key '%s'", $key); - next; - } +# reset specified keys to fall back to default: +foreach my $key (@reset) { my $externalKey = externalKeyFor($key); - if ($settings =~ s[^\s*$externalKey=.*?$][]ms) { + if ($settings =~ s[^\s*?$externalKey=.*?\n][]ms) { vlog 0, _tr("removing option '%s' from local settings", $key) unless $quiet; } else { vlog 0, _tr("option '%s' didn't exist in local settings!", $key) unless $quiet; @@ -133,29 +120,18 @@ if ($changeCount) { close(SETTINGS); } -if (scalar(keys %cmdlineSettings) > 0) { - foreach my $key (keys %cmdlineSettings) { - if (exists $currSettings->{$key}) { - $openslxDB->changeSettings({ $key => $cmdlineSettings{$key} }); - $changeCount++; - } else { - die _tr("unknown settings key '%s'!\n", $key); - } - } - $currSettings = $openslxDB->fetchSettings(); -} - -$openslxDB->disconnect(); - -if ($verbose || !$changeCount) { - my $text = $changeCount ? "resulting settings:" : "current settings:"; +if (!$changeCount) { + my $text + = $changeCount ? "resulting base settings:" : "current base settings:"; print "\n"._tr($text)."\n"; - foreach my $key (sort keys %openslxConfig) { - print qq[\t$key='$openslxConfig{$key}'\n]; + my @baseSettings = grep { exists $cmdlineConfig{$_} } keys %openslxConfig; + foreach my $key (sort @baseSettings) { + print qq[\t--$key='$openslxConfig{$key}'\n]; } - print "slxconf:\n"; - foreach my $key (sort keys %$currSettings) { - print qq[\t$key='$currSettings->{$key}'\n]; + print "extended settings:\n"; + my @extSettings = grep { !exists $cmdlineConfig{$_} } keys %openslxConfig; + foreach my $key (sort @extSettings) { + print qq[\t$key='$openslxConfig{$key}'\n]; } } @@ -177,6 +153,10 @@ slxsettings - OpenSLX-script to show & change local settings slxsettings [options] [action ...] +=head3 Script Options + + --reset= resets the given option to its default + =head3 OpenSLX Options --base-path= basic path to project files @@ -202,7 +182,6 @@ slxsettings [options] [action ...] --help brief help message --man full documentation --quiet do not print anything - --verbose show more information --version show version =head3 Actions @@ -213,10 +192,14 @@ slxsettings [options] [action ...] sets the specified openslx-option to the given value -=item B<< remove [remove ...] >> +=item B<< = >> -removes given openslx-option from the local settings (resets it to the -default value) +sets the specified extended setting to the given value + +=item B<< --reset= [--reset=...] >> + +removes the given setting from the local settings (resets it to its default +value) =back @@ -370,10 +353,6 @@ Prints the manual page and exits. Runs the script without printing anything. -=item B< --verbose> - -Prints the resulting settings after changes have been applied. - =item B< --version> Prints the version and exits. diff --git a/lib/OpenSLX/Basics.pm b/lib/OpenSLX/Basics.pm index 6a23d8c0..f1c39e05 100644 --- a/lib/OpenSLX/Basics.pm +++ b/lib/OpenSLX/Basics.pm @@ -46,7 +46,7 @@ my %translations; # this hash will hold the active openslx configuration, # the initial content is based on environment variables or default values. -# Each value may be overrided from config files and/or cmdline arguments. +# Each value may be overridden from config files and/or cmdline arguments. %openslxConfig = ( 'croak' => '0', 'db-datadir' => $ENV{SLX_DB_DATADIR}, @@ -61,6 +61,14 @@ my %translations; 'public-path' => $ENV{SLX_PUBLIC_PATH} || '/srv/openslx', 'temp-path' => $ENV{SLX_TEMP_PATH} || '/tmp', 'verbose-level' => $ENV{SLX_VERBOSE_LEVEL} || '0', + # + # extended settings follow, which are only supported by slxsettings, + # but not by any other script: + # + 'system-default-nicmods' + => 'forcedeth e1000 e100 tg3 via-rhine r8169 pcnet32', + 'system-default-fsmods' => '', + 'ossetup-max-retry-count' => '5', ); chomp($openslxConfig{'locale-charmap'}); $openslxConfig{'bin-path'} @@ -75,6 +83,8 @@ $openslxConfig{'stage1-path'} = $ENV{SLX_STAGE1_PATH} || "$openslxConfig{'private-path'}/stage1", $openslxConfig{'tftpboot-path'} = $ENV{SLX_TFTPBOOT_PATH} || "$openslxConfig{'public-path'}/tftpboot", +$openslxConfig{'vmware-path'} + = $ENV{SLX_VMWARE_PATH} || "$openslxConfig{'base-path'}/vmware", # specification of cmdline arguments that are shared by all openslx-scripts: %cmdlineConfig; -- cgit v1.2.3-55-g7522