diff options
Diffstat (limited to 'config-db/OpenSLX')
-rw-r--r-- | config-db/OpenSLX/AttributeRoster.pm | 126 | ||||
-rw-r--r-- | config-db/OpenSLX/ConfigDB.pm | 416 | ||||
-rw-r--r-- | config-db/OpenSLX/ConfigExport/DHCP/ISC.pm (renamed from config-db/OpenSLX/Export/DHCP/ISC.pm) | 2 | ||||
-rw-r--r-- | config-db/OpenSLX/DBSchema.pm | 394 | ||||
-rw-r--r-- | config-db/OpenSLX/MetaDB/DBI.pm | 381 |
5 files changed, 650 insertions, 669 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; diff --git a/config-db/OpenSLX/ConfigDB.pm b/config-db/OpenSLX/ConfigDB.pm index 289f6f7f..8269ec0c 100644 --- a/config-db/OpenSLX/ConfigDB.pm +++ b/config-db/OpenSLX/ConfigDB.pm @@ -16,6 +16,8 @@ use warnings; our (@ISA, @EXPORT_OK, %EXPORT_TAGS, $VERSION); $VERSION = 1; # API-version +use Storable qw(dclone); + use Exporter; @ISA = qw(Exporter); @@ -81,7 +83,7 @@ to filtering (with boolean operators and hierarchical expressions)]. =cut my @supportExports = qw( - isAttribute mergeAttributes pushAttributes + mergeAttributes pushAttributes externalIDForSystem externalIDForClient externalConfigNameForClient externalAttrName generatePlaceholderFor ); @@ -112,6 +114,7 @@ sub new my $class = shift; my $self = { + 'db-schema' => OpenSLX::DBSchema->new, }; return bless $self, $class; @@ -182,7 +185,7 @@ sub connect ## no critic (ProhibitBuiltinHomonyms) $self->{'db-type'} = $dbType; $self->{'meta-db'} = $metaDB; - $self->_checkAndUpgradeDBSchemaIfNecessary($metaDB); + $self->{'db-schema'}->checkAndUpgradeDBSchemaIfNecessary($metaDB); return 1; } @@ -281,55 +284,7 @@ sub getColumnsOfTable my $self = shift; my $tableName = shift; - return - map { (/^(\w+)\W/) ? $1 : $_; } - @{$DbSchema->{tables}->{$tableName}->{cols}}; -} - -=item C<getKnownSystemAttrs()> - -Returns the attribute names that apply to systems. - -=over - -=item Return Value - -An array of attribute names. - -=back - -=cut - -sub getKnownSystemAttrs -{ - my $self = shift; - - return - grep { $AttributeInfo{$_}->{"applies_to_systems"} } - keys %AttributeInfo -} - -=item C<getKnownClientAttrs()> - -Returns the attribute names that apply to clients. - -=over - -=item Return Value - -An array of attribute names. - -=back - -=cut - -sub getKnownClientAttrs -{ - my $self = shift; - - return - grep { $AttributeInfo{$_}->{"applies_to_clients"} } - keys %AttributeInfo + return $self->{'db-schema'}->getColumnsOfTable($tableName); } =item C<fetchVendorOSByFilter([%$filter], [$resultCols])> @@ -1243,10 +1198,12 @@ The IDs of the new system(s), C<undef> if the creation failed. sub addSystem { - my $self = shift; - my $valRows = _aref(shift); + my $self = shift; + my $inValRows = _aref(shift); - _checkCols($valRows, 'system', qw(name export_id)); + _checkCols($inValRows, 'system', qw(name export_id)); + + my ($valRows, $attrValRows) = _cloneAndUnhingeAttrs($inValRows); foreach my $valRow (@$valRows) { if (!$valRow->{kernel}) { @@ -1264,7 +1221,7 @@ sub addSystem } } - return $self->{'meta-db'}->addSystem($valRows); + return $self->{'meta-db'}->addSystem($valRows, $attrValRows); } =item C<removeSystem(@$systemIDs)> @@ -1324,48 +1281,50 @@ sub changeSystem { my $self = shift; my $systemIDs = _aref(shift); - my $valRows = _aref(shift); + my $inValRows = _aref(shift); - return $self->{'meta-db'}->changeSystem($systemIDs, $valRows); -} + my ($valRows, $attrValRows) = _cloneAndUnhingeAttrs($inValRows); -=item C<setSystemAttr($systemID, $attrName, $attrValue)> - -Sets a value for an attribute of the given system. If the system already -has a value for this attribute, it will be overwritten. - -=over - -=item Param C<systemID> - -The ID of the system whose attribute shall be changed. - -=item Param C<attrName> - -The name of the attribute to change. - -=item Param C<attrValue> - -The new value for the attribute. - -=item Return Value - -C<1> if the attribute could be set, C<undef> if not. - -=back - -=cut - -sub setSystemAttr -{ - my $self = shift; - my $systemID = shift; - my $attrName = shift; - my $attrValue = shift; - - return $self->{'meta-db'}->setSystemAttr($systemID, $attrName, $attrValue); + return $self->{'meta-db'}->changeSystem($systemIDs, $valRows, $attrValRows); } +#=item C<setSystemAttr($systemID, $attrName, $attrValue)> +# +#Sets a value for an attribute of the given system. If the system already +#has a value for this attribute, it will be overwritten. +# +#=over +# +#=item Param C<systemID> +# +#The ID of the system whose attribute shall be changed. +# +#=item Param C<attrName> +# +#The name of the attribute to change. +# +#=item Param C<attrValue> +# +#The new value for the attribute. +# +#=item Return Value +# +#C<1> if the attribute could be set, C<undef> if not. +# +#=back +# +#=cut +# +#sub setSystemAttr +#{ +# my $self = shift; +# my $systemID = shift; +# my $attrName = shift; +# my $attrValue = shift; +# +# return $self->{'meta-db'}->setSystemAttr($systemID, $attrName, $attrValue); +#} + =item C<setClientIDsOfSystem($systemID, @$clientIDs)> Specifies all clients that should offer the given system for booting. @@ -1608,10 +1567,12 @@ The IDs of the new client(s), C<undef> if the creation failed. sub addClient { - my $self = shift; - my $valRows = _aref(shift); + my $self = shift; + my $inValRows = _aref(shift); + + _checkCols($inValRows, 'client', qw(name mac)); - _checkCols($valRows, 'client', qw(name mac)); + my ($valRows, $attrValRows) = _cloneAndUnhingeAttrs($inValRows); foreach my $valRow (@$valRows) { if (!$valRow->{boot_type}) { @@ -1619,7 +1580,7 @@ sub addClient } } - return $self->{'meta-db'}->addClient($valRows); + return $self->{'meta-db'}->addClient($valRows, $attrValRows); } =item C<removeClient(@$clientIDs)> @@ -1679,48 +1640,50 @@ sub changeClient { my $self = shift; my $clientIDs = _aref(shift); - my $valRows = _aref(shift); - - return $self->{'meta-db'}->changeClient($clientIDs, $valRows); -} - -=item C<setClientAttr($clientID, $attrName, $attrValue)> - -Sets a value for an attribute of the given client. If the client already -has a value for this attribute, it will be overwritten. - -=over - -=item Param C<clientID> - -The ID of the client whose attribute shall be changed. - -=item Param C<attrName> - -The name of the attribute to change. - -=item Param C<attrValue> - -The new value for the attribute. - -=item Return Value - -C<1> if the attribute could be set, C<undef> if not. - -=back - -=cut + my $inValRows = _aref(shift); -sub setClientAttr -{ - my $self = shift; - my $clientID = shift; - my $attrName = shift; - my $attrValue = shift; + my ($valRows, $attrValRows) = _cloneAndUnhingeAttrs($inValRows); - return $self->{'meta-db'}->setClientAttr($clientID, $attrName, $attrValue); + return $self->{'meta-db'}->changeClient($clientIDs, $valRows, $attrValRows); } +#=item C<setClientAttr($clientID, $attrName, $attrValue)> +# +#Sets a value for an attribute of the given client. If the client already +#has a value for this attribute, it will be overwritten. +# +#=over +# +#=item Param C<clientID> +# +#The ID of the client whose attribute shall be changed. +# +#=item Param C<attrName> +# +#The name of the attribute to change. +# +#=item Param C<attrValue> +# +#The new value for the attribute. +# +#=item Return Value +# +#C<1> if the attribute could be set, C<undef> if not. +# +#=back +# +#=cut +# +#sub setClientAttr +#{ +# my $self = shift; +# my $clientID = shift; +# my $attrName = shift; +# my $attrValue = shift; +# +# return $self->{'meta-db'}->setClientAttr($clientID, $attrName, $attrValue); +#} + =item C<setSystemIDsOfClient($clientID, @$systemIDs)> Specifies all systems that should be offered for booting by the given client. @@ -1957,17 +1920,19 @@ The IDs of the new group(s), C<undef> if the creation failed. sub addGroup { - my $self = shift; - my $valRows = _aref(shift); + my $self = shift; + my $inValRows = _aref(shift); + + _checkCols($inValRows, 'group', qw(name)); - _checkCols($valRows, 'group', qw(name)); + my ($valRows, $attrValRows) = _cloneAndUnhingeAttrs($inValRows); foreach my $valRow (@$valRows) { if (!defined $valRow->{priority}) { $valRow->{priority} = '50'; } } - return $self->{'meta-db'}->addGroup($valRows); + return $self->{'meta-db'}->addGroup($valRows, $attrValRows); } =item C<removeGroup(@$groupIDs)> @@ -2001,42 +1966,42 @@ sub removeGroup return $self->{'meta-db'}->removeGroup($groupIDs); } -=item C<setGroupAttr($groupID, $attrName, $attrValue)> - -Sets a value for an attribute of the given group. If the group already -has a value for this attribute, it will be overwritten. - -=over - -=item Param C<groupID> - -The ID of the group whose attribute shall be changed. - -=item Param C<attrName> - -The name of the attribute to change. - -=item Param C<attrValue> - -The new value for the attribute. - -=item Return Value - -C<1> if the attribute could be set, C<undef> if not. - -=back - -=cut - -sub setGroupAttr -{ - my $self = shift; - my $groupID = shift; - my $attrName = shift; - my $attrValue = shift; - - return $self->{'meta-db'}->setGroupAttr($groupID, $attrName, $attrValue); -} +#=item C<setGroupAttr($groupID, $attrName, $attrValue)> +# +#Sets a value for an attribute of the given group. If the group already +#has a value for this attribute, it will be overwritten. +# +#=over +# +#=item Param C<groupID> +# +#The ID of the group whose attribute shall be changed. +# +#=item Param C<attrName> +# +#The name of the attribute to change. +# +#=item Param C<attrValue> +# +#The new value for the attribute. +# +#=item Return Value +# +#C<1> if the attribute could be set, C<undef> if not. +# +#=back +# +#=cut +# +#sub setGroupAttr +#{ +# my $self = shift; +# my $groupID = shift; +# my $attrName = shift; +# my $attrValue = shift; +# +# return $self->{'meta-db'}->setGroupAttr($groupID, $attrName, $attrValue); +#} =item C<changeGroup(@$groupIDs, @$valRows)> @@ -2062,11 +2027,13 @@ C<1> if the group(s) could be changed, C<undef> if not. sub changeGroup { - my $self = shift; - my $groupIDs = _aref(shift); - my $valRows = _aref(shift); + my $self = shift; + my $groupIDs = _aref(shift); + my $inValRows = _aref(shift); - return $self->{'meta-db'}->changeGroup($groupIDs, $valRows); + my ($valRows, $attrValRows) = _cloneAndUnhingeAttrs($inValRows); + + return $self->{'meta-db'}->changeGroup($groupIDs, $valRows, $attrValRows); } =item C<setClientIDsOfGroup($groupID, @$clientIDs)> @@ -2525,7 +2492,7 @@ sub aggregatedSystemFileInfoFor my $self = shift; my $system = shift; - my $info = {%$system}; + my $info = dclone($system); my $export = $self->fetchExportByID($system->{export_id}); if (!defined $export) { @@ -2586,32 +2553,6 @@ sub aggregatedSystemFileInfoFor =over -=item C<isAttribute($key)> - -Returns whether or not the given key is an exportable attribute. - -=over - -=item Param C<system> - -The key to check. - -=item Return Value - -1 if the given key is indeed an attribute (currently, this means that -it starts with 'attr_'), 0 if not. - -=back - -=cut - -sub isAttribute -{ - my $key = shift; - - return $key =~ m[^attr_]; -} - =item C<mergeAttributes($target, $source)> Copies all attributes from source that are unset in target over (source extends target). @@ -2648,7 +2589,7 @@ sub mergeAttributes my $sourceVal = $sourceAttrs->{$key}; my $targetVal = $targetAttrs->{$key}; if (defined $sourceVal && !defined $targetVal) { - vlog(0, _tr("merging %s (val=%s)", $key, $sourceVal)); + vlog(3, _tr("merging %s (val=%s)", $key, $sourceVal)); $targetAttrs->{$key} = $sourceVal; } } @@ -2851,51 +2792,6 @@ sub generatePlaceholderFor ################################################################################ ### private stuff ################################################################################ -sub _checkAndUpgradeDBSchemaIfNecessary -{ - my $self = shift; - my $metaDB = shift; - - vlog(2, "trying to determine schema version..."); - my $currVersion = $metaDB->schemaFetchDBVersion(); - if (!defined $currVersion) { - # that's bad, someone has messed with our DB: there is a - # database, but the 'meta'-table is empty. - # There might still be data in the other tables, but we have no way to - # find out which schema version they're in. So it's safer to give up. - croak _tr('Could not determine schema version of database'); - } - - if ($currVersion == 0) { - vlog(1, _tr('Creating DB (schema version: %s)', $DbSchema->{version})); - foreach my $tableName (keys %{$DbSchema->{tables}}) { - # create table (optionally inserting default values, too) - $metaDB->schemaAddTable( - $tableName, - $DbSchema->{tables}->{$tableName}->{cols}, - $DbSchema->{tables}->{$tableName}->{vals} - ); - } - $metaDB->schemaSetDBVersion($DbSchema->{version}); - vlog(1, _tr('DB has been created successfully')); - } elsif ($currVersion < $DbSchema->{version}) { - vlog( - 1, - _tr( - 'Our schema-version is %s, DB is %s, upgrading DB...', - $DbSchema->{version}, $currVersion - ) - ); - $metaDB->schemaUpgradeDBFrom($currVersion); - $metaDB->schemaSetDBVersion($DbSchema->{version}); - vlog(1, _tr('upgrade done')); - } else { - vlog(1, _tr('DB matches current schema version (%s)', $currVersion)); - } - - return 1; -} - sub _aref { # transparently converts the given reference to an array-ref my $ref = shift; @@ -2927,4 +2823,20 @@ sub _checkCols return 1; } +sub _cloneAndUnhingeAttrs +{ + my $inValRows = shift; + + # clone data and unhinge attrs + my (@valRows, @attrValRows); + foreach my $inValRow (@$inValRows) { + push @attrValRows, $inValRow->{attrs}; + my $valRow = dclone($inValRow); + delete $valRow->{attrs}; + push @valRows, $valRow; + } + + return (\@valRows, \@attrValRows); +} + 1; diff --git a/config-db/OpenSLX/Export/DHCP/ISC.pm b/config-db/OpenSLX/ConfigExport/DHCP/ISC.pm index 2e7aa01b..e3dd0738 100644 --- a/config-db/OpenSLX/Export/DHCP/ISC.pm +++ b/config-db/OpenSLX/ConfigExport/DHCP/ISC.pm @@ -11,7 +11,7 @@ # ISC.pm # - provides ISC-specific implementation of DHCP export. # ----------------------------------------------------------------------------- -package OpenSLX::Export::DHCP::ISC; +package OpenSLX::ConfigExport::DHCP::ISC; use strict; use warnings; diff --git a/config-db/OpenSLX/DBSchema.pm b/config-db/OpenSLX/DBSchema.pm index 801f50a9..cd92c07e 100644 --- a/config-db/OpenSLX/DBSchema.pm +++ b/config-db/OpenSLX/DBSchema.pm @@ -16,25 +16,8 @@ package OpenSLX::DBSchema; use strict; use warnings; -our (@ISA, @EXPORT, $VERSION); - -use Exporter; -$VERSION = 0.2; -@ISA = qw(Exporter); - -@EXPORT = qw( - $DbSchema %DbSchemaHistory %AttributeInfo -); - -our ($DbSchema, %DbSchemaHistory, %AttributeInfo); - - use OpenSLX::Basics; -use POSIX qw(locale_h); -my $lang = setlocale(LC_MESSAGES); -my $country = $lang =~ m[^\w\w_(\w\w)] ? lc($1) : 'us'; - ################################################################################ ### DB-schema definition ### This hash-ref describes the current OpenSLX configuration database @@ -51,7 +34,13 @@ my $country = $lang =~ m[^\w\w_(\w\w)] ? lc($1) : 'us'; ### fk => foreign key (integer) ################################################################################ -$DbSchema = { +use POSIX qw(locale_h); +my $lang = setlocale(LC_MESSAGES); +my $country = $lang =~ m[^\w\w_(\w\w)] ? lc($1) : 'us'; + +my $VERSION = 0.2; + +my $DbSchema = { 'version' => $VERSION, 'tables' => { 'client' => { @@ -170,7 +159,7 @@ $DbSchema = { ], 'vals' => [ { - 'schema_version' => $DbSchema->{'version'}, + 'schema_version' => $VERSION, }, ], }, @@ -213,16 +202,6 @@ $DbSchema = { # attributes of default system { 'system_id' => 0, - 'name' => 'automnt_dir', - 'value' => '', - }, - { - 'system_id' => 0, - 'name' => 'automnt_src', - 'value' => '', - }, - { - 'system_id' => 0, 'name' => 'country', 'value' => "$country", }, @@ -233,21 +212,6 @@ $DbSchema = { }, { 'system_id' => 0, - 'name' => 'hw_graphic', - 'value' => '', - }, - { - 'system_id' => 0, - 'name' => 'hw_monitor', - 'value' => '', - }, - { - 'system_id' => 0, - 'name' => 'hw_mouse', - 'value' => '', - }, - { - 'system_id' => 0, 'name' => 'late_dm', 'value' => 'no', }, @@ -258,52 +222,12 @@ $DbSchema = { }, { 'system_id' => 0, - 'name' => 'nis_domain', - 'value' => '', - }, - { - 'system_id' => 0, - 'name' => 'nis_servers', - 'value' => '', - }, - { - 'system_id' => 0, - 'name' => 'ramfs_fsmods', - 'value' => '', - }, - { - 'system_id' => 0, - 'name' => 'ramfs_miscmods', - 'value' => '', - }, - { - 'system_id' => 0, 'name' => 'ramfs_nicmods', 'value' => 'forcedeth e1000 e100 tg3 via-rhine r8169 pcnet32', }, { 'system_id' => 0, - 'name' => 'ramfs_screen', - 'value' => '', - }, - { - 'system_id' => 0, - 'name' => 'sane_scanner', - 'value' => '', - }, - { - 'system_id' => 0, - 'name' => 'scratch', - 'value' => '', - }, - { - 'system_id' => 0, - 'name' => 'slxgrp', - 'value' => '', - }, - { - 'system_id' => 0, 'name' => 'start_alsasound', 'value' => 'yes', }, @@ -409,23 +333,301 @@ $DbSchema = { ################################################################################ ### -### Load the available AttrInfo-modules and build a hash containing info about -### all known attributes from the data contained in those modules. +### standard methods +### +################################################################################ +sub new +{ + my $class = shift; + + my $self = { + }; + + return bless $self, $class; +} + +sub checkAndUpgradeDBSchemaIfNecessary +{ + my $self = shift; + my $metaDB = shift; + + vlog(2, "trying to determine schema version..."); + my $currVersion = $metaDB->schemaFetchDBVersion(); + if (!defined $currVersion) { + # that's bad, someone has messed with our DB: there is a + # database, but the 'meta'-table is empty. + # There might still be data in the other tables, but we have no way to + # find out which schema version they're in. So it's safer to give up. + croak _tr('Could not determine schema version of database'); + } + + if ($currVersion == 0) { + vlog(1, _tr('Creating DB (schema version: %s)', $DbSchema->{version})); + foreach my $tableName (keys %{$DbSchema->{tables}}) { + # create table (optionally inserting default values, too) + $metaDB->schemaAddTable( + $tableName, + $DbSchema->{tables}->{$tableName}->{cols}, + $DbSchema->{tables}->{$tableName}->{vals} + ); + } + $metaDB->schemaSetDBVersion($DbSchema->{version}); + vlog(1, _tr('DB has been created successfully')); + } elsif ($currVersion < $DbSchema->{version}) { + vlog( + 1, + _tr( + 'Our schema-version is %s, DB is %s, upgrading DB...', + $DbSchema->{version}, $currVersion + ) + ); + $self->_schemaUpgradeDBFrom($metaDB, $currVersion); + $metaDB->schemaSetDBVersion($DbSchema->{version}); + vlog(1, _tr('upgrade done')); + } else { + vlog(1, _tr('DB matches current schema version (%s)', $currVersion)); + } + + return 1; +} + +sub getColumnsOfTable +{ + my $self = shift; + my $tableName = shift; + + return + map { (/^(\w+)\W/) ? $1 : $_; } + @{$DbSchema->{tables}->{$tableName}->{cols}}; +} + +################################################################################ +### +### methods for upgrading the DB schema ### ################################################################################ +sub _schemaUpgradeDBFrom +{ + my $self = shift; + my $metaDB = shift; + my $currVersion = shift; -%AttributeInfo = (); + $self->_upgradeDBTo0_2($metaDB) if $currVersion < 0.2; + + return 1; +} -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}; +sub _upgradeDBTo0_2 +{ + my $self = shift; + my $metaDB = shift; + + # move attributes into separate tables ... + # + # ... system attributes ... + $metaDB->schemaAddTable( + 'system_attr', + [ + 'id:pk', + 'system_id:fk', + 'name:s.128', + 'value:s.255', + ] + ); + foreach my $system ($metaDB->fetchSystemByFilter()) { + my %attrs; + foreach my $key (keys %$system) { + next if substr($key, 0, 5) ne 'attr_'; + my $attrValue = $system->{$key} || ''; + next if $system->{id} > 0 && !length($attrValue); + my $newAttrName = substr($key, 5); + $attrs{$newAttrName} = $attrValue; + } + $metaDB->setSystemAttrs($system->{id}, \%attrs); + } + $metaDB->schemaDropColumns( + 'system', + [ + 'attr_automnt_dir', + 'attr_automnt_src', + 'attr_country', + 'attr_dm_allow_shutdown', + 'attr_hw_graphic', + 'attr_hw_monitor', + 'attr_hw_mouse', + 'attr_late_dm', + 'attr_netbios_workgroup', + 'attr_nis_domain', + 'attr_nis_servers', + 'attr_ramfs_fsmods', + 'attr_ramfs_miscmods', + 'attr_ramfs_nicmods', + 'attr_ramfs_screen', + 'attr_sane_scanner', + 'attr_scratch', + 'attr_slxgrp', + 'attr_start_alsasound', + 'attr_start_atd', + 'attr_start_cron', + 'attr_start_dreshal', + 'attr_start_ntp', + 'attr_start_nfsv4', + 'attr_start_printer', + 'attr_start_samba', + 'attr_start_snmp', + 'attr_start_sshd', + 'attr_start_syslog', + 'attr_start_x', + 'attr_start_xdmcp', + 'attr_tex_enable', + 'attr_timezone', + 'attr_tvout', + 'attr_vmware', + ], + [ + 'id:pk', + 'export_id:fk', + 'name:s.64', + 'label:s.64', + 'kernel:s.128', + 'kernel_params:s.512', + 'hidden:b', + 'comment:s.1024', + ] + ); + # + # ... client attributes ... + $metaDB->schemaAddTable( + 'client_attr', + [ + 'id:pk', + 'client_id:fk', + 'name:s.128', + 'value:s.255', + ] + ); + foreach my $client ($metaDB->fetchClientByFilter()) { + my %attrs; + foreach my $key (keys %$client) { + next if substr($key, 0, 5) ne 'attr_'; + my $attrValue = $client->{$key} || ''; + next if !length($attrValue); + my $newAttrName = substr($key, 5); + $attrs{$newAttrName} = $attrValue; + } + $metaDB->setClientAttrs($client->{id}, \%attrs); } + $metaDB->schemaDropColumns( + 'client', + [ + 'attr_automnt_dir', + 'attr_automnt_src', + 'attr_country', + 'attr_dm_allow_shutdown', + 'attr_hw_graphic', + 'attr_hw_monitor', + 'attr_hw_mouse', + 'attr_late_dm', + 'attr_netbios_workgroup', + 'attr_nis_domain', + 'attr_nis_servers', + 'attr_sane_scanner', + 'attr_scratch', + 'attr_slxgrp', + 'attr_start_alsasound', + 'attr_start_atd', + 'attr_start_cron', + 'attr_start_dreshal', + 'attr_start_ntp', + 'attr_start_nfsv4', + 'attr_start_printer', + 'attr_start_samba', + 'attr_start_snmp', + 'attr_start_sshd', + 'attr_start_syslog', + 'attr_start_x', + 'attr_start_xdmcp', + 'attr_tex_enable', + 'attr_timezone', + 'attr_tvout', + 'attr_vmware', + ], + [ + 'id:pk', + 'name:s.128', + 'mac:s.20', + 'boot_type:s.20', + 'unbootable:b', + 'kernel_params:s.128', + 'comment:s.1024', + ] + ); + # + # ... group attributes ... + $metaDB->schemaAddTable( + 'group_attr', + [ + 'id:pk', + 'group_id:fk', + 'name:s.128', + 'value:s.255', + ] + ); + foreach my $group ($metaDB->fetchGroupByFilter()) { + my %attrs; + foreach my $key (keys %$group) { + next if substr($key, 0, 5) ne 'attr_'; + my $attrValue = $group->{$key} || ''; + next if !length($attrValue); + my $newAttrName = substr($key, 5); + $attrs{$newAttrName} = $attrValue; + } + $metaDB->setGroupAttrs($group->{id}, \%attrs); + } + $metaDB->schemaDropColumns( + 'groups', + [ + 'attr_automnt_dir', + 'attr_automnt_src', + 'attr_country', + 'attr_dm_allow_shutdown', + 'attr_hw_graphic', + 'attr_hw_monitor', + 'attr_hw_mouse', + 'attr_late_dm', + 'attr_netbios_workgroup', + 'attr_nis_domain', + 'attr_nis_servers', + 'attr_sane_scanner', + 'attr_scratch', + 'attr_slxgrp', + 'attr_start_alsasound', + 'attr_start_atd', + 'attr_start_cron', + 'attr_start_dreshal', + 'attr_start_ntp', + 'attr_start_nfsv4', + 'attr_start_printer', + 'attr_start_samba', + 'attr_start_snmp', + 'attr_start_sshd', + 'attr_start_syslog', + 'attr_start_x', + 'attr_start_xdmcp', + 'attr_tex_enable', + 'attr_timezone', + 'attr_tvout', + 'attr_vmware', + ], + [ + 'id:pk', + 'name:s.128', + 'priority:i', + 'comment:s.1024', + ] + ); + + return 1; } 1; diff --git a/config-db/OpenSLX/MetaDB/DBI.pm b/config-db/OpenSLX/MetaDB/DBI.pm index 98754777..a6d2eef0 100644 --- a/config-db/OpenSLX/MetaDB/DBI.pm +++ b/config-db/OpenSLX/MetaDB/DBI.pm @@ -713,24 +713,16 @@ sub changeGlobalInfo sub addSystem { - my $self = shift; - my $valRows = shift; - - # separate the attribute hashes ... - my @attrValRows - = map { - my $attrs = $_->{attrs}; - delete $_->{attrs}; - $attrs; - } - @$valRows; + my $self = shift; + my $valRows = shift; + my $attrValRows = shift; # ... store the systems to get the IDs ... my @systemIDs = $self->_doInsert('system', $valRows); # ... finally store the individual attribute sets foreach my $id (@systemIDs) { - my $attrs = shift @attrValRows; + my $attrs = shift @$attrValRows; next if !defined $attrs; return if !$self->setSystemAttrs($id, $attrs); } @@ -751,17 +743,11 @@ sub changeSystem my $self = shift; my $systemIDs = shift; my $valRows = shift; + my $attrValRows = shift; - # separate the attribute hashes and store them individually - my @attrValRows - = map { - my $attrs = $_->{attrs}; - delete $_->{attrs}; - $attrs; - } - @$valRows; + # store the attribute hashes individually foreach my $id (@$systemIDs) { - my $attrs = shift @attrValRows; + my $attrs = shift @$attrValRows; next if !defined $attrs; return if !$self->setSystemAttrs($id, $attrs); } @@ -776,20 +762,21 @@ sub setSystemAttrs my $systemID = shift; my $attrs = shift; - # we take the simple path and remove all attributes ... + # for now we take the simple path and remove all attributes ... return if !$self->_doDelete('system_attr', [ $systemID ], 'system_id'); # ... and (re-)insert the given ones - foreach my $key (keys %$attrs) { - return if !$self->_doInsert( - 'system_attr', [ { - system_id => $systemID, - name => $key, - value => $attrs->{$key}, - } ] - ); - } - return 1; + my @attrData + = map { + { + system_id => $systemID, + name => $_, + value => $attrs->{$_}, + } + } + grep { defined $attrs->{$_} } + keys %$attrs; + return $self->_doInsert('system_attr', [ @attrData ]); } sub setClientIDsOfSystem @@ -822,22 +809,14 @@ sub addClient { my $self = shift; my $valRows = shift; - - # separate the attribute hashes ... - my @attrValRows - = map { - my $attrs = $_->{attrs}; - delete $_->{attrs}; - $attrs; - } - @$valRows; + my $attrValRows = shift; # ... store the clients to get the IDs ... my @clientIDs = $self->_doInsert('client', $valRows); # ... finally store the individual attribute sets foreach my $id (@clientIDs) { - my $attrs = shift @attrValRows; + my $attrs = shift @$attrValRows; next if !defined $attrs; return if !$self->setClientAttrs($id, $attrs); } @@ -855,20 +834,14 @@ sub removeClient sub changeClient { - my $self = shift; - my $clientIDs = shift; - my $valRows = shift; + my $self = shift; + my $clientIDs = shift; + my $valRows = shift; + my $attrValRows = shift; - # separate the attribute hashes and store them individually - my @attrValRows - = map { - my $attrs = $_->{attrs}; - delete $_->{attrs}; - $attrs; - } - @$valRows; + # store the attribute hashes individually foreach my $id (@$clientIDs) { - my $attrs = shift @attrValRows; + my $attrs = shift @$attrValRows; next if !defined $attrs; return if !$self->setClientAttrs($id, $attrs); } @@ -883,19 +856,21 @@ sub setClientAttrs my $clientID = shift; my $attrs = shift; - # we take the simple path and remove all attributes ... + # for now we take the simple path and remove all attributes ... return if !$self->_doDelete('client_attr', [ $clientID ], 'client_id'); # ... and (re-)insert the given ones - foreach my $key (keys %$attrs) { - return if !$self->_doInsert( - 'client_attr', [ { - client_id => $clientID, - name => $key, - value => $attrs->{$key}, - } ] - ); - } + my @attrData + = map { + { + client_id => $clientID, + name => $_, + value => $attrs->{$_}, + } + } + grep { defined $attrs->{$_} } + keys %$attrs; + return $self->_doInsert('client_attr', [ @attrData ]); return 1; } @@ -927,24 +902,16 @@ sub setGroupIDsOfClient sub addGroup { - my $self = shift; - my $valRows = shift; - - # separate the attribute hashes ... - my @attrValRows - = map { - my $attrs = $_->{attrs}; - delete $_->{attrs}; - $attrs; - } - @$valRows; + my $self = shift; + my $valRows = shift; + my $attrValRows = shift; # ... store the groups to get the IDs ... my @groupIDs = $self->_doInsert('groups', $valRows); # ... finally store the individual attribute sets foreach my $id (@groupIDs) { - my $attrs = shift @attrValRows; + my $attrs = shift @$attrValRows; next if !defined $attrs; return if !$self->setGroupAttrs($id, $attrs); } @@ -962,20 +929,14 @@ sub removeGroup sub changeGroup { - my $self = shift; - my $groupIDs = shift; - my $valRows = shift; + my $self = shift; + my $groupIDs = shift; + my $valRows = shift; + my $attrValRows = shift; - # separate the attribute hashes and store them individually - my @attrValRows - = map { - my $attrs = $_->{attrs}; - delete $_->{attrs}; - $attrs; - } - @$valRows; + # store the attribute hashes individually foreach my $id (@$groupIDs) { - my $attrs = shift @attrValRows; + my $attrs = shift @$attrValRows; next if !defined $attrs; return if !$self->setGroupAttrs($id, $attrs); } @@ -990,19 +951,21 @@ sub setGroupAttrs my $groupID = shift; my $attrs = shift; - # we take the simple path and remove all attributes ... + # for now we take the simple path and remove all attributes ... return if !$self->_doDelete('group_attr', [ $groupID ], 'group_id'); # ... and (re-)insert the given ones - foreach my $key (keys %$attrs) { - return if !$self->_doInsert( - 'group_attr', [ { - group_id => $groupID, - name => $key, - value => $attrs->{$key}, - } ] - ); - } + my @attrData + = map { + { + group_id => $groupID, + name => $_, + value => $attrs->{$_}, + } + } + grep { defined $attrs->{$_} } + keys %$attrs; + return $self->_doInsert('group_attr', [ @attrData ]); return 1; } @@ -1089,16 +1052,6 @@ sub schemaFetchDBVersion return $row->{schema_version}; } -sub schemaUpgradeDBFrom -{ - my $self = shift; - my $currVersion = shift; - - $self->_upgradeDBTo0_2() if $currVersion < 0.2; - - return 1; -} - sub schemaSetDBVersion { my $self = shift; @@ -1317,218 +1270,6 @@ sub schemaChangeColumns return; } -sub _upgradeDBTo0_2 -{ - my $self = shift; - - # move attributes into separate tables ... - # - # ... system attributes ... - $self->schemaAddTable( - 'system_attr', - [ - 'id:pk', - 'system_id:fk', - 'name:s.128', - 'value:s.255', - ] - ); - foreach my $system ($self->fetchSystemByFilter()) { - my %attrs; - foreach my $key (keys %$system) { - next if substr($key, 0, 5) ne 'attr_'; - my $attrValue = $system->{$key} || ''; - next if $system->{id} > 0 && !length($attrValue); - my $newAttrName = substr($key, 5); - $attrs{$newAttrName} = $attrValue; - } - $self->setSystemAttrs($system->{id}, \%attrs); - } - $self->schemaDropColumns( - 'system', - [ - 'attr_automnt_dir', - 'attr_automnt_src', - 'attr_country', - 'attr_dm_allow_shutdown', - 'attr_hw_graphic', - 'attr_hw_monitor', - 'attr_hw_mouse', - 'attr_late_dm', - 'attr_netbios_workgroup', - 'attr_nis_domain', - 'attr_nis_servers', - 'attr_ramfs_fsmods', - 'attr_ramfs_miscmods', - 'attr_ramfs_nicmods', - 'attr_ramfs_screen', - 'attr_sane_scanner', - 'attr_scratch', - 'attr_slxgrp', - 'attr_start_alsasound', - 'attr_start_atd', - 'attr_start_cron', - 'attr_start_dreshal', - 'attr_start_ntp', - 'attr_start_nfsv4', - 'attr_start_printer', - 'attr_start_samba', - 'attr_start_snmp', - 'attr_start_sshd', - 'attr_start_syslog', - 'attr_start_x', - 'attr_start_xdmcp', - 'attr_tex_enable', - 'attr_timezone', - 'attr_tvout', - 'attr_vmware', - ], - [ - 'id:pk', - 'export_id:fk', - 'name:s.64', - 'label:s.64', - 'kernel:s.128', - 'kernel_params:s.512', - 'hidden:b', - 'comment:s.1024', - ] - ); - # - # ... client attributes ... - $self->schemaAddTable( - 'client_attr', - [ - 'id:pk', - 'client_id:fk', - 'name:s.128', - 'value:s.255', - ] - ); - foreach my $client ($self->fetchClientByFilter()) { - my %attrs; - foreach my $key (keys %$client) { - next if substr($key, 0, 5) ne 'attr_'; - my $attrValue = $client->{$key} || ''; - next if !length($attrValue); - my $newAttrName = substr($key, 5); - $attrs{$newAttrName} = $attrValue; - } - $self->setClientAttrs($client->{id}, \%attrs); - } - $self->schemaDropColumns( - 'client', - [ - 'attr_automnt_dir', - 'attr_automnt_src', - 'attr_country', - 'attr_dm_allow_shutdown', - 'attr_hw_graphic', - 'attr_hw_monitor', - 'attr_hw_mouse', - 'attr_late_dm', - 'attr_netbios_workgroup', - 'attr_nis_domain', - 'attr_nis_servers', - 'attr_sane_scanner', - 'attr_scratch', - 'attr_slxgrp', - 'attr_start_alsasound', - 'attr_start_atd', - 'attr_start_cron', - 'attr_start_dreshal', - 'attr_start_ntp', - 'attr_start_nfsv4', - 'attr_start_printer', - 'attr_start_samba', - 'attr_start_snmp', - 'attr_start_sshd', - 'attr_start_syslog', - 'attr_start_x', - 'attr_start_xdmcp', - 'attr_tex_enable', - 'attr_timezone', - 'attr_tvout', - 'attr_vmware', - ], - [ - 'id:pk', - 'name:s.128', - 'mac:s.20', - 'boot_type:s.20', - 'unbootable:b', - 'kernel_params:s.128', - 'comment:s.1024', - ] - ); - # - # ... group attributes ... - $self->schemaAddTable( - 'group_attr', - [ - 'id:pk', - 'group_id:fk', - 'name:s.128', - 'value:s.255', - ] - ); - foreach my $group ($self->fetchGroupByFilter()) { - my %attrs; - foreach my $key (keys %$group) { - next if substr($key, 0, 5) ne 'attr_'; - my $attrValue = $group->{$key} || ''; - next if !length($attrValue); - my $newAttrName = substr($key, 5); - $attrs{$newAttrName} = $attrValue; - } - $self->setGroupAttrs($group->{id}, \%attrs); - } - $self->schemaDropColumns( - 'groups', - [ - 'attr_automnt_dir', - 'attr_automnt_src', - 'attr_country', - 'attr_dm_allow_shutdown', - 'attr_hw_graphic', - 'attr_hw_monitor', - 'attr_hw_mouse', - 'attr_late_dm', - 'attr_netbios_workgroup', - 'attr_nis_domain', - 'attr_nis_servers', - 'attr_sane_scanner', - 'attr_scratch', - 'attr_slxgrp', - 'attr_start_alsasound', - 'attr_start_atd', - 'attr_start_cron', - 'attr_start_dreshal', - 'attr_start_ntp', - 'attr_start_nfsv4', - 'attr_start_printer', - 'attr_start_samba', - 'attr_start_snmp', - 'attr_start_sshd', - 'attr_start_syslog', - 'attr_start_x', - 'attr_start_xdmcp', - 'attr_tex_enable', - 'attr_timezone', - 'attr_tvout', - 'attr_vmware', - ], - [ - 'id:pk', - 'name:s.128', - 'priority:i', - 'comment:s.1024', - ] - ); - - return 1; -} - 1; =head1 NAME |