summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config-db/OpenSLX/ConfigDB.pm337
-rwxr-xr-xconfig-db/config-demuxer.pl234
2 files changed, 347 insertions, 224 deletions
diff --git a/config-db/OpenSLX/ConfigDB.pm b/config-db/OpenSLX/ConfigDB.pm
index 6f8d811e..b9e69d77 100644
--- a/config-db/OpenSLX/ConfigDB.pm
+++ b/config-db/OpenSLX/ConfigDB.pm
@@ -9,11 +9,13 @@ $VERSION = 1.01; # API-version . implementation-version
### database.
### Aim of this abstraction is to hide the details of the data layout and
### the peculiarities of individual database types behind a simple interface
-### that offers straightforward access to and manipulation of the OpenSLX-systems
-### and -clients (without the need to use SQL).
-### The interface is divided into two parts:
+### that offers straightforward access to and manipulation of the
+### OpenSLX-systems and -clients (without the need to use SQL).
+### The interface is divided into four parts:
### - data access methods (getting data)
### - data manipulation methods (adding, removing and changing data)
+### - data aggregation methods (combining data in ways useful for apps)
+### - support methods
################################################################################
use Exporter;
@ISA = qw(Exporter);
@@ -23,17 +25,21 @@ my @accessExports = qw(
fetchVendorOSesByFilter fetchVendorOSesByID fetchVendorOSIDsOfSystem
fetchSystemsByFilter fetchSystemsByID fetchSystemIDsOfClient
fetchSystemIDsOfGroup
+ fetchSystemsVariantByFilter fetchSystemVariantsByID
+ fetchSystemVariantIDsOfSystem
fetchClientsByFilter fetchClientsByID fetchClientIDsOfSystem
fetchClientIDsOfGroup
fetchGroupsByFilter fetchGroupsByID fetchGroupIDsOfClient
fetchGroupIDsOfSystem
);
+
my @manipulationExports = qw(
addVendorOS removeVendorOS changeVendorOS
- setSystemIDsOfVendorOS addSystemIDsToVendorOS removeSystemIDsFromVendorOS
addSystem removeSystem changeSystem
setClientIDsOfSystem addClientIDsToSystem removeClientIDsFromSystem
setGroupIDsOfSystem addGroupIDsToSystem removeGroupIDsFromSystem
+ addSystemVariant removeSystemVariant changeSystemVariant
+ removeSystemVariantIDsFromSystem
addClient removeClient changeClient
setSystemIDsOfClient addSystemIDsToClient removeSystemIDsFromClient
setGroupIDsOfClient addGroupIDsToClient removeGroupIDsFromClient
@@ -42,11 +48,26 @@ my @manipulationExports = qw(
setSystemIDsOfGroup addSystemIDsToGroup removeSystemIDsFromGroup
);
+my @aggregationExports = qw(
+ mergeDefaultAttributesIntoSystem
+ mergeDefaultAndGroupAttributesIntoClient
+ aggregatedSystemIDsOfClient aggregatedClientIDsOfSystem
+ aggregatedKernelFilesOfSystem aggregatedInitramFilesOfSystem
+);
+
+my @supportExports = qw(
+ isAttribute mergeAttributes
+ externalIDForSystem externalIDForClient
+ externalAttrName
+);
+
@EXPORT = @accessExports;
-@EXPORT_OK = @manipulationExports;
+@EXPORT_OK = (@manipulationExports, @aggregationExports, @supportExports);
%EXPORT_TAGS = (
'access' => [ @accessExports ],
'manipulation' => [ @manipulationExports ],
+ 'aggregation' => [ @aggregationExports ],
+ 'support' => [ @supportExports ],
);
################################################################################
@@ -119,6 +140,12 @@ sub _aref
return $ref;
}
+sub _unique
+{ # return given array filtered to unique elements
+ my %seenIDs;
+ return grep { !$seenIDs{$_}++; } @_;
+}
+
################################################################################
### data access interface
################################################################################
@@ -177,10 +204,11 @@ sub fetchVendorOSesByFilter
sub fetchVendorOSesByID
{
my $confDB = shift;
- my $id = shift;
+ my $ids = _aref(shift);
+ my $resultCols = shift;
- my $filter = { 'id' => $id };
- my @vendorOSes = $confDB->{'meta-db'}->fetchVendorOSesByFilter($filter);
+ my @vendorOSes
+ = $confDB->{'meta-db'}->fetchVendorOSesByID($ids, $resultCols);
return wantarray() ? @vendorOSes : shift @vendorOSes;
}
@@ -198,10 +226,10 @@ sub fetchSystemsByFilter
sub fetchSystemsByID
{
my $confDB = shift;
- my $id = shift;
+ my $ids = _aref(shift);
+ my $resultCols = shift;
- my $filter = { 'id' => $id };
- my @systems = $confDB->{'meta-db'}->fetchSystemsByFilter($filter);
+ my @systems = $confDB->{'meta-db'}->fetchSystemsByID($ids, $resultCols);
return wantarray() ? @systems : shift @systems;
}
@@ -229,6 +257,36 @@ sub fetchSystemIDsOfGroup
return $confDB->{'meta-db'}->fetchSystemIDsOfGroup($groupID);
}
+sub fetchSystemVariantsByFilter
+{
+ my $confDB = shift;
+ my $filter = shift;
+ my $resultCols = shift;
+
+ my @systemVariants
+ = $confDB->{'meta-db'}->fetchSystemVariantsByFilter($filter, $resultCols);
+ return wantarray() ? @systemVariants : shift @systemVariants;
+}
+
+sub fetchSystemVariantsByID
+{
+ my $confDB = shift;
+ my $ids = _aref(shift);
+ my $resultCols = shift;
+
+ my @systemVariants
+ = $confDB->{'meta-db'}->fetchSystemVariantsByID($ids, $resultCols);
+ return wantarray() ? @systemVariants : shift @systemVariants;
+}
+
+sub fetchSystemVariantIDsOfSystem
+{
+ my $confDB = shift;
+ my $systemID = shift;
+
+ return $confDB->{'meta-db'}->fetchSystemVariantIDsOfSystem($systemID);
+}
+
sub fetchClientsByFilter
{
my $confDB = shift;
@@ -241,10 +299,10 @@ sub fetchClientsByFilter
sub fetchClientsByID
{
my $confDB = shift;
- my $id = shift;
+ my $ids = _aref(shift);
+ my $resultCols = shift;
- my $filter = { 'id' => $id };
- my @clients = $confDB->{'meta-db'}->fetchClientsByFilter($filter);
+ my @clients = $confDB->{'meta-db'}->fetchClientsByID($ids, $resultCols);
return wantarray() ? @clients : shift @clients;
}
@@ -278,10 +336,10 @@ sub fetchGroupsByFilter
sub fetchGroupsByID
{
my $confDB = shift;
- my $id = shift;
+ my $ids = _aref(shift);
+ my $resultCols = shift;
- my $filter = { 'id' => $id };
- my @groups = $confDB->{'meta-db'}->fetchGroupsByFilter($filter);
+ my @groups = $confDB->{'meta-db'}->fetchGroupsByID($ids, $resultCols);
return wantarray() ? @groups : shift @groups;
}
@@ -329,44 +387,6 @@ sub changeVendorOS
return $confDB->{'meta-db'}->changeVendorOS($vendorOSIDs, $valRows);
}
-sub setSystemIDsOfVendorOS
-{
- my $confDB = shift;
- my $vendorOSID = shift;
- my $systemIDs = _aref(shift);
-
- my %seen;
- my @uniqueSystemIDs = grep { !$seen{$_}++ } @$systemIDs;
- return $confDB->{'meta-db'}->setSystemIDsOfVendorOS($vendorOSID,
- \@uniqueSystemIDs);
-}
-
-sub addSystemIDsToVendorOS
-{
- my $confDB = shift;
- my $vendorOSID = shift;
- my $newSystemIDs = _aref(shift);
-
- my @systemIDs
- = $confDB->{'meta-db'}->fetchSystemIDsOfVendorOS($vendorOSID);
- push @systemIDs, @$newSystemIDs;
- return setSystemIDsOfVendorOS($confDB, $vendorOSID, \@systemIDs);
-}
-
-sub removeSystemIDsFromVendorOS
-{
- my $confDB = shift;
- my $vendorOSID = shift;
- my $removedSystemIDs = _aref(shift);
-
- my %toBeRemoved;
- @toBeRemoved{@$removedSystemIDs} = ();
- my @systemIDs
- = grep { !exists $toBeRemoved{$_} }
- $confDB->{'meta-db'}->fetchSystemIDsOfVendorOS($vendorOSID);
- return setSystemIDsOfVendorOS($confDB, $vendorOSID, \@systemIDs);
-}
-
sub addSystem
{
my $confDB = shift;
@@ -466,6 +486,31 @@ sub removeGroupIDsFromSystem
return setGroupIDsOfSystem($confDB, $systemID, \@groupIDs);
}
+sub addSystemVariant
+{
+ my $confDB = shift;
+ my $valRows = _aref(shift);
+
+ return $confDB->{'meta-db'}->addSystemVariant($valRows);
+}
+
+sub removeSystemVariant
+{
+ my $confDB = shift;
+ my $systemVariantIDs = _aref(shift);
+
+ return $confDB->{'meta-db'}->removeSystemVariant($systemVariantIDs);
+}
+
+sub changeSystemVariant
+{
+ my $confDB = shift;
+ my $systemVariantIDs = _aref(shift);
+ my $valRows = _aref(shift);
+
+ return $confDB->{'meta-db'}->changeSystemVariant($systemVariantIDs, $valRows);
+}
+
sub addClient
{
my $confDB = shift;
@@ -664,4 +709,186 @@ sub removeSystemIDsFromGroup
return setSystemIDsOfGroup($confDB, $groupID, \@systemIDs);
}
+################################################################################
+### data aggregation interface
+################################################################################
+sub mergeDefaultAttributesIntoSystem
+{ # merge default system configuration into given system
+ my $confDB = shift;
+ my $system = shift;
+ my $defaultSystem = shift;
+
+ $defaultSystem = fetchSystemsByID($confDB, 0)
+ unless defined $defaultSystem;
+
+ mergeAttributes($system, $defaultSystem);
+}
+
+sub mergeDefaultAndGroupAttributesIntoClient
+{ # merge default and group configurations into given client
+ my $confDB = shift;
+ my $client = shift;
+
+ # step over all groups this client belongs to
+ # (ordered by priority from highest to lowest):
+ my @groupIDs = fetchGroupIDsOfClient($confDB, $client->{id});
+ my @groups = sort { $b->{priority} <=> $a->{priority} }
+ fetchGroupsByID($confDB, \@groupIDs);
+ foreach my $group (@groups) {
+ # merge configuration from this group into the current client:
+ vlog 3, _tr('merging from group %d:%s...', $group->{id}, $group->{name});
+ mergeAttributes($client, $group);
+ }
+
+ # merge configuration from default client:
+ vlog 3, _tr('merging from default client...');
+ my $defaultClient = fetchClientsByID($confDB, 0);
+ mergeAttributes($client, $defaultClient);
+}
+
+sub aggregatedSystemIDsOfClient
+{ # return aggregated list of system-IDs this client should offer
+ # (as indicated by itself, the default client and the client's groups)
+ my $confDB = shift;
+ my $client = shift;
+
+ # add all systems directly linked to client:
+ my @systemIDs = fetchSystemIDsOfClient($confDB, $client->{id});
+
+ # step over all groups this client belongs to:
+ my @groupIDs = fetchGroupIDsOfClient($confDB, $client->{id});
+ my @groups = fetchGroupsByID($confDB, \@groupIDs);
+ foreach my $group (@groups) {
+ # add all systems that the client inherits from the current group:
+ push @systemIDs, fetchSystemIDsOfGroup($confDB, $group->{id});
+ }
+
+ # add all systems inherited from default client
+ push @systemIDs, fetchSystemIDsOfClient($confDB, 0);
+
+ my %seenIDs;
+ return grep { !$seenIDs{$_}++; } @systemIDs;
+ # return unique list
+}
+
+sub aggregatedClientIDsOfSystem
+{ # return aggregated list of client-IDs this system is linked to
+ # (as indicated by itself, the default system and the system's groups)
+ my $confDB = shift;
+ my $system = shift;
+
+ # add all clients directly linked to system:
+ my @clientIDs = fetchClientIDsOfSystem($confDB, $system->{id});
+
+ # step over all groups this system belongs to:
+ my @groupIDs = fetchGroupIDsOfSystem($confDB, $system->{id});
+ my @groups = fetchGroupsByID($confDB, \@groupIDs);
+ foreach my $group (@groups) {
+ # add all clients that the system inherits from the current group:
+ push @clientIDs, fetchClientIDsOfGroup($confDB, $group->{id});
+ }
+
+ # add all clients inherited from default system
+ push @clientIDs, fetchClientIDsOfSystem($confDB, 0);
+
+ my %seenIDs;
+ return grep { !$seenIDs{$_}++; } @clientIDs;
+ # return unique list
+}
+
+sub aggregatedKernelFilesOfSystem
+{ # return aggregated list of kernel-files this system is using
+ # (as indicated by itself and system's variants)
+ my $confDB = shift;
+ my $system = shift;
+
+ my $vendorOS = fetchVendorOSesByID($confDB, $system->{vendor_os_id});
+ return () if !$vendorOS || !length($vendorOS->{path});
+ my $kernelPath
+ = "$openslxConfig{'private-basepath'}/stage1/$vendorOS->{path}";
+
+ my @variantIDs = fetchSystemVariantIDsOfSystem($confDB, $system->{id});
+ my @variants = fetchSystemVariantsByID($confDB, \@variantIDs);
+
+ my @kernelFiles = map { "$kernelPath/$_->{kernel}" }
+ grep { length($_->{kernel}) > 0 }
+ ($system, @variants);
+ return _unique(@kernelFiles);
+}
+
+sub aggregatedInitramSetupsOfSystem
+{ # return aggregated list of initialramfs-setups this system is using
+ # (as indicated by itself and system's variants)
+ my $confDB = shift;
+ my $system = shift;
+
+ my $vendorOS = fetchVendorOSesByID($confDB, $system->{vendor_os_id});
+ return () if !$vendorOS || !length($vendorOS->{path});
+ my $kernelPath
+ = "$openslxConfig{'private-basepath'}/stage1/$vendorOS->{path}";
+
+ my @variantIDs = fetchSystemVariantIDsOfSystem($confDB, $system->{id});
+ my @variants = fetchSystemVariantsByID($confDB, \@variantIDs);
+
+ my @initramFiles = map { "$kernelPath/$_->{initramfs}" }
+ grep { length($_->{initramfs}) > 0 }
+ ($system, @variants);
+ return _unique(@initramFiles);
+}
+
+################################################################################
+### support interface
+################################################################################
+sub isAttribute
+{ # returns whether or not the given key is an exportable attribute
+ my $key = shift;
+
+ return $key =~ m[^attr];
+}
+
+sub mergeAttributes
+{ # copies all attributes of source that are unset in target over
+ my $target = shift;
+ my $source = shift;
+
+ foreach my $key (grep { isAttribute($_) } keys %$source) {
+ if (length($source->{$key}) > 0 && length($target->{$key}) == 0) {
+ vlog 3, _tr("merging %s (val=%s)", $key, $source->{$key});
+ $target->{$key} = $source->{$key};
+ }
+ }
+}
+
+sub externalIDForSystem
+{
+ my $system = shift;
+
+ return "default" if $system->{id} == 0;
+
+ my $externalID = $system->{name};
+ $externalID =~ s[\s+][_]g;
+ # replace any whitespace in name, such that the external ID can
+ # be used as a directory name (without complications)
+ return $externalID;
+}
+
+
+sub externalIDForClient
+{
+ my $client = shift;
+
+ return "default" if $client->{id} == 0;
+
+ my $mac = lc($client->{mac});
+ # PXE seems to expect MACs being all lowercase
+ $mac =~ tr[:][-];
+ return "01-$mac";
+}
+
+sub externalAttrName
+{
+ my $attr = shift;
+ return substr($attr, 5);
+}
+
1;
diff --git a/config-db/config-demuxer.pl b/config-db/config-demuxer.pl
index f57a9fc1..7de6ffcd 100755
--- a/config-db/config-demuxer.pl
+++ b/config-db/config-demuxer.pl
@@ -8,32 +8,25 @@ use lib $FindBin::Bin;
use Fcntl qw(:DEFAULT :flock);
use Getopt::Long qw(:config pass_through);
use OpenSLX::Basics;
-use OpenSLX::ConfigDB;
+use OpenSLX::ConfigDB qw(:access :aggregation :support);
my $pxelinux0Path = "/usr/share/syslinux/pxelinux.0";
my $pxeConfigDefaultTemplate = q[NOESCAPE 0
PROMPT 0
TIMEOUT 100
-DEFAULT menu
+DEFAULT menu.c32
IMPLICIT 1
ALLOWOPTIONS 1
ONERROR menu
MENU TITLE What would you like to do? (use cursor to select)
MENU MASTER PASSWD secret
+LABEL menu
+
];
my (
$dryRun,
# dryRun won't touch any file
- $defaultSystem,
- # configuration specified by default system
- $defaultClient,
- # configuration specified by default client
- %systemConf,
- # system configurations - straight from DB
- %clientConf,
- # configurations for each client, folded info from client, groups
- # and default client
$systemConfCount,
# number of system configurations written
$clientSystemConfCount,
@@ -69,15 +62,13 @@ if (!$dryRun) {
die _tr("Unable to create or access export-path '%s'!", $exportPath);
}
if (!-e "$exportPath/pxe/pxelinux.0") {
- system("cp -a $pxelinux0Path $exportPath/pxe/pxelinux.0");
+ system(qq[cp -a "$pxelinux0Path" $exportPath/pxe/pxelinux.0]);
}
}
my $lockFile = "$exportPath/config-demuxer.lock";
lockScript($lockFile);
-fetchConfigurations();
-
writeConfigurations();
my $wr = ($dryRun ? "would have written" : "wrote");
@@ -85,7 +76,7 @@ print "$wr $systemConfCount systems and $clientSystemConfCount client-configurat
disconnectConfigDB($openslxDB);
-system("rm -rf $tempPath") unless $dryRun || length($tempPath) == 0;
+system("rm -rf $tempPath") unless $dryRun || length($tempPath) < 12;
unlockScript($lockFile);
@@ -122,26 +113,6 @@ sub unlockScript
unlink $lockFile;
}
-sub isAttribute
-{ # returns whether or not the given key is an exportable attribute
- my $key = shift;
-
- return $key =~ m[^attr];
-}
-
-sub mergeConfigAttributes
-{ # copies all attributes of source that are unset in target over
- my $target = shift;
- my $source = shift;
-
- foreach my $key (grep { isAttribute($_) } keys %$source) {
- if (length($source->{$key}) > 0 && length($target->{$key}) == 0) {
- vlog 3, _tr("\tmerging %s (val=%s)", $key, $source->{$key});
- $target->{$key} = $source->{$key};
- }
- }
-}
-
sub writeAttributesToFile
{
my $attrHash = shift;
@@ -153,17 +124,14 @@ sub writeAttributesToFile
my @attrs = sort grep { isAttribute($_) } keys %$attrHash;
foreach my $attr (@attrs) {
if (length($attrHash->{$attr}) > 0) {
- my $shellVar = $attr;
- # convert 'attrExampleName' to 'example_name':
- $shellVar =~ s[([A-Z])]['_'.lc($1)]ge;
- $shellVar = substr($shellVar, 5);
- print ATTRS "$shellVar = $attrHash->{$attr}\n";
+ my $externalAttrName = externalAttrName($attr);
+ print ATTRS "$externalAttrName = $attrHash->{$attr}\n";
}
}
close(ATTRS);
}
-sub copySystemConfig
+sub copyExternalSystemConfig
{ # copies local configuration extensions of given system from private
# config folder (var/lib/openslx/config/...) into a temporary folder
my $systemName = shift;
@@ -171,6 +139,9 @@ sub copySystemConfig
return if $dryRun;
+ if ($targetPath !~ m[$tempPath]) {
+ die _tr("system-error: illegal target-path <%s>!", $targetPath);
+ }
system("rm -rf $targetPath");
mkdir $targetPath;
@@ -203,16 +174,6 @@ sub createTarOfPath
}
}
-sub externalClientIDFor
-{
- my $client = shift;
-
- my $mac = lc($client->{mac});
- # PXE seems to expect MACs being all lowercase
- $mac =~ tr[:][-];
- return "01-$mac";
-}
-
################################################################################
###
################################################################################
@@ -220,21 +181,41 @@ sub writePXEMenus
{
my $pxePath = "$exportPath/pxe/pxelinux.cfg";
- foreach my $client (values %clientConf) {
- my $externalClientID = externalClientIDFor($client);
+ my @clients = fetchClientsByFilter($openslxDB);
+ foreach my $client (@clients) {
+ my $externalClientID = externalIDForClient($client);
my $pxeFile = "$pxePath/$externalClientID";
- vlog 1, _tr("writing PXE-file $pxeFile");
+ vlog 1, _tr("writing PXE-file %s", $pxeFile);
open(PXE, "> $pxeFile") or die "unable to write to $pxeFile";
print PXE $pxeConfigDefaultTemplate;
- foreach my $system (values %{$client->{systems}}) {
+ my @systemIDs = aggregatedSystemIDsOfClient($openslxDB, $client);
+ my @systems = fetchSystemsByID($openslxDB, \@systemIDs);
+ foreach my $system (@systems) {
print PXE "LABEL openslx-$system->{name}\n";
- print PXE "\tMENU DEFAULT\n";
- print PXE "\tMENU LABEL ^$system->{label}\n";
- print PXE "\tKERNEL $system->{kernel}\n";
- print PXE "\tAPPEND $system->{kernel_params}\n";
- print PXE "\tIPAPPEND 1\n";
+ print PXE " MENU DEFAULT\n";
+ print PXE " MENU LABEL ^$system->{label}\n";
+ print PXE " KERNEL $system->{kernel}\n";
+ print PXE " append $system->{kernel_params}\n";
+ print PXE " ipappend 1\n";
}
close(PXE);
+ }
+}
+
+sub writeSystemPXEFiles
+{
+ my $system = shift;
+
+ my $pxePath = "$exportPath/pxe/pxelinux.cfg";
+
+ my @kernelFiles = aggregatedKernelFilesOfSystem($openslxDB, $system);
+ foreach my $kernelFile (@kernelFiles) {
+ vlog 1, _tr('copying kernel %s to %s/', $kernelFile, $pxePath);
+ system(qq[cp -a "$kernelFile" $pxePath/]) unless $dryRun;
+ }
+ foreach my $initramFile (aggregatedInitramFilesOfSystem($openslxDB, $system)) {
+ vlog 1, _tr('copying initramfs %s to %s/', $initramFile, $pxePath);
+ system(qq[cp -a "$initramFile" $pxePath/]) unless $dryRun;
}
}
@@ -244,37 +225,48 @@ sub writeClientConfigurationsForSystem
my $buildPath = shift;
my $attrFile = shift;
- foreach my $client (values %{$system->{clients}}) {
+ 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++;
- # copy this client's configuration in order to
- # merge system configuration into client config and write the
- # resulting attributes to a configuration file:
- my $clientSystemConf = { %$client };
- mergeConfigAttributes($clientSystemConf, $system);
- writeAttributesToFile($clientSystemConf, $attrFile);
+ # 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);
- my $externalClientID = externalClientIDFor($client);
+ # create tar containing external system configuration
+ # and client attribute file:
+ my $externalClientID = externalIDForClient($client);
+ my $externalSystemID = externalIDForSystem($system);
createTarOfPath($buildPath, "${externalClientID}.tgz",
- "$exportPath/client-conf/$system->{name}");
+ "$exportPath/client-conf/$externalSystemID");
}
}
sub writeSystemConfigurations
{
- foreach my $system (values %systemConf) {
+ 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";
- copySystemConfig($system->{name}, $buildPath);
+ copyExternalSystemConfig($system->{name}, $buildPath);
my $attrFile = "$buildPath/initramfs/machine-setup";
+ mergeDefaultAttributesIntoSystem($openslxDB, $system);
writeAttributesToFile($system, $attrFile);
- createTarOfPath($buildPath, "default.tgz",
- "$exportPath/client-conf/$system->{name}");
+ my $externalSystemID = externalIDForSystem($system);
+ my $systemPath = "$exportPath/client-conf/$externalSystemID";
+ createTarOfPath($buildPath, "default.tgz", $systemPath);
+
+ writeSystemPXEFiles($system);
writeClientConfigurationsForSystem($system, $buildPath, $attrFile);
@@ -282,102 +274,6 @@ sub writeSystemConfigurations
}
}
-sub linkClientToSystems
-{
- my ($client, @systemIDs) = @_;
-
- my $clientID = $client->{id};
- $client->{systems} = {} unless exists $client->{systems};
- foreach my $sysID (@systemIDs) {
- my $sysConf = $systemConf{$sysID};
- next if !defined $sysConf || $sysConf->{unbootable};
-
- # refer from system to client:
- $sysConf->{clients} = {} unless exists $sysConf->{clients};
- if (!exists $sysConf->{clients}->{$clientID}) {
- vlog 2, _tr('linking client %d:%s to system %d:%s',
- $clientID, $client->{name},
- $sysID, $sysConf->{name});
- $sysConf->{clients}->{$clientID} = $client;
- }
-
- # refer from client to system:
- if (!exists $client->{systems}->{$sysID}) {
- $client->{systems}->{$sysID} = $systemConf{$sysID};
- }
- }
-}
-
-sub fetchSystemConfigurations
-{
- $defaultSystem = fetchSystemsByID($openslxDB, 0);
-
- foreach my $s (fetchSystemsByFilter($openslxDB)) {
- next unless $s->{id} > 0;
- vlog 2, _tr('read system %d:%s...', $s->{id}, $s->{name});
-
- # replace any whitespace in name, as we will use it as a
- # directory name later:
- $s->{name} =~ s[\s+][_]g;
-
- # merge default system configuration into this system and store
- # that into hash:
- mergeConfigAttributes($s, $defaultSystem);
- $systemConf{$s->{id}} = $s;
- }
-}
-
-sub fetchClientConfigurations
-{
- my %groups;
- foreach my $g (fetchGroupsByFilter($openslxDB)) {
- vlog 2, _tr('read group %d:%s...', $g->{id}, $g->{name});
- $groups{$g->{id}} = $g;
- }
-
- $defaultClient = fetchClientsByID($openslxDB, 0);
-
- foreach my $client (fetchClientsByFilter($openslxDB)) {
- next unless $client->{id} > 0;
- vlog 2, _tr('read client %d:%s...', $client->{id}, $client->{name});
-
- # add all systems directly linked to client:
- linkClientToSystems($client,
- fetchSystemIDsOfClient($openslxDB, $client->{id}));
-
- # now fetch and step over all groups this client belongs to
- # (ordered by priority from highest to lowest):
- my @clientGroups
- = sort { $b->{priority} <=> $a->{priority} }
- map { $groups{$_} }
- grep { exists $groups{$_} }
- # just to be safe: filter out unknown group-IDs
- fetchGroupIDsOfClient($openslxDB, $client->{id});
- foreach my $group (@clientGroups) {
- # fetch and add all systems that the client inherits from
- # the current group:
- linkClientToSystems($client,
- fetchSystemIDsOfGroup($openslxDB, $group->{id}));
-
- # merge configuration from this group into the current client:
- vlog 3, _tr('merging from group %d:%s...', $group->{id}, $group->{name});
- mergeConfigAttributes($client, $group);
- }
-
- # merge configuration from default client and store client
- # configuration into hash:
- vlog 3, _tr('merging from default client...');
- mergeConfigAttributes($client, $defaultClient);
- $clientConf{$client->{id}} = $client;
- }
-}
-
-sub fetchConfigurations
-{
- fetchSystemConfigurations();
- fetchClientConfigurations();
-}
-
sub writeConfigurations
{
$systemConfCount = $clientSystemConfCount = 0;