From 1417b305c990fb428f4089052826a5ba1329c7cf Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sat, 28 Oct 2006 14:23:49 +0000 Subject: * renamed several scripts to our new convention: no .pl for user-executable stuff... git-svn-id: http://svn.openslx.org/svn/openslx/trunk@475 95ad53e4-c205-0410-b2fa-d234c58c8868 --- config-db/OpenSLX/MetaDB/Base.pm | 729 +++++++++++++++++++-------- config-db/devel-tools/test-config-db.pl | 202 ++++++++ config-db/devel-tools/test-config-demuxer.pl | 220 ++++++++ config-db/slxconfig-demuxer | 651 ++++++++++++++++++++++++ config-db/slxconfig-demuxer.pl | 651 ------------------------ config-db/slxldd | 199 ++++++++ config-db/slxldd.pl | 199 -------- config-db/slxsettings | 317 ++++++++++++ config-db/slxsetup | 341 +++++++++++++ config-db/slxsetup-test-data-simple.pl | 341 ------------- config-db/slxsetup.pl | 317 ------------ config-db/test-config-db.pl | 202 -------- config-db/test-config-demuxer.pl | 220 -------- 13 files changed, 2461 insertions(+), 2128 deletions(-) create mode 100755 config-db/devel-tools/test-config-db.pl create mode 100755 config-db/devel-tools/test-config-demuxer.pl create mode 100755 config-db/slxconfig-demuxer delete mode 100755 config-db/slxconfig-demuxer.pl create mode 100755 config-db/slxldd delete mode 100755 config-db/slxldd.pl create mode 100755 config-db/slxsettings create mode 100755 config-db/slxsetup delete mode 100755 config-db/slxsetup-test-data-simple.pl delete mode 100755 config-db/slxsetup.pl delete mode 100755 config-db/test-config-db.pl delete mode 100755 config-db/test-config-demuxer.pl diff --git a/config-db/OpenSLX/MetaDB/Base.pm b/config-db/OpenSLX/MetaDB/Base.pm index 6a0371b0..6766e795 100644 --- a/config-db/OpenSLX/MetaDB/Base.pm +++ b/config-db/OpenSLX/MetaDB/Base.pm @@ -4,171 +4,23 @@ # # Oliver Tappe # -################################################################################ -# OpenSLX::MetaDB:Base - the base class for all MetaDB drivers -# -# Copyright 2006 by Oliver Tappe - all rights reserved. -# -# You may distribute this module under the terms of the GNU GPL v2. -################################################################################ - package OpenSLX::MetaDB::Base; +use strict; + use vars qw($VERSION); $VERSION = 1.01; # API-version . implementation-version -################################################################################ -=pod - -=head1 NAME - -OpenSLX::MetaDB::Base - the base class for all MetaDB drivers - -=head1 SYNOPSIS - - package OpenSLX::MetaDB::coolnewDB; - - use vars qw(@ISA $VERSION); - @ISA = ('OpenSLX::MetaDB::Base'); - $VERSION = 1.01; - - my $superVersion = $OpenSLX::MetaDB::Base::VERSION; - if ($superVersion < $VERSION) { - confess _tr('Unable to load module <%s> (Version <%s> required)', - 'OpenSLX::MetaDB::Base', $VERSION); - } - - use coolnewDB; - - sub new - { - my $class = shift; - my $self = {}; - return bless $self, $class; - } - - sub connectConfigDB - { - my $self = shift; - - my $dbName = $openslxConfig{'db-name'}; - vlog 1, "trying to connect to coolnewDB-database <$dbName>"; - $self->{'dbh'} = ... # get connection handle from coolnewDB - } - - sub disconnectConfigDB - { - my $self = shift; - - $self->{'dbh'}->disconnect; - } - - # override all methods of OpenSLX::MetaDB::Base in order to implement - # a full MetaDB driver - ... - -I> - -=head1 DESCRIPTION - -This class defines the MetaDB interface for the OpenSLX. - -Aim of the MetaDB abstraction is to make it possible to use a large set -of different databases (from CSV-files to a fullblown Oracle-installation) -transparently. - -While OpenSLX::ConfigDB represents the data layer to the outside world, each -implementation of OpenSLX::MetaDB::Base provides a backend for a specific database. - -This way, the different OpenSLX-scripts do not have to burden -themselves with any DB-specific details, they just request the data they want -from the ConfigDB-layer and that in turn creates and communicates with the -appropriate MetaDB driver in order to connect to the database and fetch and/or -change the data as instructed. - -The MetaDB interface contains of four different parts: - -=over - -=item - L (connection handling and utilities) - -=item - L (getting data) - -=item - L (adding, removing and changing data) - -=item - L (migrating between different DB-versions) - -=back - -In order to implement a MetaDB driver for a specific database, you need -to inherit from B and implement the full interface. As this -is quite some work, it might be wiser to actually inherit your driver from -B>, which is a default implementation for SQL databases. - -If there is a DBD-driver for the database your new MetaDB driver wants to talk -to then all you need to do is inherit from B and then -reimplement L> (and maybe some other methods in order to -improve efficiency). - -=cut - -################################################################################ -use strict; use Carp; ################################################################################ - -=head2 Basic Methods - -The following basic methods need to be implemented in a MetaDB driver: - -=over - -=cut - +### basic functions ################################################################################ sub new { confess "Don't create OpenSLX::MetaDB::Base - objects directly!"; } -=item C - - $metaDB->connectConfigDB($dbParams); - -Tries to establish a connection to the DBMS that this MetaDB driver deals with. -The global configuration hash C<%config> contains further info about the -requested connection. When implementing this method, you may have to look at -the following entries in order to find out which database to connect to: - -=over - -=item C<$config{'db-basepath'}> - -basic path to openslx database, defaults to path of running script - -=item C<$config{'db-datadir'}> - -data folder created under db-basepath, default depends on db-type (many -DBMSs don't have such a folder, as they do not store the data in the -filesystem). - -=item C<$config{'db-spec'}> - -full specification of database, a special string defining the -precise database to connect to (this allows connecting to a database -that requires specifications which aren't cared for by the existing -C<%config>-entries). - -=item C<$config{'db-name'}> - -the precise name of the database that should be connected (defaults to 'openslx'). - -=back - -=cut - sub connectConfigDB { } @@ -182,51 +34,8 @@ sub quote } ################################################################################ - -=back - -=head2 Data Access Methods - -The following methods need to be implemented in a MetaDB driver in order to -allow the user to access data: - -=over - -=cut - +### data access interface ################################################################################ - -=item C - - my $filter = { 'os_type' => 'LINUX' }; - my $resultCols = 'id,name,descr'; - my @systems = $metaDBH->fetchSystemsByFilter($filter, $resultCols); - -Fetches and returns information about all systems match the given filter. - -=over - -=item Param C<$filter> - -A hash-ref defining the filter criteria to be applied. Each key corresponds -to a DB column and the (hash-)value contains the respective column value. [At a -later stage, this might be improved to support more structured approach to -filtering (with boolean operators and more)]. - -=item Param C<$resultCols> [Optional] - -A comma-separated list of colunm names that shall be returned. If not defined, -all available data must be returned. - -=item Return Value - -An array of hash-refs containing the resulting data rows. - - -=back - -=cut - sub fetchVendorOSesByFilter { } @@ -434,8 +243,532 @@ sub schemaChangeColumns { } -=back +1; +################################################################################ -=cut +=pod + +=head1 NAME + +OpenSLX::MetaDB::Base - the base class for all MetaDB drivers + +=head1 SYNOPSIS + + package OpenSLX::MetaDB::coolnewDB; + + use vars qw(@ISA $VERSION); + @ISA = ('OpenSLX::MetaDB::Base'); + $VERSION = 1.01; + + my $superVersion = $OpenSLX::MetaDB::Base::VERSION; + if ($superVersion < $VERSION) { + confess _tr('Unable to load module <%s> (Version <%s> required)', + 'OpenSLX::MetaDB::Base', $VERSION); + } + + use coolnewDB; + + sub new + { + my $class = shift; + my $self = {}; + return bless $self, $class; + } + + sub connectConfigDB + { + my $self = shift; + + my $dbName = $openslxConfig{'db-name'}; + vlog 1, "trying to connect to coolnewDB-database <$dbName>"; + $self->{'dbh'} = ... # get connection handle from coolnewDB + } + + sub disconnectConfigDB + { + my $self = shift; + + $self->{'dbh'}->disconnect; + } + + # override all methods of OpenSLX::MetaDB::Base in order to implement + # a full MetaDB driver + ... + +I> + +=head1 DESCRIPTION + +This class defines the MetaDB interface for the OpenSLX. + +Aim of the MetaDB abstraction is to make it possible to use a large set +of different databases (from CSV-files to a fullblown Oracle-installation) +transparently. + +While OpenSLX::ConfigDB represents the data layer to the outside world, each +implementation of OpenSLX::MetaDB::Base provides a backend for a specific database. + +This way, the different OpenSLX-scripts do not have to burden +themselves with any DB-specific details, they just request the data they want +from the ConfigDB-layer and that in turn creates and communicates with the +appropriate MetaDB driver in order to connect to the database and fetch and/or +change the data as instructed. + +The MetaDB interface contains of four different parts: + +=over + +=item - L (connection handling and utilities) -1; \ No newline at end of file +=item - L (getting data) + +=item - L (adding, removing and changing data) + +=item - L (migrating between different DB-versions) + +=back + +In order to implement a MetaDB driver for a specific database, you need +to inherit from B and implement the full interface. As this +is quite some work, it might be wiser to actually inherit your driver from +B>, which is a default implementation for SQL databases. + +If there is a DBD-driver for the database your new MetaDB driver wants to talk +to then all you need to do is inherit from B and then +reimplement L> (and maybe some other methods in order to +improve efficiency). + +=head1 Special Concepts + +=over + +=item C + +A filter is a hash-ref defining the filter criteria to be applied to a database +query. Each key of the filter corresponds to a DB column and the (hash-)value +contains the respective column value. + +[At a later stage, this will be improved to support a more structured approach +to filtering (with boolean operators and hierarchical expressions)]. + +=back + +=head1 Methods + +=head2 Basic Methods + +The following basic methods need to be implemented in a MetaDB driver: + +=over + +=item C + +Tries to establish a connection to the DBMS that this MetaDB driver deals with. +The global configuration hash C<%config> contains further info about the +requested connection. When implementing this method, you may have to look at +the following entries in order to find out which database to connect to: + +=over + +=item C<$config{'db-basepath'}> + +Basic path to openslx database, defaults to path of running script + +=item C<$config{'db-datadir'}> + +Data folder created under db-basepath, default depends on db-type (many +DBMSs don't have such a folder, as they do not store the data in the +filesystem). + +=item C<$config{'db-spec'}> + +Full specification of database, a special string defining the +precise database to connect to (this allows connecting to a database +that requires specifications which aren't cared for by the existing +C<%config>-entries). + +=item C<$config{'db-name'}> + +The precise name of the database that should be connected (defaults to 'openslx'). + +=back + +=item C + +Tears down the connection to the DBMS that this MetaDB driver deals with and +cleans up. + +=item C + +Returns the given string quoted such that it can be used in SQL-statements +(with respect to the corresponding DBMS). + +This usually involves putting +single quotes around the string and escaping any single quote characters +enclosed in the given string with a backslash. + +=back + +=head2 Data Access Methods + +The following methods need to be implemented in a MetaDB driver in order to +allow the user to access data: + +=over + +=item C + +Fetches and returns information about all vendor-OSes that match the given +filter. + +=over + +=item Param C + +A hash-ref containing the filter criteria that shall be applied - default +is no filtering. See L for more info. + +=item Param C + +A string listing the columns that shall be returned - default is all columns. + +=item Return Value + +An array of hash-refs containing the resulting data rows. + +=back + +=item C + +Fetches and returns information the vendor-OSes with the given IDs. + +=over + +=item Param C + +An array of the vendor-OS-IDs you are interested in. + +=item Param C + +A string listing the columns that shall be returned - default is all columns. + +=item Return Value + +An array of hash-refs containing the resulting data rows. + +=back + +=item C + +Fetches and returns information about all systems that match the given filter. + +=over + +=item Param C<$filter> + +A hash-ref containing the filter criteria that shall be applied - default +is no filtering. See L for more info. + +=item Param C<$resultCols> [Optional] + +A comma-separated list of colunm names that shall be returned. If not defined, +all available data must be returned. + +=item Return Value + +An array of hash-refs containing the resulting data rows. + +=back + +=item C + +Fetches and returns information the systems with the given IDs. + +=over + +=item Param C + +An array of the system-IDs you are interested in. + +=item Param C + +A string listing the columns that shall be returned - default is all columns. + +=item Return Value + +An array of hash-refs containing the resulting data rows. + +=back + +=item C + +Fetches the IDs of all systems that make use of the vendor-OS with the given ID. + +=over + +=item Param C + +ID of the vendor-OS whose systems shall be returned. + +=item Return Value + +An array of system-IDs. + +=back + +=item C + +Fetches the IDs of all systems that are used by the client with the given +ID. + +=over + +=item Param C + +ID of the client whose systems shall be returned. + +=item Return Value + +An array of system-IDs. + +=back + +=item C + +Fetches the IDs of all systems that are part of the group with the given +ID. + +=over + +=item Param C + +ID of the group whose systems shall be returned. + +=item Return Value + +An array of system-IDs. + +=back + +=item C + +Fetches and returns information about all system variants that match the given +filter. + +=over + +=item Param C<$filter> + +A hash-ref containing the filter criteria that shall be applied - default +is no filtering. See L for more info. + +=item Param C<$resultCols> [Optional] + +A comma-separated list of colunm names that shall be returned. If not defined, +all available data must be returned. + +=item Return Value + +An array of hash-refs containing the resulting data rows. + +=back + +=item C + +Fetches and returns information the systems variants with the given IDs. + +=over + +=item Param C + +An array of the system-variant-IDs you are interested in. + +=item Param C + +A string listing the columns that shall be returned - default is all columns. + +=item Return Value + +An array of hash-refs containing the resulting data rows. + +=back + +=item C + +Fetches the IDs of all system variants that belong to the system with the given +ID. + +=over + +=item Param C + +ID of the system whose variants shall be returned. + +=item Return Value + +An array of system-variant-IDs. + +=back + +=item C + +Fetches and returns information about all clients that match the given filter. + +=over + +=item Param C<$filter> + +A hash-ref containing the filter criteria that shall be applied - default +is no filtering. See L for more info. + +=item Param C<$resultCols> [Optional] + +A comma-separated list of colunm names that shall be returned. If not defined, +all available data must be returned. + +=item Return Value + +An array of hash-refs containing the resulting data rows. + +=back + +=item C + +Fetches and returns information the clients with the given IDs. + +=over + +=item Param C + +An array of the client-IDs you are interested in. + +=item Param C + +A string listing the columns that shall be returned - default is all columns. + +=item Return Value + +An array of hash-refs containing the resulting data rows. + +=back + +=item C + +Fetches the IDs of all clients that make use of the system with the given +ID. + +=over + +=item Param C + +ID of the system whose clients shall be returned. + +=item Return Value + +An array of client-IDs. + +=back + +=item C + +Fetches the IDs of all clients that are part of the group with the given +ID. + +=over + +=item Param C + +ID of the group whose clients shall be returned. + +=item Return Value + +An array of client-IDs. + +=back + + + +=item C + +Fetches and returns information about all groups that match the given filter. + +=over + +=item Param C<$filter> + +A hash-ref containing the filter criteria that shall be applied - default +is no filtering. See L for more info. + +=item Param C<$resultCols> [Optional] + +A comma-separated list of colunm names that shall be returned. If not defined, +all available data must be returned. + +=item Return Value + +An array of hash-refs containing the resulting data rows. + +=back + + + +=item C + +Fetches and returns information the groups with the given IDs. + +=over + +=item Param C + +An array of the group-IDs you are interested in. + +=item Param C + +A string listing the columns that shall be returned - default is all columns. + +=item Return Value + +An array of hash-refs containing the resulting data rows. + +=back + + + +=item C + +Fetches the IDs of all groups that contain the client with the given +ID. + +=over + +=item Param C + +ID of the client whose groups shall be returned. + +=item Return Value + +An array of client-IDs. + +=back + + + +=item C + +Fetches the IDs of all groups that contain the system with the given +ID. + +=over + +=item Param C + +ID of the system whose groups shall be returned. + +=item Return Value + +An array of client-IDs. + +=back + +=cut diff --git a/config-db/devel-tools/test-config-db.pl b/config-db/devel-tools/test-config-db.pl new file mode 100755 index 00000000..ecbdbd15 --- /dev/null +++ b/config-db/devel-tools/test-config-db.pl @@ -0,0 +1,202 @@ +#! /usr/bin/perl +# +# test-config-db.pl - test-script for the OpenSLX config-db & MetaDB modules. +# +# (c) 2006 - OpenSLX.com +# +# Oliver Tappe +# +use strict; + +# add the folder this script lives in to perl's search path for modules: +use FindBin; +use lib "$FindBin::RealBin"; + # development path only (as script should never be installed) + +use OpenSLX::Basics; +use OpenSLX::ConfigDB qw(:access :manipulation); + +openslxInit(); + +my $openslxDB = connectConfigDB(); + +addVendorOS($openslxDB, { + 'name' => "suse-93-minimal", + 'descr' => "SuSE 9.3 minimale Installation", +}); + +addVendorOS($openslxDB, { + 'name' => "suse-93-KDE", + 'descr' => "SuSE 9.3 grafische Installation mit KDE", +}); + +addVendorOS($openslxDB, { + 'name' => "debian-31", + 'descr' => "Debian 3.1 Default-Installation", +}); + +my @systems; +foreach my $id (1..10) { + push @systems, { + 'name' => "name of $id", + 'descr' => "descr of $id", + 'vendor_os_id' => 1 + $id % 3, + }; +} +addSystem($openslxDB, \@systems); + +removeSystem($openslxDB, [1,3,5,7,9,11,13,15,17,19] ); + +changeSystem($openslxDB, [ 2 ], [ { 'name' => 'new name of 2'} ] ); + +changeSystem($openslxDB, [ 0 ], [ { 'attrStartX' => 'kde,gnome'} ] ); +changeSystem($openslxDB, [ 1,2,3 ], [ { 'attrHwMonitor' => '1280x1024'} ] ); +changeSystem($openslxDB, [ 4 ], [ { 'attrHwMonitor' => '800x600'} ] ); + + +changeSystem($openslxDB, 4, { 'id' => 114, 'name' => 'id should still be 4'} ); + +my $metaDB = $openslxDB->{'meta-db'}; +my $colDescrs = [ + 'id:pk', + 'name:s.30', + 'descr:s.1024', + 'counter:i', + 'hidden:b', + 'dropped1:b', + 'dropped2:b', +]; +my $initialVals = [ + { + 'name' => '123456789012345678901234567890xxx', + 'descr' => 'descr-value-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + 'counter' => 34567, + 'hidden' => 1, + 'dropped1' => 0, + 'dropped2' => 1, + }, + { + 'name' => 'name', + 'descr' => q[from_äöüß#'"$...\to_here], + 'counter' => -1, + 'hidden' => 0, + 'dropped1' => 1, + 'dropped2' => 0, + }, +]; + + +$metaDB->schemaAddTable('test', $colDescrs, $initialVals); + +$metaDB->schemaRenameTable('test', 'test2', $colDescrs); + +push @$colDescrs, 'added:s.20'; +push @$colDescrs, 'added2:s.20'; +$metaDB->schemaAddColumns('test2', + ['added:s.20', 'added2:b'], + [{'added' => 'added'}, {'added2' => '1'}], + $colDescrs); + +my @rows = $metaDB->_doSelect("SELECT * FROM test2"); +foreach my $row (@rows) { + foreach my $r (keys %$row) { + print "$r = $row->{$r}\n"; + } +} + +$colDescrs = [grep {$_ !~ m[dropped]} @$colDescrs]; +$metaDB->schemaDropColumns('test2', ['dropped1', 'dropped2'], $colDescrs); + + +$colDescrs = [ + map { + if ($_ =~ m[counter]) { + "count:i"; + } elsif ($_ =~ m[descr]) { + "description:s.30"; + } else { + $_ + } + } @$colDescrs +]; +$metaDB->schemaChangeColumns('test2', + { 'counter' => 'count:i', + 'descr' => 'description:s.30' }, + $colDescrs); + +my @rows = $metaDB->_doSelect("SELECT * FROM test2"); +foreach my $row (@rows) { + foreach my $r (keys %$row) { + print "$r = $row->{$r}\n"; + } +} + +$metaDB->schemaDropTable('test2'); + +my $clientG01ID = addClient($openslxDB, { + 'name' => "PC-G-01", + 'mac' => "00:14:85:80:00:35", + 'boot_type' => 'pxe', +}); + +my $clientG02ID = addClient($openslxDB, { + 'name' => "PC-G-02", + 'mac' => "00:14:85:80:00:36", + 'boot_type' => 'pxe', +}); + +my $clientG03ID = addClient($openslxDB, { + 'name' => "PC-G-03", + 'mac' => "00:14:85:80:00:37", + 'boot_type' => 'pxe', +}); + +my $clientG04ID = addClient($openslxDB, { + 'name' => "PC-G-04", + 'mac' => "00:14:85:80:00:38", + 'boot_type' => 'pxe', + 'unbootable' => 1, +}); + +my $clientF01ID = addClient($openslxDB, { + 'name' => "PC-F-01", + 'mac' => "00:14:85:80:00:31", + 'boot_type' => 'other', +}); + +my $clientF02ID = addClient($openslxDB, { + 'name' => "PC-F-02", + 'mac' => "00:14:85:80:00:32", + 'boot_type' => 'pxe', +}); + +my $clientF03ID = addClient($openslxDB, { + 'name' => "PC-F-03", + 'mac' => "00:14:85:80:00:33", + 'boot_type' => 'pxe', +}); + +addClientIDsToSystem($openslxDB, 6, [$clientG01ID, $clientG02ID, $clientG03ID, $clientG04ID, $clientF01ID, $clientF02ID, $clientF03ID]); + +my $group1ID = addGroup($openslxDB, { + 'name' => "Gell-PCs", + 'descr' => "Gell-Threemansion PCs from 2002", + 'attrHwMouse' => 'serial', +}); +addClientIDsToGroup($openslxDB, $group1ID, [$clientG01ID, $clientF02ID, $clientG03ID]); + +my $group2ID = addGroup($openslxDB, { + 'name' => "Teacher-PCs", + 'descr' => "all PCs sitting on teacher's desks", + 'attrHwMonitor' => '1600x1200', +}); +addClientIDsToGroup($openslxDB, $group2ID, [$clientG01ID, $clientF01ID]); +addSystemIDsToGroup($openslxDB, $group2ID, [2, 3]); + +my $group3ID = addGroup($openslxDB, { + 'name' => "PCs in room G", + 'descr' => "all PCs of room 234", +}); +addClientIDsToGroup($openslxDB, $group3ID, [$clientG01ID, $clientG02ID, $clientG03ID, $clientG04ID]); + +disconnectConfigDB($openslxDB); diff --git a/config-db/devel-tools/test-config-demuxer.pl b/config-db/devel-tools/test-config-demuxer.pl new file mode 100755 index 00000000..e5ee3aa9 --- /dev/null +++ b/config-db/devel-tools/test-config-demuxer.pl @@ -0,0 +1,220 @@ +#! /usr/bin/perl +# +# test-config-demuxer.pl - test-script for the OpenSLX config-demuxer. +# +# (c) 2006 - OpenSLX.com +# +# Oliver Tappe +# +use strict; + +# add the folder this script lives in to perl's search path for modules: +use FindBin; +use lib "$FindBin::RealBin"; + # development path only (as script should never be installed) + +use OpenSLX::Basics; +use OpenSLX::ConfigDB qw(:access :manipulation); + +openslxInit(); + +$openslxConfig{'db-name'} = 'openslx_testscript'; + # make sure to use a database of our own! + +my $openslxDB = connectConfigDB(); + +emptyDatabase($openslxDB); + +addVendorOS($openslxDB,{ + 'name' => "suse-10-minimal", + 'comment' => "SuSE 10 minimale Installation", + 'path' => "suse-10.0", + # relative to /var/lib/openslx/stage1 +}); + +addVendorOS($openslxDB, { + 'name' => "suse-10-KDE", + 'comment' => "SuSE 10 grafische Installation mit KDE", + 'path' => "suse-10.0", +}); + +addVendorOS($openslxDB, { + 'name' => "debian-31", + 'comment' => "Debian 3.1 Default-Installation", +}); + +my @systems; +foreach my $id (1..10) { + push @systems, { + 'name' => "name of $id", + 'label' => "label of $id", + 'comment' => "comment of $id", + 'vendor_os_id' => 1 + $id % 3, + 'ramfs_debug_level' => $id%2, + 'ramfs_use_glibc' => 0, + 'ramfs_use_busybox' => 0, + 'ramfs_nicmods' => ($id % 3) ? 'forcedeth e1000 e100 tg3 via-rhine r8169 pcnet32' : '', + 'ramfs_fsmods' => ($id % 3)==2 ? 'nbd ext3 nfs reiserfs xfs' : '', + 'kernel' => "boot/vmlinuz-2.6.13-15-default", + 'kernel_params' => "splash=silent", + 'export_type' => 'nfs', + }; +} +addSystem($openslxDB, \@systems); + +removeSystem($openslxDB, [1,3,5,7,9,11,13,15,17,19] ); + +changeSystem($openslxDB, [ 2 ], [ { 'name' => 'new name of 2'} ] ); + +changeSystem($openslxDB, [ 0 ], [ { 'attr_start_x' => 'kde,gnome'} ] ); +changeSystem($openslxDB, [ 1,2,3 ], [ { 'attr_hw_monitor' => '1280x1024'} ] ); +changeSystem($openslxDB, [ 4 ], [ { 'attr_hw_monitor' => '800x600'} ] ); + + +changeSystem($openslxDB, 4, { 'id' => 114, 'name' => 'id should still be 4'} ); + +my $metaDB = $openslxDB->{'meta-db'}; +my $colDescrs = [ + 'id:pk', + 'name:s.30', + 'comment:s.1024', + 'counter:i', + 'hidden:b', + 'dropped1:b', + 'dropped2:b', +]; +my $initialVals = [ + { + 'name' => '123456789012345678901234567890xxx', + 'comment' => 'comment-value-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + 'counter' => 34567, + 'hidden' => 1, + 'dropped1' => 0, + 'dropped2' => 1, + }, + { + 'name' => 'name', + 'comment' => q[from_äöüß#'"$...\to_here], + 'counter' => -1, + 'hidden' => 0, + 'dropped1' => 1, + 'dropped2' => 0, + }, +]; + + +$metaDB->schemaAddTable('test', $colDescrs, $initialVals); + +$metaDB->schemaRenameTable('test', 'test2', $colDescrs); + +push @$colDescrs, 'added:s.20'; +push @$colDescrs, 'added2:s.20'; +$metaDB->schemaAddColumns('test2', + ['added:s.20', 'added2:b'], + [{'added' => 'added'}, {'added2' => '1'}], + $colDescrs); + +my @rows = $metaDB->_doSelect("SELECT * FROM test2"); +foreach my $row (@rows) { + foreach my $r (keys %$row) { + print "$r = $row->{$r}\n"; + } +} + +$colDescrs = [grep {$_ !~ m[dropped]} @$colDescrs]; +$metaDB->schemaDropColumns('test2', ['dropped1', 'dropped2'], $colDescrs); + + +$colDescrs = [ + map { + if ($_ =~ m[counter]) { + "count:i"; + } elsif ($_ =~ m[comment]) { + "description:s.30"; + } else { + $_ + } + } @$colDescrs +]; +$metaDB->schemaChangeColumns('test2', + { 'counter' => 'count:i', + 'comment' => 'description:s.30' }, + $colDescrs); + +my @rows = $metaDB->_doSelect("SELECT * FROM test2"); +foreach my $row (@rows) { + foreach my $r (keys %$row) { + print "$r = $row->{$r}\n"; + } +} + +$metaDB->schemaDropTable('test2'); + +my $clientG01ID = addClient($openslxDB, { + 'name' => "PC-G-01", + 'mac' => "00:50:56:0D:03:35", + 'boot_type' => 'pxe', +}); + +my $clientG02ID = addClient($openslxDB, { + 'name' => "PC-G-02", + 'mac' => "00:50:56:0D:03:36", + 'boot_type' => 'pxe', + 'unbootable' => 1, +}); + +my $clientG03ID = addClient($openslxDB, { + 'name' => "PC-G-03", + 'mac' => "00:50:56:0D:03:37", + 'boot_type' => 'pxe', +}); + +my $clientG04ID = addClient($openslxDB, { + 'name' => "PC-G-04", + 'mac' => "00:50:56:0D:03:38", + 'boot_type' => 'pxe', + 'kernel_params' => 'console=ttyS0,19200', +}); + +my $clientF01ID = addClient($openslxDB, { + 'name' => "PC-F-01", + 'mac' => "00:50:56:0D:03:31", + 'boot_type' => 'other', +}); + +my $clientF02ID = addClient($openslxDB, { + 'name' => "PC-F-02", + 'mac' => "00:50:56:0D:03:32", + 'boot_type' => 'pxe', +}); + +my $clientF03ID = addClient($openslxDB, { + 'name' => "PC-F-03", + 'mac' => "00:50:56:0D:03:33", + 'boot_type' => 'pxe', +}); + +addClientIDsToSystem($openslxDB, 6, [$clientG01ID, $clientG02ID, $clientG03ID, $clientG04ID, $clientF01ID, $clientF02ID, $clientF03ID]); + +my $group1ID = addGroup($openslxDB, { + 'name' => "Gell-PCs", + 'comment' => "Gell-Threemansion PCs from 2002", + 'attr_hw_mouse' => 'serial', +}); +addClientIDsToGroup($openslxDB, $group1ID, [$clientG01ID, $clientF02ID, $clientG03ID]); + +my $group2ID = addGroup($openslxDB, { + 'name' => "Teacher-PCs", + 'comment' => "all PCs sitting on teacher's desks", + 'attr_hw_monitor' => '1600x1200', +}); +addClientIDsToGroup($openslxDB, $group2ID, [$clientG01ID, $clientF01ID]); +addSystemIDsToGroup($openslxDB, $group2ID, [2, 3]); + +my $group3ID = addGroup($openslxDB, { + 'name' => "PCs in room G", + 'comment' => "all PCs of room 234", +}); +addClientIDsToGroup($openslxDB, $group3ID, [$clientG01ID, $clientG02ID, $clientG03ID, $clientG04ID]); + +disconnectConfigDB($openslxDB); diff --git a/config-db/slxconfig-demuxer b/config-db/slxconfig-demuxer new file mode 100755 index 00000000..62780f17 --- /dev/null +++ b/config-db/slxconfig-demuxer @@ -0,0 +1,651 @@ +#! /usr/bin/perl +# +# slxconfig-demuxer.pl - OpenSLX configuration demultiplexer +# +# (c) 2006 - OpenSLX.com +# +# Oliver Tappe +# +use strict; + +my $abstract = q[ +slxconfig-demuxer.pl + This script will read information about all systems, clients and + groups from the OpenSLX configuration database, mix & match the individual + configurational attributes and then demultiplex the resulting information + to a set of configuration files. These files are used by any OpenSLX-client + during boot to find out which systems to offer for booting. + + The resulting files will be put into the OpenSLX-tftpboot-path (you can use + the option --tftpboot-path to override the default taken from the OpenSLX + default settings). + + Please use the --man option in order to read the full manual. +]; + +use Fcntl qw(:DEFAULT :flock); +use File::Basename; +use Getopt::Long qw(:config pass_through); +use Pod::Usage; + +# add the lib-folder and the folder this script lives in to perl's search +# path for modules: +use FindBin; +use lib "$FindBin::RealBin/../lib"; + # production path +use lib "$FindBin::RealBin"; + # development path + +use OpenSLX::Basics; +use OpenSLX::ConfigDB qw(:access :aggregation :support); + +my $pxeConfigDefaultTemplate = q[# generated by openslx +NOESCAPE 0 +PROMPT 0 +TIMEOUT 10 +DEFAULT menu.c32 +IMPLICIT 1 +ALLOWOPTIONS 1 +MENU TITLE What would you like to do? (use cursor to select) +MENU MASTER PASSWD secret +]; + +my ( + $dryRun, + # dryRun won't touch any file + $systemConfCount, + # number of system configurations written + $clientSystemConfCount, + # number of (system-specific) client configurations written + $helpReq, + $manReq, + $versionReq, +); + +GetOptions( + 'dry-run' => \$dryRun, + # dry-run doesn't write anything, just prints statistic about what + # would have been written + 'help|?' => \$helpReq, + 'man' => \$manReq, + 'version' => \$versionReq, +) or pod2usage(2); +pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq; +pod2usage(-verbose => 2) if $manReq; +if ($versionReq) { + system('slxversion'); + exit 1; +} + +openslxInit(); + +my $openslxDB = connectConfigDB(); + +my $clientConfigPath = "$openslxConfig{'private-path'}/config"; +if (!-d $clientConfigPath) { + die _tr("Unable to access client-config-path '%s'!", $clientConfigPath); +} +my $tempPath = "$openslxConfig{'temp-path'}/slxconfig-demuxer"; +if (!$dryRun) { + mkdir $tempPath; + if (!-d $tempPath) { + die _tr("Unable to create or access temp-path '%s'!", $tempPath); + } +} +my $tftpbootPath = $openslxConfig{'tftpboot-path'}; +if (!$dryRun) { + system("rm -rf $tftpbootPath/client-config/* $tftpbootPath/pxe/*"); + system("mkdir -p $tftpbootPath/client-config $tftpbootPath/pxe/pxelinux.cfg"); + if (!-d $tftpbootPath) { + die _tr("Unable to create or access tftpboot-path '%s'!", $tftpbootPath); + } +} + +my $lockFile = "$tftpbootPath/config-demuxer.lock"; +lockScript($lockFile); + +writeConfigurations(); + +my $wr = ($dryRun ? "would have written" : "wrote"); +print "$wr $systemConfCount systems and $clientSystemConfCount client-configurations to $tftpbootPath/client-config\n"; + +disconnectConfigDB($openslxDB); + +system("rm -rf $tempPath") unless $dryRun || length($tempPath) < 12; + +unlockScript($lockFile); + +exit; + +################################################################################ +### +################################################################################ +sub lockScript +{ + my $lockFile = shift; + + return if $dryRun; + + # use a lock-file to singularize execution of this script: + if (-e $lockFile) { + my $ctime = (stat($lockFile))[10]; + my $now = time(); + if ($now - $ctime > 15*60) { + # existing lock file is older than 15 minutes, wipe it: + unlink $lockFile; + } + } + if (!sysopen(LOCKFILE, $lockFile, O_RDWR|O_CREAT|O_EXCL)) { + if ($! == 13) { + die _tr(qq[Unable to create lock-file <%s>, exiting!\n], $lockFile); + } else { + die _tr(qq[Lock-file <%s> exists, script is already running. +Please remove the logfile and try again if you are sure that no one else +is executing this script.\n], $lockFile); + } + } +} + +sub unlockScript +{ + my $lockFile = shift; + + return if $dryRun; + + unlink $lockFile; +} + +sub writeAttributesToFile +{ + my $attrHash = shift; + my $fileName = shift; + + return if $dryRun; + + open(ATTRS, "> $fileName") or die "unable to write to $fileName"; + my @attrs = sort grep { isAttribute($_) } keys %$attrHash; + foreach my $attr (@attrs) { + if (length($attrHash->{$attr}) > 0) { + my $externalAttrName = externalAttrName($attr); + print ATTRS "$externalAttrName=$attrHash->{$attr}\n"; + } + } + close(ATTRS); +} + +sub copyExternalSystemConfig +{ # copies local configuration extensions of given system from private + # config folder (var/lib/openslx/config/...) into a temporary folder + my $systemName = shift; + my $targetPath = shift; + + return if $dryRun; + + if ($targetPath !~ m[$tempPath]) { + die _tr("system-error: illegal target-path <%s>!", $targetPath); + } + system("rm -rf $targetPath"); + mkdir $targetPath; + + # first copy default files... + my $defaultConfigPath = "$clientConfigPath/default"; + if (-d $defaultConfigPath) { + system("cp -r $defaultConfigPath/* $targetPath"); + } + # now pour system-specific configuration on top (if any): + my $systemConfigPath = "$clientConfigPath/$systemName"; + if (-d $systemConfigPath) { + system("cp -r $systemConfigPath/* $targetPath"); + } +} + +sub createTarOfPath +{ + my $buildPath = shift; + my $tarName = shift; + my $destinationPath = shift; + + my $tarFile = "$destinationPath/$tarName"; + vlog 1, _tr('creating tar %s', $tarFile); + return if $dryRun; + + mkdir $destinationPath; + my $tarCmd = "cd $buildPath && tar czf $tarFile *"; + if (system("$tarCmd") != 0) { + die _tr("unable to execute shell-command:\n\t%s \n\t(%s)", $tarCmd, $!); + } +} + +################################################################################ +### +################################################################################ +sub writePXEMenus +{ + my $pxePath = "$tftpbootPath/pxe"; + my $pxeConfigPath = "$tftpbootPath/pxe/pxelinux.cfg"; + + if (!-e "$pxePath/pxelinux.0") { + my $pxelinux0Path + = "$openslxConfig{'share-path'}/tftpboot/pxelinux.0"; + system(qq[cp -a "$pxelinux0Path" $pxePath/]); + } + if (!-e "$pxePath/menu.c32") { + my $menuc32Path + = "$openslxConfig{'share-path'}/tftpboot/menu.c32"; + system(qq[cp -a "$menuc32Path" $pxePath/]); + } + + my @clients = fetchClientsByFilter($openslxDB); + foreach my $client (@clients) { + my $externalClientID = externalIDForClient($client); + my $pxeFile = "$pxeConfigPath/$externalClientID"; + my $clientAppend = $client->{kernel_params}; + vlog 1, _tr("writing PXE-file %s", $pxeFile); + open(PXE, "> $pxeFile") or die "unable to write to $pxeFile"; + print PXE $pxeConfigDefaultTemplate; + my @systemIDs = aggregatedSystemIDsOfClient($openslxDB, $client); + my @systems = fetchSystemsByID($openslxDB, \@systemIDs); + foreach my $system (@systems) { + my @infos = aggregatedSystemFileInfosOfSystem($openslxDB, $system); + foreach my $info (@infos) { + my $extSysID = externalIDForSystem($info); + my $append = $system->{kernel_params}; + $append .= " initrd=$extSysID/initramfs"; + $append .= " $clientAppend"; + $append .= " rootfs=$info->{'export-uri'} file"; + print PXE "LABEL openslx-$extSysID\n"; +# print PXE "\tMENU DEFAULT\n"; + print PXE "\tMENU LABEL ^$info->{label}\n"; + print PXE "\tKERNEL $extSysID/kernel\n"; + print PXE "\tAPPEND $append\n"; + print PXE "\tIPAPPEND 1\n"; + } + } + close(PXE); + } +} + +sub generateInitalRamFS +{ + my $setup = shift; + my $vendorOS = shift; + my $pxeSysPath = shift; + + vlog 1, _tr('generating initialramfs %s/initramfs', $pxeSysPath); + my $cmd = "$openslxConfig{'bin-path'}/slxmkramfs "; + if ($setup->{ramfs_use_glibc}) { + $cmd .= '-g '; + } + if ($setup->{ramfs_use_busybox}) { + $cmd .= '-b '; + } + my $debugLevel = $setup->{ramfs_debug_level}; + if ($debugLevel) { + $cmd .= qq[-d $debugLevel ]; + } + if (length($setup->{ramfs_nicmods}) > 0) { + $cmd .= qq[-n "$setup->{ramfs_nicmods}" ]; + } + if (length($setup->{ramfs_fsmods}) > 0) { + $cmd .= qq[-f "$setup->{ramfs_fsmods}" ]; + } + my $rootPath + = "$openslxConfig{'private-path'}/stage1/$vendorOS->{path}"; + $cmd .= "-i $pxeSysPath/initramfs -r $rootPath"; + + $ENV{'SLX_PRIVATE_PATH'} = $openslxConfig{'private-path'}; + $ENV{'SLX_PUBLIC_PATH'} = $openslxConfig{'public-path'}; + $ENV{'SLX_SHARE_PATH'} = $openslxConfig{'share-path'}; + vlog 2, _tr('executing %s', $cmd); + system($cmd) unless $dryRun; +} + +sub writeSystemPXEFiles +{ + my $system = shift; + + my $pxePath = "$tftpbootPath/pxe"; + + my $vendorOS = fetchVendorOSesByID($openslxDB, $system->{vendor_os_id}); + my @infos = aggregatedSystemFileInfosOfSystem($openslxDB, $system); + foreach my $info (@infos) { + my $kernelFile = $info->{'kernel-file'}; + my $extSysID = externalIDForSystem($info); + my $pxeSysPath = "$pxePath/$extSysID"; + if (-e $pxeSysPath) { + die _tr('PXE-system %s already exists!', $pxeSysPath); + } + mkdir $pxeSysPath; + vlog 1, _tr('copying kernel %s to %s/kernel', $kernelFile, $pxeSysPath); + system(qq[cp -a "$kernelFile" $pxeSysPath/kernel]) unless $dryRun; + + generateInitalRamFS($info, $vendorOS, $pxeSysPath); + } +} + +sub writeClientConfigurationsForSystem +{ + my $system = shift; + my $buildPath = shift; + my $attrFile = shift; + + my @clientIDs = aggregatedClientIDsOfSystem($openslxDB, $system); + my @clients = fetchClientsByID($openslxDB, \@clientIDs); + foreach my $client (@clients) { + vlog 2, _tr("exporting client %d:%s", $client->{id}, $client->{name}); + $clientSystemConfCount++; + + # merge configurations of client, it's groups, default client and + # system and write the resulting attributes to a configuration file: + mergeDefaultAndGroupAttributesIntoClient($openslxDB, $client); + mergeAttributes($client, $system); + writeAttributesToFile($client, $attrFile); + + # create tar containing external system configuration + # and client attribute file: + my $externalClientID = externalIDForClient($client); + my $externalSystemID = externalIDForSystem($system); + createTarOfPath($buildPath, "${externalClientID}.tgz", + "$tftpbootPath/client-config/$externalSystemID"); + } +} + +sub writeSystemConfigurations +{ + my @systems = fetchSystemsByFilter($openslxDB); + foreach my $system (@systems) { + next unless $system->{id} > 0; + + vlog 2, _tr('exporting system %d:%s', $system->{id}, $system->{name}); + $systemConfCount++; + + my $buildPath = "$tempPath/build"; + copyExternalSystemConfig($system->{name}, $buildPath); + + my $attrFile = "$buildPath/initramfs/machine-setup"; + mergeDefaultAttributesIntoSystem($openslxDB, $system); + writeAttributesToFile($system, $attrFile); + + my $externalSystemID = externalIDForSystem($system); + my $systemPath = "$tftpbootPath/client-config/$externalSystemID"; + createTarOfPath($buildPath, "default.tgz", $systemPath); + + writeSystemPXEFiles($system); + + writeClientConfigurationsForSystem($system, $buildPath, $attrFile); + + system("rm -rf $buildPath") unless $dryRun; + } +} + +sub writeConfigurations +{ + $systemConfCount = $clientSystemConfCount = 0; + writeSystemConfigurations(); + writePXEMenus(); +} + +__END__ + +=head1 NAME + +slxconfig-demuxer.pl - OpenSLX configuration demultiplexer + +=head1 SYNOPSIS + +slxconfig-demuxer.pl [options] + + Script Options: + --dry-run avoids writing anything, for testing + + OpenSLX Options: + --base-path= basic path to project files + --bin-path= path to binaries and scripts + --config-path= path to configuration files + --db-basepath= basic path to openslx database + --db-datadir= data folder created under db-basepath + --db-name= name of database + --db-spec= full DBI-specification of database + --db-type= type of database to connect to + --export-path= path to root of all exported filesystems + --locale= locale to use for translations + --logfile= file to write logging output to + --private-path= path to private data + --public-path= path to public (client-accesible) data + --share-path= path to sharable data + --temp-path= path to temporary data + --tftpboot-path= path to root of tftp-server + --verbose-level= level of logging verbosity (0-3) + + General Options: + --help brief help message + --man full documentation + --version show version + +=head1 OPTIONS + +=head3 Script Options + +=over 8 + +=item B<--dry-run> + +Runs the script but avoids writing anything. This is useful for testing, as +you can learn from the logging output what would have been done. + +=back + +=head3 OpenSLX Options + +=over 8 + +=item B<--base-path=> + +Sets basic path to project files. + +Default is $SLX_BASE_PATH (usually F). + +=item B<--bin-path=> + +Sets path to binaries and scripts. + +Default is $SLX_BASE_PATH/bin (usually F). + +=item B<--config-path=> + +Sets path to configuration files. + +Default is $SLX_CONFIG_PATH (usually F). + +=item B<--db-basepath=> + +Sets basic path to openslx database. + +Default is $SLX_DB_PATH (usually F). + +=item B<--db-datadir=> + +Sets data folder created under db-basepath. + +Default is $SLX_DB_DATADIR (usually empty as it depends on db-type +whether or not such a directory is required at all). + +=item B<--db-name=> + +Gives the name of the database to connect to. + +Default is $SLX_DB_NAME (usually C). + +=item B<--db-spec=> + +Gives the full DBI-specification of database to connect to. Content depends +on the db-type. + +Default is $SLX_DB_SPEC (usually empty as it will be built automatically). + +=item B<--db-type=> + +Sets the type of database to connect to (CSV, SQLite, mysql, ...). + +Default $SLX_DB_TYPE (usually C). + +=item B<--export-path=> + +Sets path to root of all exported filesystems. For each type of export (NFS, +NBD, ...) a separate folder will be created in here. + +Default is $SLX_EXPORT_PATH (usually F. + +=item B<--locale=> + +Sets the locale to use for translations. + +Defaults to the system's standard locale. + +=item B<--logfile=> + +Specifies a file where logging output will be written to. + +Default is to log to STDERR. + +=item B<--private-path=> + +Sets path to private data, where the config-db, vendor_oses and configurational +extensions will be stored. + +Default is $SLX_PRIVATE_PATH (usually F. + +=item B<--public-path=> + +Sets path to public (client-accesible) data. + +Default is $SLX_PUBLIC_PATH (usually F. + +=item B<--share-path=> + +Sets path to sharable data, where distro-specs and functionality templates +will be stored. + +Default is $SLX_SHARE_PATH (usually F. + +=item B<--temp-path=> + +Sets path to temporary data. + +Default is $SLX_TEMP_PATH (usually F. + +=item B<--tftpboot-path=> + +Sets path to root of tftp-server from which clients will access their files. + +Default is $SLX_TFTPBOOT_PATH (usually F. + +=item B<--verbose-level=> + +Sets the level of logging verbosity (0-3). + +Default is $SLX_VERBOSE_LEVEL (usually 0, no logging). + +=back + +=head3 General Options + +=over 8 + +=item B<--help> + +Prints a brief help message and exits. + +=item B<--man> + +Prints the manual page and exits. + +=item B<--version> + +Prints the version and exits. + +=back + +=head1 DESCRIPTION + +B will read information about all systems, clients and +groups from the OpenSLX configuration database, mix & match the individual +configurational attributes and then demultiplex the resulting information +to a set of configuration files. These files are used by any OpenSLX-client +during boot to find out which systems to offer for booting. + +The resulting files will be put into the OpenSLX-tftpboot-path (you can use the +option B<--tftpboot-path> to override the default taken from the OpenSLX +default settings). + +=head2 FILE CREATION + +The following set of files will be created: + +=over 8 + +=item B + +The basic PXE files (F, F) will be copied into +F<$SLX_TFTPBOOT_PATH/pxe> to make them available to any PXE-client via tftp. + +=item B + +For each client, a PXE configuration file will be generated and written to +F<$SLX_TFTPBOOT_PATH/pxe/pxelinux.cfg/01->. This file will +contain information about the systems this client shall offer for booting. +For each of these systems, the kernel cmdline options required for that +particular system setup is specified (via PXE's APPEND option). + +=item B + +For each bootable system, that system's kernel will be copied to +F<$SLX_TFTPBOOT_PATH/pxe//kernel and an OpenSLX-specific initramfs +required for booting that particular system is generated (by means of +slxmkramfs) and put into F<$SLX_TFTPBOOT_PATH/pxe//initramfs. + +These two files (kernel & initramfs) will be referenced by the PXE client +configuration of all clients that offer this specific system for booting. + +=item B + +For each combination of system and client, an OpenSLX configuration archive +will be generated and written to +F<$SLX_TFTPBOOT_PATH/client-config//01-.tgz>. +This archive will contain the file F, specifying all +the attributes of that particular client (e.g. whether or not it should start +the X-server). + +Furthermore, the archive may contain additional system files that are +required for the client (e.g. a special PAM-module required for LDAP +authentication). These files are copied from F<$SLX_PRIVATE_PATH/config/default> +and F<$SLX_PROVATE_PATH/config/>. + +=back + +=head2 MIXING & MATCHING (THE DEMUXER) + +In the OpenSLX configuration database, each system, group and client may have +several configurational attributes set to a specific value that will cause +a client booting that system to behave in a certain way. The mixing of all +these different attributes into one set that is relevant for a specific client +booting one specific system is one important task of the slxconfig-demuxer. + +As an example, let's assume one system setup that is configured to boot directly +into a special application that demands a rather low screen-resolution of +1024x768 pixels, as otherwise the text would be unreadable due to very small +fonts being used by that app. In order to achieve this, the administrator can +set the I-attribute of the B to '1024x768'. +Let's say one of the clients, however, is connected to a very old monitor that +has problems with this resolution and only supports 800x600 pixels. In that +case, the administrator can set the I-attribute of that B to +'800x600'. The mixing & matching process would make sure that this specific +client would run that system with a resolution of 800x600, while all other +clients would run that system in 1024x768. + +So the slxconfig-demuxer demultiplexes the individual configurational attributes +into a concrete set of configuration settings for specific clients and their +offered systems, making sure that each client/system combination uses the +appropriate settings. + +=cut diff --git a/config-db/slxconfig-demuxer.pl b/config-db/slxconfig-demuxer.pl deleted file mode 100755 index 62780f17..00000000 --- a/config-db/slxconfig-demuxer.pl +++ /dev/null @@ -1,651 +0,0 @@ -#! /usr/bin/perl -# -# slxconfig-demuxer.pl - OpenSLX configuration demultiplexer -# -# (c) 2006 - OpenSLX.com -# -# Oliver Tappe -# -use strict; - -my $abstract = q[ -slxconfig-demuxer.pl - This script will read information about all systems, clients and - groups from the OpenSLX configuration database, mix & match the individual - configurational attributes and then demultiplex the resulting information - to a set of configuration files. These files are used by any OpenSLX-client - during boot to find out which systems to offer for booting. - - The resulting files will be put into the OpenSLX-tftpboot-path (you can use - the option --tftpboot-path to override the default taken from the OpenSLX - default settings). - - Please use the --man option in order to read the full manual. -]; - -use Fcntl qw(:DEFAULT :flock); -use File::Basename; -use Getopt::Long qw(:config pass_through); -use Pod::Usage; - -# add the lib-folder and the folder this script lives in to perl's search -# path for modules: -use FindBin; -use lib "$FindBin::RealBin/../lib"; - # production path -use lib "$FindBin::RealBin"; - # development path - -use OpenSLX::Basics; -use OpenSLX::ConfigDB qw(:access :aggregation :support); - -my $pxeConfigDefaultTemplate = q[# generated by openslx -NOESCAPE 0 -PROMPT 0 -TIMEOUT 10 -DEFAULT menu.c32 -IMPLICIT 1 -ALLOWOPTIONS 1 -MENU TITLE What would you like to do? (use cursor to select) -MENU MASTER PASSWD secret -]; - -my ( - $dryRun, - # dryRun won't touch any file - $systemConfCount, - # number of system configurations written - $clientSystemConfCount, - # number of (system-specific) client configurations written - $helpReq, - $manReq, - $versionReq, -); - -GetOptions( - 'dry-run' => \$dryRun, - # dry-run doesn't write anything, just prints statistic about what - # would have been written - 'help|?' => \$helpReq, - 'man' => \$manReq, - 'version' => \$versionReq, -) or pod2usage(2); -pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq; -pod2usage(-verbose => 2) if $manReq; -if ($versionReq) { - system('slxversion'); - exit 1; -} - -openslxInit(); - -my $openslxDB = connectConfigDB(); - -my $clientConfigPath = "$openslxConfig{'private-path'}/config"; -if (!-d $clientConfigPath) { - die _tr("Unable to access client-config-path '%s'!", $clientConfigPath); -} -my $tempPath = "$openslxConfig{'temp-path'}/slxconfig-demuxer"; -if (!$dryRun) { - mkdir $tempPath; - if (!-d $tempPath) { - die _tr("Unable to create or access temp-path '%s'!", $tempPath); - } -} -my $tftpbootPath = $openslxConfig{'tftpboot-path'}; -if (!$dryRun) { - system("rm -rf $tftpbootPath/client-config/* $tftpbootPath/pxe/*"); - system("mkdir -p $tftpbootPath/client-config $tftpbootPath/pxe/pxelinux.cfg"); - if (!-d $tftpbootPath) { - die _tr("Unable to create or access tftpboot-path '%s'!", $tftpbootPath); - } -} - -my $lockFile = "$tftpbootPath/config-demuxer.lock"; -lockScript($lockFile); - -writeConfigurations(); - -my $wr = ($dryRun ? "would have written" : "wrote"); -print "$wr $systemConfCount systems and $clientSystemConfCount client-configurations to $tftpbootPath/client-config\n"; - -disconnectConfigDB($openslxDB); - -system("rm -rf $tempPath") unless $dryRun || length($tempPath) < 12; - -unlockScript($lockFile); - -exit; - -################################################################################ -### -################################################################################ -sub lockScript -{ - my $lockFile = shift; - - return if $dryRun; - - # use a lock-file to singularize execution of this script: - if (-e $lockFile) { - my $ctime = (stat($lockFile))[10]; - my $now = time(); - if ($now - $ctime > 15*60) { - # existing lock file is older than 15 minutes, wipe it: - unlink $lockFile; - } - } - if (!sysopen(LOCKFILE, $lockFile, O_RDWR|O_CREAT|O_EXCL)) { - if ($! == 13) { - die _tr(qq[Unable to create lock-file <%s>, exiting!\n], $lockFile); - } else { - die _tr(qq[Lock-file <%s> exists, script is already running. -Please remove the logfile and try again if you are sure that no one else -is executing this script.\n], $lockFile); - } - } -} - -sub unlockScript -{ - my $lockFile = shift; - - return if $dryRun; - - unlink $lockFile; -} - -sub writeAttributesToFile -{ - my $attrHash = shift; - my $fileName = shift; - - return if $dryRun; - - open(ATTRS, "> $fileName") or die "unable to write to $fileName"; - my @attrs = sort grep { isAttribute($_) } keys %$attrHash; - foreach my $attr (@attrs) { - if (length($attrHash->{$attr}) > 0) { - my $externalAttrName = externalAttrName($attr); - print ATTRS "$externalAttrName=$attrHash->{$attr}\n"; - } - } - close(ATTRS); -} - -sub copyExternalSystemConfig -{ # copies local configuration extensions of given system from private - # config folder (var/lib/openslx/config/...) into a temporary folder - my $systemName = shift; - my $targetPath = shift; - - return if $dryRun; - - if ($targetPath !~ m[$tempPath]) { - die _tr("system-error: illegal target-path <%s>!", $targetPath); - } - system("rm -rf $targetPath"); - mkdir $targetPath; - - # first copy default files... - my $defaultConfigPath = "$clientConfigPath/default"; - if (-d $defaultConfigPath) { - system("cp -r $defaultConfigPath/* $targetPath"); - } - # now pour system-specific configuration on top (if any): - my $systemConfigPath = "$clientConfigPath/$systemName"; - if (-d $systemConfigPath) { - system("cp -r $systemConfigPath/* $targetPath"); - } -} - -sub createTarOfPath -{ - my $buildPath = shift; - my $tarName = shift; - my $destinationPath = shift; - - my $tarFile = "$destinationPath/$tarName"; - vlog 1, _tr('creating tar %s', $tarFile); - return if $dryRun; - - mkdir $destinationPath; - my $tarCmd = "cd $buildPath && tar czf $tarFile *"; - if (system("$tarCmd") != 0) { - die _tr("unable to execute shell-command:\n\t%s \n\t(%s)", $tarCmd, $!); - } -} - -################################################################################ -### -################################################################################ -sub writePXEMenus -{ - my $pxePath = "$tftpbootPath/pxe"; - my $pxeConfigPath = "$tftpbootPath/pxe/pxelinux.cfg"; - - if (!-e "$pxePath/pxelinux.0") { - my $pxelinux0Path - = "$openslxConfig{'share-path'}/tftpboot/pxelinux.0"; - system(qq[cp -a "$pxelinux0Path" $pxePath/]); - } - if (!-e "$pxePath/menu.c32") { - my $menuc32Path - = "$openslxConfig{'share-path'}/tftpboot/menu.c32"; - system(qq[cp -a "$menuc32Path" $pxePath/]); - } - - my @clients = fetchClientsByFilter($openslxDB); - foreach my $client (@clients) { - my $externalClientID = externalIDForClient($client); - my $pxeFile = "$pxeConfigPath/$externalClientID"; - my $clientAppend = $client->{kernel_params}; - vlog 1, _tr("writing PXE-file %s", $pxeFile); - open(PXE, "> $pxeFile") or die "unable to write to $pxeFile"; - print PXE $pxeConfigDefaultTemplate; - my @systemIDs = aggregatedSystemIDsOfClient($openslxDB, $client); - my @systems = fetchSystemsByID($openslxDB, \@systemIDs); - foreach my $system (@systems) { - my @infos = aggregatedSystemFileInfosOfSystem($openslxDB, $system); - foreach my $info (@infos) { - my $extSysID = externalIDForSystem($info); - my $append = $system->{kernel_params}; - $append .= " initrd=$extSysID/initramfs"; - $append .= " $clientAppend"; - $append .= " rootfs=$info->{'export-uri'} file"; - print PXE "LABEL openslx-$extSysID\n"; -# print PXE "\tMENU DEFAULT\n"; - print PXE "\tMENU LABEL ^$info->{label}\n"; - print PXE "\tKERNEL $extSysID/kernel\n"; - print PXE "\tAPPEND $append\n"; - print PXE "\tIPAPPEND 1\n"; - } - } - close(PXE); - } -} - -sub generateInitalRamFS -{ - my $setup = shift; - my $vendorOS = shift; - my $pxeSysPath = shift; - - vlog 1, _tr('generating initialramfs %s/initramfs', $pxeSysPath); - my $cmd = "$openslxConfig{'bin-path'}/slxmkramfs "; - if ($setup->{ramfs_use_glibc}) { - $cmd .= '-g '; - } - if ($setup->{ramfs_use_busybox}) { - $cmd .= '-b '; - } - my $debugLevel = $setup->{ramfs_debug_level}; - if ($debugLevel) { - $cmd .= qq[-d $debugLevel ]; - } - if (length($setup->{ramfs_nicmods}) > 0) { - $cmd .= qq[-n "$setup->{ramfs_nicmods}" ]; - } - if (length($setup->{ramfs_fsmods}) > 0) { - $cmd .= qq[-f "$setup->{ramfs_fsmods}" ]; - } - my $rootPath - = "$openslxConfig{'private-path'}/stage1/$vendorOS->{path}"; - $cmd .= "-i $pxeSysPath/initramfs -r $rootPath"; - - $ENV{'SLX_PRIVATE_PATH'} = $openslxConfig{'private-path'}; - $ENV{'SLX_PUBLIC_PATH'} = $openslxConfig{'public-path'}; - $ENV{'SLX_SHARE_PATH'} = $openslxConfig{'share-path'}; - vlog 2, _tr('executing %s', $cmd); - system($cmd) unless $dryRun; -} - -sub writeSystemPXEFiles -{ - my $system = shift; - - my $pxePath = "$tftpbootPath/pxe"; - - my $vendorOS = fetchVendorOSesByID($openslxDB, $system->{vendor_os_id}); - my @infos = aggregatedSystemFileInfosOfSystem($openslxDB, $system); - foreach my $info (@infos) { - my $kernelFile = $info->{'kernel-file'}; - my $extSysID = externalIDForSystem($info); - my $pxeSysPath = "$pxePath/$extSysID"; - if (-e $pxeSysPath) { - die _tr('PXE-system %s already exists!', $pxeSysPath); - } - mkdir $pxeSysPath; - vlog 1, _tr('copying kernel %s to %s/kernel', $kernelFile, $pxeSysPath); - system(qq[cp -a "$kernelFile" $pxeSysPath/kernel]) unless $dryRun; - - generateInitalRamFS($info, $vendorOS, $pxeSysPath); - } -} - -sub writeClientConfigurationsForSystem -{ - my $system = shift; - my $buildPath = shift; - my $attrFile = shift; - - my @clientIDs = aggregatedClientIDsOfSystem($openslxDB, $system); - my @clients = fetchClientsByID($openslxDB, \@clientIDs); - foreach my $client (@clients) { - vlog 2, _tr("exporting client %d:%s", $client->{id}, $client->{name}); - $clientSystemConfCount++; - - # merge configurations of client, it's groups, default client and - # system and write the resulting attributes to a configuration file: - mergeDefaultAndGroupAttributesIntoClient($openslxDB, $client); - mergeAttributes($client, $system); - writeAttributesToFile($client, $attrFile); - - # create tar containing external system configuration - # and client attribute file: - my $externalClientID = externalIDForClient($client); - my $externalSystemID = externalIDForSystem($system); - createTarOfPath($buildPath, "${externalClientID}.tgz", - "$tftpbootPath/client-config/$externalSystemID"); - } -} - -sub writeSystemConfigurations -{ - my @systems = fetchSystemsByFilter($openslxDB); - foreach my $system (@systems) { - next unless $system->{id} > 0; - - vlog 2, _tr('exporting system %d:%s', $system->{id}, $system->{name}); - $systemConfCount++; - - my $buildPath = "$tempPath/build"; - copyExternalSystemConfig($system->{name}, $buildPath); - - my $attrFile = "$buildPath/initramfs/machine-setup"; - mergeDefaultAttributesIntoSystem($openslxDB, $system); - writeAttributesToFile($system, $attrFile); - - my $externalSystemID = externalIDForSystem($system); - my $systemPath = "$tftpbootPath/client-config/$externalSystemID"; - createTarOfPath($buildPath, "default.tgz", $systemPath); - - writeSystemPXEFiles($system); - - writeClientConfigurationsForSystem($system, $buildPath, $attrFile); - - system("rm -rf $buildPath") unless $dryRun; - } -} - -sub writeConfigurations -{ - $systemConfCount = $clientSystemConfCount = 0; - writeSystemConfigurations(); - writePXEMenus(); -} - -__END__ - -=head1 NAME - -slxconfig-demuxer.pl - OpenSLX configuration demultiplexer - -=head1 SYNOPSIS - -slxconfig-demuxer.pl [options] - - Script Options: - --dry-run avoids writing anything, for testing - - OpenSLX Options: - --base-path= basic path to project files - --bin-path= path to binaries and scripts - --config-path= path to configuration files - --db-basepath= basic path to openslx database - --db-datadir= data folder created under db-basepath - --db-name= name of database - --db-spec= full DBI-specification of database - --db-type= type of database to connect to - --export-path= path to root of all exported filesystems - --locale= locale to use for translations - --logfile= file to write logging output to - --private-path= path to private data - --public-path= path to public (client-accesible) data - --share-path= path to sharable data - --temp-path= path to temporary data - --tftpboot-path= path to root of tftp-server - --verbose-level= level of logging verbosity (0-3) - - General Options: - --help brief help message - --man full documentation - --version show version - -=head1 OPTIONS - -=head3 Script Options - -=over 8 - -=item B<--dry-run> - -Runs the script but avoids writing anything. This is useful for testing, as -you can learn from the logging output what would have been done. - -=back - -=head3 OpenSLX Options - -=over 8 - -=item B<--base-path=> - -Sets basic path to project files. - -Default is $SLX_BASE_PATH (usually F). - -=item B<--bin-path=> - -Sets path to binaries and scripts. - -Default is $SLX_BASE_PATH/bin (usually F). - -=item B<--config-path=> - -Sets path to configuration files. - -Default is $SLX_CONFIG_PATH (usually F). - -=item B<--db-basepath=> - -Sets basic path to openslx database. - -Default is $SLX_DB_PATH (usually F). - -=item B<--db-datadir=> - -Sets data folder created under db-basepath. - -Default is $SLX_DB_DATADIR (usually empty as it depends on db-type -whether or not such a directory is required at all). - -=item B<--db-name=> - -Gives the name of the database to connect to. - -Default is $SLX_DB_NAME (usually C). - -=item B<--db-spec=> - -Gives the full DBI-specification of database to connect to. Content depends -on the db-type. - -Default is $SLX_DB_SPEC (usually empty as it will be built automatically). - -=item B<--db-type=> - -Sets the type of database to connect to (CSV, SQLite, mysql, ...). - -Default $SLX_DB_TYPE (usually C). - -=item B<--export-path=> - -Sets path to root of all exported filesystems. For each type of export (NFS, -NBD, ...) a separate folder will be created in here. - -Default is $SLX_EXPORT_PATH (usually F. - -=item B<--locale=> - -Sets the locale to use for translations. - -Defaults to the system's standard locale. - -=item B<--logfile=> - -Specifies a file where logging output will be written to. - -Default is to log to STDERR. - -=item B<--private-path=> - -Sets path to private data, where the config-db, vendor_oses and configurational -extensions will be stored. - -Default is $SLX_PRIVATE_PATH (usually F. - -=item B<--public-path=> - -Sets path to public (client-accesible) data. - -Default is $SLX_PUBLIC_PATH (usually F. - -=item B<--share-path=> - -Sets path to sharable data, where distro-specs and functionality templates -will be stored. - -Default is $SLX_SHARE_PATH (usually F. - -=item B<--temp-path=> - -Sets path to temporary data. - -Default is $SLX_TEMP_PATH (usually F. - -=item B<--tftpboot-path=> - -Sets path to root of tftp-server from which clients will access their files. - -Default is $SLX_TFTPBOOT_PATH (usually F. - -=item B<--verbose-level=> - -Sets the level of logging verbosity (0-3). - -Default is $SLX_VERBOSE_LEVEL (usually 0, no logging). - -=back - -=head3 General Options - -=over 8 - -=item B<--help> - -Prints a brief help message and exits. - -=item B<--man> - -Prints the manual page and exits. - -=item B<--version> - -Prints the version and exits. - -=back - -=head1 DESCRIPTION - -B will read information about all systems, clients and -groups from the OpenSLX configuration database, mix & match the individual -configurational attributes and then demultiplex the resulting information -to a set of configuration files. These files are used by any OpenSLX-client -during boot to find out which systems to offer for booting. - -The resulting files will be put into the OpenSLX-tftpboot-path (you can use the -option B<--tftpboot-path> to override the default taken from the OpenSLX -default settings). - -=head2 FILE CREATION - -The following set of files will be created: - -=over 8 - -=item B - -The basic PXE files (F, F) will be copied into -F<$SLX_TFTPBOOT_PATH/pxe> to make them available to any PXE-client via tftp. - -=item B - -For each client, a PXE configuration file will be generated and written to -F<$SLX_TFTPBOOT_PATH/pxe/pxelinux.cfg/01->. This file will -contain information about the systems this client shall offer for booting. -For each of these systems, the kernel cmdline options required for that -particular system setup is specified (via PXE's APPEND option). - -=item B - -For each bootable system, that system's kernel will be copied to -F<$SLX_TFTPBOOT_PATH/pxe//kernel and an OpenSLX-specific initramfs -required for booting that particular system is generated (by means of -slxmkramfs) and put into F<$SLX_TFTPBOOT_PATH/pxe//initramfs. - -These two files (kernel & initramfs) will be referenced by the PXE client -configuration of all clients that offer this specific system for booting. - -=item B - -For each combination of system and client, an OpenSLX configuration archive -will be generated and written to -F<$SLX_TFTPBOOT_PATH/client-config//01-.tgz>. -This archive will contain the file F, specifying all -the attributes of that particular client (e.g. whether or not it should start -the X-server). - -Furthermore, the archive may contain additional system files that are -required for the client (e.g. a special PAM-module required for LDAP -authentication). These files are copied from F<$SLX_PRIVATE_PATH/config/default> -and F<$SLX_PROVATE_PATH/config/>. - -=back - -=head2 MIXING & MATCHING (THE DEMUXER) - -In the OpenSLX configuration database, each system, group and client may have -several configurational attributes set to a specific value that will cause -a client booting that system to behave in a certain way. The mixing of all -these different attributes into one set that is relevant for a specific client -booting one specific system is one important task of the slxconfig-demuxer. - -As an example, let's assume one system setup that is configured to boot directly -into a special application that demands a rather low screen-resolution of -1024x768 pixels, as otherwise the text would be unreadable due to very small -fonts being used by that app. In order to achieve this, the administrator can -set the I-attribute of the B to '1024x768'. -Let's say one of the clients, however, is connected to a very old monitor that -has problems with this resolution and only supports 800x600 pixels. In that -case, the administrator can set the I-attribute of that B to -'800x600'. The mixing & matching process would make sure that this specific -client would run that system with a resolution of 800x600, while all other -clients would run that system in 1024x768. - -So the slxconfig-demuxer demultiplexes the individual configurational attributes -into a concrete set of configuration settings for specific clients and their -offered systems, making sure that each client/system combination uses the -appropriate settings. - -=cut diff --git a/config-db/slxldd b/config-db/slxldd new file mode 100755 index 00000000..ee887e01 --- /dev/null +++ b/config-db/slxldd @@ -0,0 +1,199 @@ +#! /usr/bin/perl +# +# slxldd.pl - OpenSLX-rewrite of ldd that works on multiple architectures. +# +# (c) 2006 - OpenSLX.com +# +# Oliver Tappe +# +use strict; + +my $abstract = q[ +slxldd.pl + This script reimplements ldd in a way that should work for all + binary formats supported by the binutils installed on the host system. + + An example: if you have a folder containing an ia64 system, you can + invoke this script on a ia32-host in order to determine all the libraries + required by a binary of the ia64 target system. +]; + +use File::Glob ':globally'; +use Getopt::Long; +use Pod::Usage; + +use OpenSLX::Basics; + +my ( + $helpReq, + $rootPath, + $versionReq, + + @libFolders, + @libs, + %libInfo, +); + +GetOptions( + 'help|?' => \$helpReq, + 'root-path=s' => \$rootPath, + 'version' => \$versionReq, +) or pod2usage(2); +pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq; +if ($versionReq) { + system('slxversion'); + exit 1; +} + +openslxInit(); + +if (!$rootPath) { + print _tr("You need to specify the root-path!\n"); + pod2usage(2); +} + +$rootPath =~ s[/+$][]; + # remove trailing slashes + +if (!@ARGV) { + print _tr("You need to specify at least one file!\n"); + pod2usage(2); +} + +fetchLoaderConfig(); + +foreach my $file (@ARGV) { + if ($file =~ m[^/]) { + # force absolute path relative to $rootPath: + $file = "$rootPath$file"; + } else { + # relative paths are relative to $rootPath: + $file = "$rootPath/$file"; + } + + next if `file $file` =~ m[shell\s+script]; + # silently ignore shell scripts + + addLibsForBinary($file); +} + +sub fetchLoaderConfigFile +{ + my $ldConfFile = shift; + + open(LDCONF, "< $ldConfFile"); + while() { + chomp; + if (/^\s*include\s+(.+?)\s*$/i) { + foreach my $incFile (<$rootPath$1>) { + fetchLoaderConfigFile($incFile); + } + next; + } + if (/\S+/i) { + s[=.+][]; + # remove any lib-type specifications (e.g. '=libc5') + push @libFolders, "$rootPath$_"; + } + } + close LDCONF; +} + +sub fetchLoaderConfig +{ + if (!-e "$rootPath/etc/ld.so.conf") { + die _tr("$rootPath/etc/ld.so.conf not found, maybe wrong root-path?\n"); + } + fetchLoaderConfigFile("$rootPath/etc/ld.so.conf"); + + # add "trusted" folders /lib and /usr/lib if not already in place: + if (!grep { m[^$rootPath/lib$]} @libFolders) { + push @libFolders, "$rootPath/lib"; + } + if (!grep { m[^$rootPath/usr/lib$] } @libFolders) { + push @libFolders, "$rootPath/usr/lib"; + } +} + +sub addLib +{ + my $lib = shift; + + if (!exists $libInfo{$lib}) { + push @libs, $lib; + my $libPath; + foreach my $folder (@libFolders) { + if (-e "$folder/$lib") { + $libPath = "$folder/$lib"; + last; + } + } + if (!defined $libPath) { + die _tr("*** unable to find lib %s! ***\n", $lib); + } + print "$libPath\n"; + $libInfo{$lib} = $libPath; + addLibsForBinary($libPath); + } +} + +sub addLibsForBinary +{ + my $binary = shift; + + # we try objdump... + my $res = `objdump -p $binary 2>/dev/null`; + if (!$?) { + while($res =~ m[^\s*NEEDED\s*(.+?)\s*$]gm) { + addLib($1); + } + } else { + # ...objdump failed, so we try readelf instead: + $res = `readelf -d $binary 2>/dev/null`; + if ($?) { + die _tr("neither objdump nor readelf seems to be installed, giving up!\n"); + } + while($res =~ m{\(NEEDED\)[^\[]+\[(.+?)\]\s*$}gm) { + addLib($1); + } + } +} + + +__END__ + +=head1 NAME + +slxldd.pl - OpenSLX-script to determine the libraries required by any given +binary file. + +=head1 SYNOPSIS + +slxldd.pl [options] file [...more files] + + Options: + --help brief help message + --root-path= path to the root folder for library search + --version show version + +=head1 OPTIONS + +=over 8 + +=item B<--help> + +Prints a brief help message and exits. + +=item B<--root-path=> + +Sets the root folder that is used when searching for libraries. In order to +collect the loader-settings, etc/ld.so.conf is read relative to this path and +all libraries are sought relative to this path, too (a.k.a. a virtual chroot). + +=item B<--version> + +Prints the version and exits. + +=back + +=cut \ No newline at end of file diff --git a/config-db/slxldd.pl b/config-db/slxldd.pl deleted file mode 100755 index ee887e01..00000000 --- a/config-db/slxldd.pl +++ /dev/null @@ -1,199 +0,0 @@ -#! /usr/bin/perl -# -# slxldd.pl - OpenSLX-rewrite of ldd that works on multiple architectures. -# -# (c) 2006 - OpenSLX.com -# -# Oliver Tappe -# -use strict; - -my $abstract = q[ -slxldd.pl - This script reimplements ldd in a way that should work for all - binary formats supported by the binutils installed on the host system. - - An example: if you have a folder containing an ia64 system, you can - invoke this script on a ia32-host in order to determine all the libraries - required by a binary of the ia64 target system. -]; - -use File::Glob ':globally'; -use Getopt::Long; -use Pod::Usage; - -use OpenSLX::Basics; - -my ( - $helpReq, - $rootPath, - $versionReq, - - @libFolders, - @libs, - %libInfo, -); - -GetOptions( - 'help|?' => \$helpReq, - 'root-path=s' => \$rootPath, - 'version' => \$versionReq, -) or pod2usage(2); -pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq; -if ($versionReq) { - system('slxversion'); - exit 1; -} - -openslxInit(); - -if (!$rootPath) { - print _tr("You need to specify the root-path!\n"); - pod2usage(2); -} - -$rootPath =~ s[/+$][]; - # remove trailing slashes - -if (!@ARGV) { - print _tr("You need to specify at least one file!\n"); - pod2usage(2); -} - -fetchLoaderConfig(); - -foreach my $file (@ARGV) { - if ($file =~ m[^/]) { - # force absolute path relative to $rootPath: - $file = "$rootPath$file"; - } else { - # relative paths are relative to $rootPath: - $file = "$rootPath/$file"; - } - - next if `file $file` =~ m[shell\s+script]; - # silently ignore shell scripts - - addLibsForBinary($file); -} - -sub fetchLoaderConfigFile -{ - my $ldConfFile = shift; - - open(LDCONF, "< $ldConfFile"); - while() { - chomp; - if (/^\s*include\s+(.+?)\s*$/i) { - foreach my $incFile (<$rootPath$1>) { - fetchLoaderConfigFile($incFile); - } - next; - } - if (/\S+/i) { - s[=.+][]; - # remove any lib-type specifications (e.g. '=libc5') - push @libFolders, "$rootPath$_"; - } - } - close LDCONF; -} - -sub fetchLoaderConfig -{ - if (!-e "$rootPath/etc/ld.so.conf") { - die _tr("$rootPath/etc/ld.so.conf not found, maybe wrong root-path?\n"); - } - fetchLoaderConfigFile("$rootPath/etc/ld.so.conf"); - - # add "trusted" folders /lib and /usr/lib if not already in place: - if (!grep { m[^$rootPath/lib$]} @libFolders) { - push @libFolders, "$rootPath/lib"; - } - if (!grep { m[^$rootPath/usr/lib$] } @libFolders) { - push @libFolders, "$rootPath/usr/lib"; - } -} - -sub addLib -{ - my $lib = shift; - - if (!exists $libInfo{$lib}) { - push @libs, $lib; - my $libPath; - foreach my $folder (@libFolders) { - if (-e "$folder/$lib") { - $libPath = "$folder/$lib"; - last; - } - } - if (!defined $libPath) { - die _tr("*** unable to find lib %s! ***\n", $lib); - } - print "$libPath\n"; - $libInfo{$lib} = $libPath; - addLibsForBinary($libPath); - } -} - -sub addLibsForBinary -{ - my $binary = shift; - - # we try objdump... - my $res = `objdump -p $binary 2>/dev/null`; - if (!$?) { - while($res =~ m[^\s*NEEDED\s*(.+?)\s*$]gm) { - addLib($1); - } - } else { - # ...objdump failed, so we try readelf instead: - $res = `readelf -d $binary 2>/dev/null`; - if ($?) { - die _tr("neither objdump nor readelf seems to be installed, giving up!\n"); - } - while($res =~ m{\(NEEDED\)[^\[]+\[(.+?)\]\s*$}gm) { - addLib($1); - } - } -} - - -__END__ - -=head1 NAME - -slxldd.pl - OpenSLX-script to determine the libraries required by any given -binary file. - -=head1 SYNOPSIS - -slxldd.pl [options] file [...more files] - - Options: - --help brief help message - --root-path= path to the root folder for library search - --version show version - -=head1 OPTIONS - -=over 8 - -=item B<--help> - -Prints a brief help message and exits. - -=item B<--root-path=> - -Sets the root folder that is used when searching for libraries. In order to -collect the loader-settings, etc/ld.so.conf is read relative to this path and -all libraries are sought relative to this path, too (a.k.a. a virtual chroot). - -=item B<--version> - -Prints the version and exits. - -=back - -=cut \ No newline at end of file diff --git a/config-db/slxsettings b/config-db/slxsettings new file mode 100755 index 00000000..4c82be28 --- /dev/null +++ b/config-db/slxsettings @@ -0,0 +1,317 @@ +#! /usr/bin/perl +# +# slxsetup.pl - OpenSLX-script to show & change local settings +# +# (c) 2006 - OpenSLX.com +# +# Oliver Tappe +# +use strict; + +my $abstract = q[ +slxsetup.pl + This script can be used to show or change the local settings for OpenSLX. + + Any cmdline-argument passed to this script will change the local OpenSLX + settings file (usually /etc/opt/openslx/settings.local). + + If you invoke the script without any arguments, it will print the current + settings and exit. + + Please use the --man option in order to read the full manual. +]; + +use Getopt::Long qw(:config pass_through); +use Pod::Usage; + +# add the lib-folder and the folder this script lives in to perl's search +# path for modules: +use FindBin; +use lib "$FindBin::RealBin/../lib"; + # production path +use lib "$FindBin::RealBin"; + # development path + +use OpenSLX::Basics; + +my ( + $noShow, + $quiet, + @remove, + $helpReq, + $manReq, + $versionReq, +); + +GetOptions( + 'noshow' => \$noShow, + # will display current configuration + 'quiet' => \$quiet, + # will avoid printing anything + 'remove=s' => \@remove, + # will avoid printing anything + + 'help|?' => \$helpReq, + 'man' => \$manReq, + 'version' => \$versionReq, +); +pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq; +pod2usage(-verbose => 2) if $manReq; +if ($versionReq) { + system('slxversion'); + exit 1; +} + +openslxInit() or pod2usage(2); + +# fetch current content of local settings file... +open(SETTINGS, "< $openslxConfig{'config-path'}/settings.local"); +$/ = undef; +my $settings = ; +close(SETTINGS); + +my $changeCount; + +# ...set new values... +foreach my $key (sort keys %cmdlineConfig) { + next if $key eq 'config-path'; + # config-path can't be changed, it is used to find settings.local + my $value = $cmdlineConfig{$key}; + next if !defined $value; + vlog 0, _tr('setting %s to <%s>', $key, $value) unless $quiet; + $key =~ tr[-][_]; + my $externalKey = "SLX_".uc($key); + if (!($settings =~ s[^\s*$externalKey=.*?$][$externalKey=$value]ms)) { + $settings .= "$externalKey=$value\n"; + } + $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; + } + vlog 0, _tr('removing %s', $key) unless $quiet; + $key =~ tr[-][_]; + my $externalKey = "SLX_".uc($key); + $settings =~ s[^\s*$externalKey=.*?$][]ms; + $changeCount++; +} + +# ... and write local settings file if necessary +if ($changeCount) { + my $f = "$openslxConfig{'config-path'}/settings.local"; + open(SETTINGS, "> $f") + or die _tr('Unable to write local settings file <%s> (%s)', $f, $!); + print SETTINGS $settings; + close(SETTINGS); +} + +if (!($noShow || $quiet)) { + print "\n"._tr("resulting settings:")."\n"; + foreach my $key (sort keys %openslxConfig) { + print "\t$key=$openslxConfig{$key}\n"; + } +} + +__END__ + +=head1 NAME + +slxsetup.pl - OpenSLX-script to show & change local settings + +=head1 SYNOPSIS + +slxsetup.pl [options] + + Script Options: + --noshow do not print resulting settings + --quiet do not print anything + --remove= remove given key from settings + + OpenSLX Options: + --base-path= basic path to project files + --bin-path= path to binaries and scripts + --config-path= path to configuration files + --db-basepath= basic path to openslx database + --db-datadir= data folder created under db-basepath + --db-name= name of database + --db-spec= full DBI-specification of database + --db-type= type of database to connect to + --export-path= path to root of all exported filesystems + --locale= locale to use for translations + --logfile= file to write logging output to + --private-path= path to private data + --public-path= path to public (client-accesible) data + --share-path= path to sharable data + --temp-path= path to temporary data + --tftpboot-path= path to root of tftp-server + --verbose-level= level of logging verbosity (0-3) + + General Options: + --help brief help message + --man full documentation + --version show version + +=head1 OPTIONS + +=head3 Script Options + +=over 8 + +=item B<--noshow> + +Avoids printing the resulting settings after any changes have been applied. + +=item B<--quiet> + +Runs the script without printing anything. + +=item B<--remove=> + +Removes given key from settings (apply more than once to remove several keys). + +=back + +=head3 OpenSLX Options + +=over 8 + +=item B<--base-path=> + +Sets basic path to project files. + +Default is $SLX_BASE_PATH (usually F). + +=item B<--bin-path=> + +Sets path to binaries and scripts. + +Default is $SLX_BASE_PATH/bin (usually F). + +=item B<--config-path=> + +Sets path to configuration files. + +Default is $SLX_CONFIG_PATH (usually F). + +=item B<--db-basepath=> + +Sets basic path to openslx database. + +Default is $SLX_DB_PATH (usually F). + +=item B<--db-datadir=> + +Sets data folder created under db-basepath. + +Default is $SLX_DB_DATADIR (usually empty as it depends on db-type +whether or not such a directory is required at all). + +=item B<--db-name=> + +Gives the name of the database to connect to. + +Default is $SLX_DB_NAME (usually C). + +=item B<--db-spec=> + +Gives the full DBI-specification of database to connect to. Content depends +on the db-type. + +Default is $SLX_DB_SPEC (usually empty as it will be built automatically). + +=item B<--db-type=> + +Sets the type of database to connect to (CSV, SQLite, mysql, ...). + +Default $SLX_DB_TYPE (usually C). + +=item B<--export-path=> + +Sets path to root of all exported filesystems. For each type of export (NFS, +NBD, ...) a separate folder will be created in here. + +Default is $SLX_EXPORT_PATH (usually F. + +=item B<--locale=> + +Sets the locale to use for translations. + +Defaults to the system's standard locale. + +=item B<--logfile=> + +Specifies a file where logging output will be written to. + +Default is to log to STDERR. + +=item B<--private-path=> + +Sets path to private data, where the config-db, vendor_oses and configurational +extensions will be stored. + +Default is $SLX_PRIVATE_PATH (usually F. + +=item B<--public-path=> + +Sets path to public (client-accesible) data. + +Default is $SLX_PUBLIC_PATH (usually F. + +=item B<--share-path=> + +Sets path to sharable data, where distro-specs and functionality templates +will be stored. + +Default is $SLX_SHARE_PATH (usually F. + +=item B<--temp-path=> + +Sets path to temporary data. + +Default is $SLX_TEMP_PATH (usually F. + +=item B<--tftpboot-path=> + +Sets path to root of tftp-server from which clients will access their files. + +Default is $SLX_TFTPBOOT_PATH (usually F. + +=item B<--verbose-level=> + +Sets the level of logging verbosity (0-3). + +Default is $SLX_VERBOSE_LEVEL (usually 0, no logging). + +=back + +=head3 General Options + +=over 8 + +=item B<--help> + +Prints a brief help message and exits. + +=item B<--man> + +Prints the manual page and exits. + +=item B<--version> + +Prints the version and exits. + +=back + +=head1 DESCRIPTION + +B can be used to show or change the local settings for OpenSLX. + +Any cmdline-argument passed to this script will change the local OpenSLX +settings file (usually /etc/opt/openslx/settings.local). + +If you invoke the script without any arguments, it will print the current +settings and exit. diff --git a/config-db/slxsetup b/config-db/slxsetup new file mode 100755 index 00000000..71afa0a3 --- /dev/null +++ b/config-db/slxsetup @@ -0,0 +1,341 @@ +#! /usr/bin/perl +# +# slxsetup-test-data-simple.pl - Simple OpenSLX test data generator +# +# (c) 2006 - OpenSLX.com +# +# Oliver Tappe +# +use strict; + +my $abstract = q[ +slxsetup-test-data-simple.pl + This script will generate a very simple OpenSLX test-dataset, useful for + testing and/or trying things out. + + If the OpenSLX configuration database already contains data, the script + will ask for confirmation before clobbering that database. +]; + +use Getopt::Long qw(:config pass_through); +use Pod::Usage; + +# add the lib-folder and the folder this script lives in to perl's search +# path for modules: +use FindBin; +use lib "$FindBin::RealBin/../lib"; + # production path +use lib "$FindBin::RealBin"; + # development path + +use OpenSLX::Basics; +use OpenSLX::ConfigDB qw(:access :manipulation); + +my ( + $clobber, + $helpReq, + $manReq, + $versionReq, +); + +GetOptions( + 'clobber' => \$clobber, + # clobber causes this script to overwrite the database without asking + 'help|?' => \$helpReq, + 'man' => \$manReq, + 'version' => \$versionReq, +); +pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq; +pod2usage(-verbose => 2) if $manReq; +if ($versionReq) { + system('slxversion'); + exit 1; +} + +openslxInit() or pod2usage(2); + +my $openslxDB = connectConfigDB(); + +my @systems = fetchSystemsByFilter($openslxDB); +my $systemCount = scalar(@systems)-1; + # ignore default system +my @clients = fetchClientsByFilter($openslxDB); +my $clientCount = scalar(@clients)-1; + # ignore default client +if ($systemCount && $clientCount && !$clobber) { + my $yes = _tr('yes'); + my $no = _tr('no'); + print _tr(qq[This will overwrite the current OpenSLX-database with an example dataset. +All your data (%s systems and %s clients) will be lost! +Do you want to continue(%s/%s)? ], $systemCount, $clientCount, $yes, $no); + my $answer = <>; + if ($answer !~ m[^\s*$yes]i) { + print "no - stopping\n"; + exit 5; + } + print "yes - starting...\n"; +} + +emptyDatabase($openslxDB); + +my $vendorOs1Id = addVendorOS($openslxDB, { + 'name' => "suse-10", + 'comment' => "SuSE 10.0 Default-Installation", + 'path' => "suse-10.0", +}); + +my $vendorOs2Id = addVendorOS($openslxDB, { + 'name' => "suse-10.1", + 'comment' => "SuSE 10.1 Default-Installation", + 'path' => "suse-10.1", +}); + +my @systems; + +my $system1Id = addSystem($openslxDB, { + 'name' => "suse-10.0", + 'label' => "SUSE LINUX 10.0", + 'comment' => "Testsystem für openslx", + 'vendor_os_id' => $vendorOs1Id, + 'ramfs_debug_level' => 0, + 'ramfs_use_glibc' => 0, + 'ramfs_use_busybox' => 0, + 'ramfs_nicmods' => '', + 'ramfs_fsmods' => '', + 'kernel' => "boot/vmlinuz-2.6.13-15-default", + 'kernel_params' => "", + 'export_type' => 'nfs', + 'attr_start_xdmcp' => 'kdm', +}); + +my $system2Id = addSystem($openslxDB, { + 'name' => "suse-10.1", + 'label' => "SUSE LINUX 10.1", + 'comment' => "Testsystem für openslx", + 'vendor_os_id' => $vendorOs2Id, + 'ramfs_debug_level' => 0, + 'ramfs_use_glibc' => 0, + 'ramfs_use_busybox' => 0, + 'ramfs_nicmods' => '', + 'ramfs_fsmods' => '', + 'kernel' => "boot/vmlinuz-2.6.16.21-0.21-default", + 'kernel_params' => "debug=0", + 'export_type' => 'nfs', + 'attr_start_xdmcp' => 'kdm', +}); + +my $client1Id = addClient($openslxDB, { + 'name' => "Client-1", + 'mac' => "00:50:56:0D:03:38", + 'boot_type' => 'pxe', +}); + +my $client2Id = addClient($openslxDB, { + 'name' => "Client-2", + 'mac' => "00:16:41:55:12:92", + 'boot_type' => 'pxe', +}); + +addSystemIDsToClient($openslxDB, $client1Id, [$system1Id, $system2Id]); +addSystemIDsToClient($openslxDB, $client2Id, [$system2Id]); + +disconnectConfigDB($openslxDB); + +if ($openslxConfig{'db-type'} =~ m[^\s*csv\s*$]i) { + my $csvFolder = "$openslxConfig{'db-basepath'}/$openslxConfig{'db-name'}-csv"; + print "The test-database with the CSV-files has been created in\n"; + print "\t$csvFolder\n"; + print "You can change the dataset with a simple editor or using\n"; + print "a spreadsheet software like 'OpenOffice Calc' or 'Gnumeric'.\n"; +} + +__END__ + +=head1 NAME + +slxsetup-test-data-simple.pl - Simple OpenSLX test data generator + +=head1 SYNOPSIS + +slxsetup-test-data-simple.pl [options] + + Script Options: + --clobber overwrites config-db without asking + + OpenSLX Options: + --base-path= basic path to project files + --bin-path= path to binaries and scripts + --config-path= path to configuration files + --db-basepath= basic path to openslx database + --db-datadir= data folder created under db-basepath + --db-name= name of database + --db-spec= full DBI-specification of database + --db-type= type of database to connect to + --export-path= path to root of all exported filesystems + --locale= locale to use for translations + --logfile= file to write logging output to + --private-path= path to private data + --public-path= path to public (client-accesible) data + --share-path= path to sharable data + --temp-path= path to temporary data + --tftpboot-path= path to root of tftp-server + --verbose-level= level of logging verbosity (0-3) + + General Options: + --help brief help message + --man full documentation + --version show version + +=head1 OPTIONS + +=head3 Script Options + +=over 8 + +=item B<--clobber> + +Runs the script without asking any questions, B + +=back + +=head3 OpenSLX Options + +=over 8 + +=item B<--base-path=> + +Sets basic path to project files. + +Default is $SLX_BASE_PATH (usually F). + +=item B<--bin-path=> + +Sets path to binaries and scripts. + +Default is $SLX_BASE_PATH/bin (usually F). + +=item B<--config-path=> + +Sets path to configuration files. + +Default is $SLX_CONFIG_PATH (usually F). + +=item B<--db-basepath=> + +Sets basic path to openslx database. + +Default is $SLX_DB_PATH (usually F). + +=item B<--db-datadir=> + +Sets data folder created under db-basepath. + +Default is $SLX_DB_DATADIR (usually empty as it depends on db-type +whether or not such a directory is required at all). + +=item B<--db-name=> + +Gives the name of the database to connect to. + +Default is $SLX_DB_NAME (usually C). + +=item B<--db-spec=> + +Gives the full DBI-specification of database to connect to. Content depends +on the db-type. + +Default is $SLX_DB_SPEC (usually empty as it will be built automatically). + +=item B<--db-type=> + +Sets the type of database to connect to (CSV, SQLite, mysql, ...). + +Default $SLX_DB_TYPE (usually C). + +=item B<--export-path=> + +Sets path to root of all exported filesystems. For each type of export (NFS, +NBD, ...) a separate folder will be created in here. + +Default is $SLX_EXPORT_PATH (usually F. + +=item B<--locale=> + +Sets the locale to use for translations. + +Defaults to the system's standard locale. + +=item B<--logfile=> + +Specifies a file where logging output will be written to. + +Default is to log to STDERR. + +=item B<--private-path=> + +Sets path to private data, where the config-db, vendor_oses and configurational +extensions will be stored. + +Default is $SLX_PRIVATE_PATH (usually F. + +=item B<--public-path=> + +Sets path to public (client-accesible) data. + +Default is $SLX_PUBLIC_PATH (usually F. + +=item B<--share-path=> + +Sets path to sharable data, where distro-specs and functionality templates +will be stored. + +Default is $SLX_SHARE_PATH (usually F. + +=item B<--temp-path=> + +Sets path to temporary data. + +Default is $SLX_TEMP_PATH (usually F. + +=item B<--tftpboot-path=> + +Sets path to root of tftp-server from which clients will access their files. + +Default is $SLX_TFTPBOOT_PATH (usually F. + +=item B<--verbose-level=> + +Sets the level of logging verbosity (0-3). + +Default is $SLX_VERBOSE_LEVEL (usually 0, no logging). + +=back + +=head3 General Options + +=over 8 + +=item B<--help> + +Prints a brief help message and exits. + +=item B<--man> + +Prints the manual page and exits. + +=item B<--version> + +Prints the version and exits. + +=back + +=head1 DESCRIPTION + +B will generate a very simple test-dataset +useful for testing and/or trying things out. + +If the OpenSLX configuration database already contains data, the script +will ask for confirmation before clobbering that database. + +=cut \ No newline at end of file diff --git a/config-db/slxsetup-test-data-simple.pl b/config-db/slxsetup-test-data-simple.pl deleted file mode 100755 index 71afa0a3..00000000 --- a/config-db/slxsetup-test-data-simple.pl +++ /dev/null @@ -1,341 +0,0 @@ -#! /usr/bin/perl -# -# slxsetup-test-data-simple.pl - Simple OpenSLX test data generator -# -# (c) 2006 - OpenSLX.com -# -# Oliver Tappe -# -use strict; - -my $abstract = q[ -slxsetup-test-data-simple.pl - This script will generate a very simple OpenSLX test-dataset, useful for - testing and/or trying things out. - - If the OpenSLX configuration database already contains data, the script - will ask for confirmation before clobbering that database. -]; - -use Getopt::Long qw(:config pass_through); -use Pod::Usage; - -# add the lib-folder and the folder this script lives in to perl's search -# path for modules: -use FindBin; -use lib "$FindBin::RealBin/../lib"; - # production path -use lib "$FindBin::RealBin"; - # development path - -use OpenSLX::Basics; -use OpenSLX::ConfigDB qw(:access :manipulation); - -my ( - $clobber, - $helpReq, - $manReq, - $versionReq, -); - -GetOptions( - 'clobber' => \$clobber, - # clobber causes this script to overwrite the database without asking - 'help|?' => \$helpReq, - 'man' => \$manReq, - 'version' => \$versionReq, -); -pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq; -pod2usage(-verbose => 2) if $manReq; -if ($versionReq) { - system('slxversion'); - exit 1; -} - -openslxInit() or pod2usage(2); - -my $openslxDB = connectConfigDB(); - -my @systems = fetchSystemsByFilter($openslxDB); -my $systemCount = scalar(@systems)-1; - # ignore default system -my @clients = fetchClientsByFilter($openslxDB); -my $clientCount = scalar(@clients)-1; - # ignore default client -if ($systemCount && $clientCount && !$clobber) { - my $yes = _tr('yes'); - my $no = _tr('no'); - print _tr(qq[This will overwrite the current OpenSLX-database with an example dataset. -All your data (%s systems and %s clients) will be lost! -Do you want to continue(%s/%s)? ], $systemCount, $clientCount, $yes, $no); - my $answer = <>; - if ($answer !~ m[^\s*$yes]i) { - print "no - stopping\n"; - exit 5; - } - print "yes - starting...\n"; -} - -emptyDatabase($openslxDB); - -my $vendorOs1Id = addVendorOS($openslxDB, { - 'name' => "suse-10", - 'comment' => "SuSE 10.0 Default-Installation", - 'path' => "suse-10.0", -}); - -my $vendorOs2Id = addVendorOS($openslxDB, { - 'name' => "suse-10.1", - 'comment' => "SuSE 10.1 Default-Installation", - 'path' => "suse-10.1", -}); - -my @systems; - -my $system1Id = addSystem($openslxDB, { - 'name' => "suse-10.0", - 'label' => "SUSE LINUX 10.0", - 'comment' => "Testsystem für openslx", - 'vendor_os_id' => $vendorOs1Id, - 'ramfs_debug_level' => 0, - 'ramfs_use_glibc' => 0, - 'ramfs_use_busybox' => 0, - 'ramfs_nicmods' => '', - 'ramfs_fsmods' => '', - 'kernel' => "boot/vmlinuz-2.6.13-15-default", - 'kernel_params' => "", - 'export_type' => 'nfs', - 'attr_start_xdmcp' => 'kdm', -}); - -my $system2Id = addSystem($openslxDB, { - 'name' => "suse-10.1", - 'label' => "SUSE LINUX 10.1", - 'comment' => "Testsystem für openslx", - 'vendor_os_id' => $vendorOs2Id, - 'ramfs_debug_level' => 0, - 'ramfs_use_glibc' => 0, - 'ramfs_use_busybox' => 0, - 'ramfs_nicmods' => '', - 'ramfs_fsmods' => '', - 'kernel' => "boot/vmlinuz-2.6.16.21-0.21-default", - 'kernel_params' => "debug=0", - 'export_type' => 'nfs', - 'attr_start_xdmcp' => 'kdm', -}); - -my $client1Id = addClient($openslxDB, { - 'name' => "Client-1", - 'mac' => "00:50:56:0D:03:38", - 'boot_type' => 'pxe', -}); - -my $client2Id = addClient($openslxDB, { - 'name' => "Client-2", - 'mac' => "00:16:41:55:12:92", - 'boot_type' => 'pxe', -}); - -addSystemIDsToClient($openslxDB, $client1Id, [$system1Id, $system2Id]); -addSystemIDsToClient($openslxDB, $client2Id, [$system2Id]); - -disconnectConfigDB($openslxDB); - -if ($openslxConfig{'db-type'} =~ m[^\s*csv\s*$]i) { - my $csvFolder = "$openslxConfig{'db-basepath'}/$openslxConfig{'db-name'}-csv"; - print "The test-database with the CSV-files has been created in\n"; - print "\t$csvFolder\n"; - print "You can change the dataset with a simple editor or using\n"; - print "a spreadsheet software like 'OpenOffice Calc' or 'Gnumeric'.\n"; -} - -__END__ - -=head1 NAME - -slxsetup-test-data-simple.pl - Simple OpenSLX test data generator - -=head1 SYNOPSIS - -slxsetup-test-data-simple.pl [options] - - Script Options: - --clobber overwrites config-db without asking - - OpenSLX Options: - --base-path= basic path to project files - --bin-path= path to binaries and scripts - --config-path= path to configuration files - --db-basepath= basic path to openslx database - --db-datadir= data folder created under db-basepath - --db-name= name of database - --db-spec= full DBI-specification of database - --db-type= type of database to connect to - --export-path= path to root of all exported filesystems - --locale= locale to use for translations - --logfile= file to write logging output to - --private-path= path to private data - --public-path= path to public (client-accesible) data - --share-path= path to sharable data - --temp-path= path to temporary data - --tftpboot-path= path to root of tftp-server - --verbose-level= level of logging verbosity (0-3) - - General Options: - --help brief help message - --man full documentation - --version show version - -=head1 OPTIONS - -=head3 Script Options - -=over 8 - -=item B<--clobber> - -Runs the script without asking any questions, B - -=back - -=head3 OpenSLX Options - -=over 8 - -=item B<--base-path=> - -Sets basic path to project files. - -Default is $SLX_BASE_PATH (usually F). - -=item B<--bin-path=> - -Sets path to binaries and scripts. - -Default is $SLX_BASE_PATH/bin (usually F). - -=item B<--config-path=> - -Sets path to configuration files. - -Default is $SLX_CONFIG_PATH (usually F). - -=item B<--db-basepath=> - -Sets basic path to openslx database. - -Default is $SLX_DB_PATH (usually F). - -=item B<--db-datadir=> - -Sets data folder created under db-basepath. - -Default is $SLX_DB_DATADIR (usually empty as it depends on db-type -whether or not such a directory is required at all). - -=item B<--db-name=> - -Gives the name of the database to connect to. - -Default is $SLX_DB_NAME (usually C). - -=item B<--db-spec=> - -Gives the full DBI-specification of database to connect to. Content depends -on the db-type. - -Default is $SLX_DB_SPEC (usually empty as it will be built automatically). - -=item B<--db-type=> - -Sets the type of database to connect to (CSV, SQLite, mysql, ...). - -Default $SLX_DB_TYPE (usually C). - -=item B<--export-path=> - -Sets path to root of all exported filesystems. For each type of export (NFS, -NBD, ...) a separate folder will be created in here. - -Default is $SLX_EXPORT_PATH (usually F. - -=item B<--locale=> - -Sets the locale to use for translations. - -Defaults to the system's standard locale. - -=item B<--logfile=> - -Specifies a file where logging output will be written to. - -Default is to log to STDERR. - -=item B<--private-path=> - -Sets path to private data, where the config-db, vendor_oses and configurational -extensions will be stored. - -Default is $SLX_PRIVATE_PATH (usually F. - -=item B<--public-path=> - -Sets path to public (client-accesible) data. - -Default is $SLX_PUBLIC_PATH (usually F. - -=item B<--share-path=> - -Sets path to sharable data, where distro-specs and functionality templates -will be stored. - -Default is $SLX_SHARE_PATH (usually F. - -=item B<--temp-path=> - -Sets path to temporary data. - -Default is $SLX_TEMP_PATH (usually F. - -=item B<--tftpboot-path=> - -Sets path to root of tftp-server from which clients will access their files. - -Default is $SLX_TFTPBOOT_PATH (usually F. - -=item B<--verbose-level=> - -Sets the level of logging verbosity (0-3). - -Default is $SLX_VERBOSE_LEVEL (usually 0, no logging). - -=back - -=head3 General Options - -=over 8 - -=item B<--help> - -Prints a brief help message and exits. - -=item B<--man> - -Prints the manual page and exits. - -=item B<--version> - -Prints the version and exits. - -=back - -=head1 DESCRIPTION - -B will generate a very simple test-dataset -useful for testing and/or trying things out. - -If the OpenSLX configuration database already contains data, the script -will ask for confirmation before clobbering that database. - -=cut \ No newline at end of file diff --git a/config-db/slxsetup.pl b/config-db/slxsetup.pl deleted file mode 100755 index 4c82be28..00000000 --- a/config-db/slxsetup.pl +++ /dev/null @@ -1,317 +0,0 @@ -#! /usr/bin/perl -# -# slxsetup.pl - OpenSLX-script to show & change local settings -# -# (c) 2006 - OpenSLX.com -# -# Oliver Tappe -# -use strict; - -my $abstract = q[ -slxsetup.pl - This script can be used to show or change the local settings for OpenSLX. - - Any cmdline-argument passed to this script will change the local OpenSLX - settings file (usually /etc/opt/openslx/settings.local). - - If you invoke the script without any arguments, it will print the current - settings and exit. - - Please use the --man option in order to read the full manual. -]; - -use Getopt::Long qw(:config pass_through); -use Pod::Usage; - -# add the lib-folder and the folder this script lives in to perl's search -# path for modules: -use FindBin; -use lib "$FindBin::RealBin/../lib"; - # production path -use lib "$FindBin::RealBin"; - # development path - -use OpenSLX::Basics; - -my ( - $noShow, - $quiet, - @remove, - $helpReq, - $manReq, - $versionReq, -); - -GetOptions( - 'noshow' => \$noShow, - # will display current configuration - 'quiet' => \$quiet, - # will avoid printing anything - 'remove=s' => \@remove, - # will avoid printing anything - - 'help|?' => \$helpReq, - 'man' => \$manReq, - 'version' => \$versionReq, -); -pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq; -pod2usage(-verbose => 2) if $manReq; -if ($versionReq) { - system('slxversion'); - exit 1; -} - -openslxInit() or pod2usage(2); - -# fetch current content of local settings file... -open(SETTINGS, "< $openslxConfig{'config-path'}/settings.local"); -$/ = undef; -my $settings = ; -close(SETTINGS); - -my $changeCount; - -# ...set new values... -foreach my $key (sort keys %cmdlineConfig) { - next if $key eq 'config-path'; - # config-path can't be changed, it is used to find settings.local - my $value = $cmdlineConfig{$key}; - next if !defined $value; - vlog 0, _tr('setting %s to <%s>', $key, $value) unless $quiet; - $key =~ tr[-][_]; - my $externalKey = "SLX_".uc($key); - if (!($settings =~ s[^\s*$externalKey=.*?$][$externalKey=$value]ms)) { - $settings .= "$externalKey=$value\n"; - } - $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; - } - vlog 0, _tr('removing %s', $key) unless $quiet; - $key =~ tr[-][_]; - my $externalKey = "SLX_".uc($key); - $settings =~ s[^\s*$externalKey=.*?$][]ms; - $changeCount++; -} - -# ... and write local settings file if necessary -if ($changeCount) { - my $f = "$openslxConfig{'config-path'}/settings.local"; - open(SETTINGS, "> $f") - or die _tr('Unable to write local settings file <%s> (%s)', $f, $!); - print SETTINGS $settings; - close(SETTINGS); -} - -if (!($noShow || $quiet)) { - print "\n"._tr("resulting settings:")."\n"; - foreach my $key (sort keys %openslxConfig) { - print "\t$key=$openslxConfig{$key}\n"; - } -} - -__END__ - -=head1 NAME - -slxsetup.pl - OpenSLX-script to show & change local settings - -=head1 SYNOPSIS - -slxsetup.pl [options] - - Script Options: - --noshow do not print resulting settings - --quiet do not print anything - --remove= remove given key from settings - - OpenSLX Options: - --base-path= basic path to project files - --bin-path= path to binaries and scripts - --config-path= path to configuration files - --db-basepath= basic path to openslx database - --db-datadir= data folder created under db-basepath - --db-name= name of database - --db-spec= full DBI-specification of database - --db-type= type of database to connect to - --export-path= path to root of all exported filesystems - --locale= locale to use for translations - --logfile= file to write logging output to - --private-path= path to private data - --public-path= path to public (client-accesible) data - --share-path= path to sharable data - --temp-path= path to temporary data - --tftpboot-path= path to root of tftp-server - --verbose-level= level of logging verbosity (0-3) - - General Options: - --help brief help message - --man full documentation - --version show version - -=head1 OPTIONS - -=head3 Script Options - -=over 8 - -=item B<--noshow> - -Avoids printing the resulting settings after any changes have been applied. - -=item B<--quiet> - -Runs the script without printing anything. - -=item B<--remove=> - -Removes given key from settings (apply more than once to remove several keys). - -=back - -=head3 OpenSLX Options - -=over 8 - -=item B<--base-path=> - -Sets basic path to project files. - -Default is $SLX_BASE_PATH (usually F). - -=item B<--bin-path=> - -Sets path to binaries and scripts. - -Default is $SLX_BASE_PATH/bin (usually F). - -=item B<--config-path=> - -Sets path to configuration files. - -Default is $SLX_CONFIG_PATH (usually F). - -=item B<--db-basepath=> - -Sets basic path to openslx database. - -Default is $SLX_DB_PATH (usually F). - -=item B<--db-datadir=> - -Sets data folder created under db-basepath. - -Default is $SLX_DB_DATADIR (usually empty as it depends on db-type -whether or not such a directory is required at all). - -=item B<--db-name=> - -Gives the name of the database to connect to. - -Default is $SLX_DB_NAME (usually C). - -=item B<--db-spec=> - -Gives the full DBI-specification of database to connect to. Content depends -on the db-type. - -Default is $SLX_DB_SPEC (usually empty as it will be built automatically). - -=item B<--db-type=> - -Sets the type of database to connect to (CSV, SQLite, mysql, ...). - -Default $SLX_DB_TYPE (usually C). - -=item B<--export-path=> - -Sets path to root of all exported filesystems. For each type of export (NFS, -NBD, ...) a separate folder will be created in here. - -Default is $SLX_EXPORT_PATH (usually F. - -=item B<--locale=> - -Sets the locale to use for translations. - -Defaults to the system's standard locale. - -=item B<--logfile=> - -Specifies a file where logging output will be written to. - -Default is to log to STDERR. - -=item B<--private-path=> - -Sets path to private data, where the config-db, vendor_oses and configurational -extensions will be stored. - -Default is $SLX_PRIVATE_PATH (usually F. - -=item B<--public-path=> - -Sets path to public (client-accesible) data. - -Default is $SLX_PUBLIC_PATH (usually F. - -=item B<--share-path=> - -Sets path to sharable data, where distro-specs and functionality templates -will be stored. - -Default is $SLX_SHARE_PATH (usually F. - -=item B<--temp-path=> - -Sets path to temporary data. - -Default is $SLX_TEMP_PATH (usually F. - -=item B<--tftpboot-path=> - -Sets path to root of tftp-server from which clients will access their files. - -Default is $SLX_TFTPBOOT_PATH (usually F. - -=item B<--verbose-level=> - -Sets the level of logging verbosity (0-3). - -Default is $SLX_VERBOSE_LEVEL (usually 0, no logging). - -=back - -=head3 General Options - -=over 8 - -=item B<--help> - -Prints a brief help message and exits. - -=item B<--man> - -Prints the manual page and exits. - -=item B<--version> - -Prints the version and exits. - -=back - -=head1 DESCRIPTION - -B can be used to show or change the local settings for OpenSLX. - -Any cmdline-argument passed to this script will change the local OpenSLX -settings file (usually /etc/opt/openslx/settings.local). - -If you invoke the script without any arguments, it will print the current -settings and exit. diff --git a/config-db/test-config-db.pl b/config-db/test-config-db.pl deleted file mode 100755 index ecbdbd15..00000000 --- a/config-db/test-config-db.pl +++ /dev/null @@ -1,202 +0,0 @@ -#! /usr/bin/perl -# -# test-config-db.pl - test-script for the OpenSLX config-db & MetaDB modules. -# -# (c) 2006 - OpenSLX.com -# -# Oliver Tappe -# -use strict; - -# add the folder this script lives in to perl's search path for modules: -use FindBin; -use lib "$FindBin::RealBin"; - # development path only (as script should never be installed) - -use OpenSLX::Basics; -use OpenSLX::ConfigDB qw(:access :manipulation); - -openslxInit(); - -my $openslxDB = connectConfigDB(); - -addVendorOS($openslxDB, { - 'name' => "suse-93-minimal", - 'descr' => "SuSE 9.3 minimale Installation", -}); - -addVendorOS($openslxDB, { - 'name' => "suse-93-KDE", - 'descr' => "SuSE 9.3 grafische Installation mit KDE", -}); - -addVendorOS($openslxDB, { - 'name' => "debian-31", - 'descr' => "Debian 3.1 Default-Installation", -}); - -my @systems; -foreach my $id (1..10) { - push @systems, { - 'name' => "name of $id", - 'descr' => "descr of $id", - 'vendor_os_id' => 1 + $id % 3, - }; -} -addSystem($openslxDB, \@systems); - -removeSystem($openslxDB, [1,3,5,7,9,11,13,15,17,19] ); - -changeSystem($openslxDB, [ 2 ], [ { 'name' => 'new name of 2'} ] ); - -changeSystem($openslxDB, [ 0 ], [ { 'attrStartX' => 'kde,gnome'} ] ); -changeSystem($openslxDB, [ 1,2,3 ], [ { 'attrHwMonitor' => '1280x1024'} ] ); -changeSystem($openslxDB, [ 4 ], [ { 'attrHwMonitor' => '800x600'} ] ); - - -changeSystem($openslxDB, 4, { 'id' => 114, 'name' => 'id should still be 4'} ); - -my $metaDB = $openslxDB->{'meta-db'}; -my $colDescrs = [ - 'id:pk', - 'name:s.30', - 'descr:s.1024', - 'counter:i', - 'hidden:b', - 'dropped1:b', - 'dropped2:b', -]; -my $initialVals = [ - { - 'name' => '123456789012345678901234567890xxx', - 'descr' => 'descr-value-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - 'counter' => 34567, - 'hidden' => 1, - 'dropped1' => 0, - 'dropped2' => 1, - }, - { - 'name' => 'name', - 'descr' => q[from_äöüß#'"$...\to_here], - 'counter' => -1, - 'hidden' => 0, - 'dropped1' => 1, - 'dropped2' => 0, - }, -]; - - -$metaDB->schemaAddTable('test', $colDescrs, $initialVals); - -$metaDB->schemaRenameTable('test', 'test2', $colDescrs); - -push @$colDescrs, 'added:s.20'; -push @$colDescrs, 'added2:s.20'; -$metaDB->schemaAddColumns('test2', - ['added:s.20', 'added2:b'], - [{'added' => 'added'}, {'added2' => '1'}], - $colDescrs); - -my @rows = $metaDB->_doSelect("SELECT * FROM test2"); -foreach my $row (@rows) { - foreach my $r (keys %$row) { - print "$r = $row->{$r}\n"; - } -} - -$colDescrs = [grep {$_ !~ m[dropped]} @$colDescrs]; -$metaDB->schemaDropColumns('test2', ['dropped1', 'dropped2'], $colDescrs); - - -$colDescrs = [ - map { - if ($_ =~ m[counter]) { - "count:i"; - } elsif ($_ =~ m[descr]) { - "description:s.30"; - } else { - $_ - } - } @$colDescrs -]; -$metaDB->schemaChangeColumns('test2', - { 'counter' => 'count:i', - 'descr' => 'description:s.30' }, - $colDescrs); - -my @rows = $metaDB->_doSelect("SELECT * FROM test2"); -foreach my $row (@rows) { - foreach my $r (keys %$row) { - print "$r = $row->{$r}\n"; - } -} - -$metaDB->schemaDropTable('test2'); - -my $clientG01ID = addClient($openslxDB, { - 'name' => "PC-G-01", - 'mac' => "00:14:85:80:00:35", - 'boot_type' => 'pxe', -}); - -my $clientG02ID = addClient($openslxDB, { - 'name' => "PC-G-02", - 'mac' => "00:14:85:80:00:36", - 'boot_type' => 'pxe', -}); - -my $clientG03ID = addClient($openslxDB, { - 'name' => "PC-G-03", - 'mac' => "00:14:85:80:00:37", - 'boot_type' => 'pxe', -}); - -my $clientG04ID = addClient($openslxDB, { - 'name' => "PC-G-04", - 'mac' => "00:14:85:80:00:38", - 'boot_type' => 'pxe', - 'unbootable' => 1, -}); - -my $clientF01ID = addClient($openslxDB, { - 'name' => "PC-F-01", - 'mac' => "00:14:85:80:00:31", - 'boot_type' => 'other', -}); - -my $clientF02ID = addClient($openslxDB, { - 'name' => "PC-F-02", - 'mac' => "00:14:85:80:00:32", - 'boot_type' => 'pxe', -}); - -my $clientF03ID = addClient($openslxDB, { - 'name' => "PC-F-03", - 'mac' => "00:14:85:80:00:33", - 'boot_type' => 'pxe', -}); - -addClientIDsToSystem($openslxDB, 6, [$clientG01ID, $clientG02ID, $clientG03ID, $clientG04ID, $clientF01ID, $clientF02ID, $clientF03ID]); - -my $group1ID = addGroup($openslxDB, { - 'name' => "Gell-PCs", - 'descr' => "Gell-Threemansion PCs from 2002", - 'attrHwMouse' => 'serial', -}); -addClientIDsToGroup($openslxDB, $group1ID, [$clientG01ID, $clientF02ID, $clientG03ID]); - -my $group2ID = addGroup($openslxDB, { - 'name' => "Teacher-PCs", - 'descr' => "all PCs sitting on teacher's desks", - 'attrHwMonitor' => '1600x1200', -}); -addClientIDsToGroup($openslxDB, $group2ID, [$clientG01ID, $clientF01ID]); -addSystemIDsToGroup($openslxDB, $group2ID, [2, 3]); - -my $group3ID = addGroup($openslxDB, { - 'name' => "PCs in room G", - 'descr' => "all PCs of room 234", -}); -addClientIDsToGroup($openslxDB, $group3ID, [$clientG01ID, $clientG02ID, $clientG03ID, $clientG04ID]); - -disconnectConfigDB($openslxDB); diff --git a/config-db/test-config-demuxer.pl b/config-db/test-config-demuxer.pl deleted file mode 100755 index 7fcc8f76..00000000 --- a/config-db/test-config-demuxer.pl +++ /dev/null @@ -1,220 +0,0 @@ -#! /usr/bin/perl -# -# test-config-demuxer.pl - test-script for the OpenSLX config-demuxer. -# -# (c) 2006 - OpenSLX.com -# -# Oliver Tappe -# -use strict; - -# add the folder this script lives in to perl's search path for modules: -use FindBin; -use lib "$FindBin::RealBin"; - # development path only (as script should never be installed) - -use OpenSLX::Basics; -use OpenSLX::ConfigDB qw(:access :manipulation); - -openslxInit(); - -$openslxConfig{'db-name'} = 'openslx_testscript'; - # make sure to use a database of our own! - -my $openslxDB = connectConfigDB(); - -emptyDatabase($openslxDB); - -addVendorOS($openslxDB, { - 'name' => "suse-10-minimal", - 'comment' => "SuSE 10 minimale Installation", - 'path' => "suse-10.0", - # relative to /var/lib/openslx/stage1 -}); - -addVendorOS($openslxDB, { - 'name' => "suse-10-KDE", - 'comment' => "SuSE 10 grafische Installation mit KDE", - 'path' => "suse-10.0", -}); - -addVendorOS($openslxDB, { - 'name' => "debian-31", - 'comment' => "Debian 3.1 Default-Installation", -}); - -my @systems; -foreach my $id (1..10) { - push @systems, { - 'name' => "name of $id", - 'label' => "label of $id", - 'comment' => "comment of $id", - 'vendor_os_id' => 1 + $id % 3, - 'ramfs_debug_level' => $id%2, - 'ramfs_use_glibc' => 0, - 'ramfs_use_busybox' => 0, - 'ramfs_nicmods' => ($id % 3) ? 'forcedeth e1000 e100 tg3 via-rhine r8169 pcnet32' : '', - 'ramfs_fsmods' => ($id % 3)==2 ? 'nbd ext3 nfs reiserfs xfs' : '', - 'kernel' => "boot/vmlinuz-2.6.13-15-default", - 'kernel_params' => "splash=silent", - 'export_type' => 'nfs', - }; -} -addSystem($openslxDB, \@systems); - -removeSystem($openslxDB, [1,3,5,7,9,11,13,15,17,19] ); - -changeSystem($openslxDB, [ 2 ], [ { 'name' => 'new name of 2'} ] ); - -changeSystem($openslxDB, [ 0 ], [ { 'attr_start_x' => 'kde,gnome'} ] ); -changeSystem($openslxDB, [ 1,2,3 ], [ { 'attr_hw_monitor' => '1280x1024'} ] ); -changeSystem($openslxDB, [ 4 ], [ { 'attr_hw_monitor' => '800x600'} ] ); - - -changeSystem($openslxDB, 4, { 'id' => 114, 'name' => 'id should still be 4'} ); - -my $metaDB = $openslxDB->{'meta-db'}; -my $colDescrs = [ - 'id:pk', - 'name:s.30', - 'comment:s.1024', - 'counter:i', - 'hidden:b', - 'dropped1:b', - 'dropped2:b', -]; -my $initialVals = [ - { - 'name' => '123456789012345678901234567890xxx', - 'comment' => 'comment-value-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - 'counter' => 34567, - 'hidden' => 1, - 'dropped1' => 0, - 'dropped2' => 1, - }, - { - 'name' => 'name', - 'comment' => q[from_äöüß#'"$...\to_here], - 'counter' => -1, - 'hidden' => 0, - 'dropped1' => 1, - 'dropped2' => 0, - }, -]; - - -$metaDB->schemaAddTable('test', $colDescrs, $initialVals); - -$metaDB->schemaRenameTable('test', 'test2', $colDescrs); - -push @$colDescrs, 'added:s.20'; -push @$colDescrs, 'added2:s.20'; -$metaDB->schemaAddColumns('test2', - ['added:s.20', 'added2:b'], - [{'added' => 'added'}, {'added2' => '1'}], - $colDescrs); - -my @rows = $metaDB->_doSelect("SELECT * FROM test2"); -foreach my $row (@rows) { - foreach my $r (keys %$row) { - print "$r = $row->{$r}\n"; - } -} - -$colDescrs = [grep {$_ !~ m[dropped]} @$colDescrs]; -$metaDB->schemaDropColumns('test2', ['dropped1', 'dropped2'], $colDescrs); - - -$colDescrs = [ - map { - if ($_ =~ m[counter]) { - "count:i"; - } elsif ($_ =~ m[comment]) { - "description:s.30"; - } else { - $_ - } - } @$colDescrs -]; -$metaDB->schemaChangeColumns('test2', - { 'counter' => 'count:i', - 'comment' => 'description:s.30' }, - $colDescrs); - -my @rows = $metaDB->_doSelect("SELECT * FROM test2"); -foreach my $row (@rows) { - foreach my $r (keys %$row) { - print "$r = $row->{$r}\n"; - } -} - -$metaDB->schemaDropTable('test2'); - -my $clientG01ID = addClient($openslxDB, { - 'name' => "PC-G-01", - 'mac' => "00:50:56:0D:03:35", - 'boot_type' => 'pxe', -}); - -my $clientG02ID = addClient($openslxDB, { - 'name' => "PC-G-02", - 'mac' => "00:50:56:0D:03:36", - 'boot_type' => 'pxe', - 'unbootable' => 1, -}); - -my $clientG03ID = addClient($openslxDB, { - 'name' => "PC-G-03", - 'mac' => "00:50:56:0D:03:37", - 'boot_type' => 'pxe', -}); - -my $clientG04ID = addClient($openslxDB, { - 'name' => "PC-G-04", - 'mac' => "00:50:56:0D:03:38", - 'boot_type' => 'pxe', - 'kernel_params' => 'console=ttyS0,19200', -}); - -my $clientF01ID = addClient($openslxDB, { - 'name' => "PC-F-01", - 'mac' => "00:50:56:0D:03:31", - 'boot_type' => 'other', -}); - -my $clientF02ID = addClient($openslxDB, { - 'name' => "PC-F-02", - 'mac' => "00:50:56:0D:03:32", - 'boot_type' => 'pxe', -}); - -my $clientF03ID = addClient($openslxDB, { - 'name' => "PC-F-03", - 'mac' => "00:50:56:0D:03:33", - 'boot_type' => 'pxe', -}); - -addClientIDsToSystem($openslxDB, 6, [$clientG01ID, $clientG02ID, $clientG03ID, $clientG04ID, $clientF01ID, $clientF02ID, $clientF03ID]); - -my $group1ID = addGroup($openslxDB, { - 'name' => "Gell-PCs", - 'comment' => "Gell-Threemansion PCs from 2002", - 'attr_hw_mouse' => 'serial', -}); -addClientIDsToGroup($openslxDB, $group1ID, [$clientG01ID, $clientF02ID, $clientG03ID]); - -my $group2ID = addGroup($openslxDB, { - 'name' => "Teacher-PCs", - 'comment' => "all PCs sitting on teacher's desks", - 'attr_hw_monitor' => '1600x1200', -}); -addClientIDsToGroup($openslxDB, $group2ID, [$clientG01ID, $clientF01ID]); -addSystemIDsToGroup($openslxDB, $group2ID, [2, 3]); - -my $group3ID = addGroup($openslxDB, { - 'name' => "PCs in room G", - 'comment' => "all PCs of room 234", -}); -addClientIDsToGroup($openslxDB, $group3ID, [$clientG01ID, $clientG02ID, $clientG03ID, $clientG04ID]); - -disconnectConfigDB($openslxDB); -- cgit v1.2.3-55-g7522