From 0da021ecc1344f0b01052c958c89b504b9406e50 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Mon, 23 Apr 2007 18:35:11 +0000 Subject: * changed semantics of slxos-export (back) to add/update/remove in order to seperate the creation of new exports from the updating of existing ones. This has become necessary with the new naming scheme. * introduced new naming scheme that names exports like the vendor-OS, but adds one letter to it to differentiate several exports of the same vendor-OS and type. git-svn-id: http://svn.openslx.org/svn/openslx/trunk@922 95ad53e4-c205-0410-b2fa-d234c58c8868 --- installer/OpenSLX/OSExport/Engine.pm | 183 +++++++++++++++++++++-------------- installer/slxos-export | 44 +++++++-- 2 files changed, 147 insertions(+), 80 deletions(-) (limited to 'installer') diff --git a/installer/OpenSLX/OSExport/Engine.pm b/installer/OpenSLX/OSExport/Engine.pm index 6c00e3fc..e656c755 100644 --- a/installer/OpenSLX/OSExport/Engine.pm +++ b/installer/OpenSLX/OSExport/Engine.pm @@ -67,10 +67,106 @@ sub new return bless $self, $class; } -sub initialize +sub initializeFromExisting +{ + my $self = shift; + my $exportName = shift; + + my $openslxDB = instantiateClass("OpenSLX::ConfigDB"); + $openslxDB->connect(); + + my $export + = $openslxDB->fetchExportByFilter({'name' => $exportName}); + if (!defined $export) { + die _tr("Export '%s' not found in DB, giving up!", $exportName); + } + my $vendorOS + = $openslxDB->fetchVendorOSByFilter({ 'id' => $export->{vendor_os_id} }); + + $openslxDB->disconnect(); + + $self->_initialize($vendorOS->{name}, $vendorOS->{id}, + $export->{name}, $export->{type}); +} + +sub initializeForNew +{ + my $self = shift; + my $vendorOSName = shift; + my $exportType = lc(shift); + + my $openslxDB = instantiateClass("OpenSLX::ConfigDB"); + $openslxDB->connect(); + + my $vendorOS + = $openslxDB->fetchVendorOSByFilter({ 'name' => $vendorOSName }); + if (!defined $vendorOS) { + die _tr("vendor-OS '%s' not found in DB, giving up!", $vendorOSName); + } + + my $exportCounter + = $openslxDB->getNextExportCounterForVendorOS($vendorOS->{id}); + my $exportName = sprintf "$vendorOSName-%c", 64+$exportCounter; + + $openslxDB->disconnect(); + + $self->_initialize($vendorOS->{name}, $vendorOS->{id}, + $exportName, $exportType); +} + +sub exportVendorOS +{ + my $self = shift; + + if (!$self->{'exporter'}->checkRequirements($self->{'vendor-os-path'})) { + die _tr("clients wouldn't be able to access the exported root-fs!\nplease install the missing module(s) or use another export-type."); + } + + $self->{'exporter'}->exportVendorOS( + $self->{'vendor-os-path'}, + $self->{'export-path'} + ); + vlog 0, _tr("vendor-OS '%s' successfully exported to '%s'!", + $self->{'vendor-os-path'}, $self->{'export-path'}); + $self->addExportToConfigDB(); +} + +sub updateExportedVendorOS +{ + my $self = shift; + my $exportName = shift; + + if (!$self->{'exporter'}->checkRequirements($self->{'vendor-os-path'})) { + die _tr("clients wouldn't be able to access the exported root-fs!\nplease install the missing module(s) or use another export-type."); + } + + $self->{'exporter'}->exportVendorOS( + $self->{'vendor-os-path'}, + $self->{'export-path'} + ); + vlog 0, _tr("export '%s' successfully updated!", $self->{'export-path'}); +} + +sub purgeExport +{ + my $self = shift; + + if ($self->{'exporter'}->purgeExport($self->{'export-path'})) { + vlog 0, _tr("export '%s' successfully removed!", + $self->{'export-path'}); + } + $self->removeExportFromConfigDB(); +} + +################################################################################ +### implementation methods +################################################################################ +sub _initialize { my $self = shift; my $vendorOSName = shift; + my $vendorOSId = shift; + my $exportName = shift; my $exportType = lc(shift); if (!exists $supportedExportTypes{lc($exportType)}) { @@ -81,6 +177,8 @@ sub initialize } $self->{'vendor-os-name'} = $vendorOSName; + $self->{'vendor-os-id'} = $vendorOSId; + $self->{'export-name'} = $exportName; $self->{'export-type'} = $exportType; $vendorOSName =~ m[^(.+?\-[^-]+)]; my $distroName = $1; @@ -116,42 +214,11 @@ sub initialize $self->{'vendor-os-path'} = "$openslxConfig{'stage1-path'}/$vendorOSName"; $self->{'export-path'} - = "$openslxConfig{'export-path'}/$exportType/$vendorOSName"; + = "$openslxConfig{'export-path'}/$exportType/$exportName"; vlog 1, _tr("vendor-OS from '%s' will be exported to '%s'", $self->{'vendor-os-path'}, $self->{'export-path'}); } -sub exportVendorOS -{ - my $self = shift; - - if (!$self->{'exporter'}->checkRequirements($self->{'vendor-os-path'})) { - die _tr("clients wouldn't be able to access the exported root-fs!\nplease install the missing module(s) or use another export-type."); - } - - $self->{'exporter'}->exportVendorOS( - $self->{'vendor-os-path'}, - $self->{'export-path'} - ); - vlog 0, _tr("vendor-OS '%s' successfully exported to '%s'!", - $self->{'vendor-os-path'}, $self->{'export-path'}); - $self->addExportToConfigDB(); -} - -sub purgeExport -{ - my $self = shift; - - if ($self->{'exporter'}->purgeExport($self->{'export-path'})) { - vlog 0, _tr("export '%s' successfully removed!", - $self->{'export-path'}); - } - $self->removeExportFromConfigDB(); -} - -################################################################################ -### implementation methods -################################################################################ sub addExportToConfigDB { my $self = shift; @@ -159,43 +226,17 @@ sub addExportToConfigDB my $openslxDB = instantiateClass("OpenSLX::ConfigDB"); $openslxDB->connect(); - my $exportName = $self->{'vendor-os-name'}; - my $export - = $openslxDB->fetchExportByFilter({ 'name' => $exportName }); - if (defined $export && $export->{type} ne $self->{'export-type'}) { - # export with default name already exists (with different type), - # so we try appending the type to generate a unique name: - $exportName = "$self->{'vendor-os-name'}-$self->{'export-type'}"; - $export - = $openslxDB->fetchExportByFilter({ - 'name' => $exportName, - 'type' => $self->{'export-type'}, - }); - } - # insert new export if it doesn't already exist in DB: - if (defined $export) { - vlog 0, _tr("No need to change export '%s' in OpenSLX-database.\n", - $exportName); - } else { - my $vendorOSName = $self->{'vendor-os-name'}; - my $vendorOS - = $openslxDB->fetchVendorOSByFilter({'name' => $vendorOSName}); - if (!defined $vendorOS) { - die _tr("vendor-OS '%s' could not be found in OpenSLX-database, giving up!\n", - $vendorOSName); + my $id = $openslxDB->addExport( + { + 'vendor_os_id' => $self->{'vendor-os-id'}, + 'name' => $self->{'export-name'}, + 'type' => $self->{'export-type'}, } - my $id = $openslxDB->addExport( - { - 'vendor_os_id' => $vendorOS->{id}, - 'name' => $exportName, - 'type' => $self->{'export-type'}, - } - ); - vlog 0, _tr("Export '%s' has been added to DB (ID=%s)...\n", - $exportName, $id); - # now create a default system for that export, using the standard kernel: - system("slxconfig add-system $exportName"); - } + ); + vlog 0, _tr("Export '%s' has been added to DB (ID=%s)...\n", + $self->{'export-name'}, $id); + # now create a default system for that export, using the standard kernel: + system("slxconfig add-system $self->{'export-name'}"); $openslxDB->disconnect(); } @@ -208,14 +249,14 @@ sub removeExportFromConfigDB $openslxDB->connect(); # remove export from DB: - my $exportName = $self->{'vendor-os-name'}; + my $exportName = $self->{'export-name'}; my $export = $openslxDB->fetchExportByFilter({ 'name' => $exportName, 'type' => $self->{'export-type'}, }); if (!defined $export) { - vlog 0, _tr("Export '%s' didn't exist in OpenSLX-database.\n", + vlog 0, _tr("Export '%s' doesn't exist in OpenSLX-database.\n", $exportName); } else { $openslxDB->removeExport($export->{id}); diff --git a/installer/slxos-export b/installer/slxos-export index 7890166e..81e8157d 100755 --- a/installer/slxos-export +++ b/installer/slxos-export @@ -99,19 +99,38 @@ if ($action =~ m[^list-ex]i) { # create OSExport-engine for given export type and start it: my $engine = OpenSLX::OSExport::Engine->new; - $engine->initialize($vendorOSName, $exportType); + $engine->initializeForNew($vendorOSName, $exportType); if (!-e $engine->{'vendor-os-path'}) { die _tr("vendor-OS '%s' doesn't exist, giving up!\n", $engine->{'vendor-os-path'}); } $engine->exportVendorOS(); +} elsif ($action =~ m[^(update)]i) { + if (scalar(@ARGV) != 1) { + print STDERR _tr("You need to specify exactly one export-name!\n"); + pod2usage(2); + } + my $exportName = shift @ARGV; + + # we chdir into the script's folder such that all relative paths have + # a known starting point: + chdir($FindBin::RealBin) + or die _tr("can't chdir to script-path <%> (%s)", $FindBin::RealBin, $!); + + # create OSExport-engine for given export type and start it: + my $engine = OpenSLX::OSExport::Engine->new; + $engine->initializeFromExisting($exportName); + if (!-e $engine->{'vendor-os-path'}) { + die _tr("vendor-OS '%s' doesn't exist, giving up!\n", + $engine->{'vendor-os-path'}); + } + $engine->updateExportedVendorOS(); } elsif ($action =~ m[^remove]i) { - if (scalar(@ARGV) != 2) { + if (scalar(@ARGV) != 1) { print STDERR _tr("You need to specify exactly one export-name and one export-type!\n"); pod2usage(2); } my $exportName = shift @ARGV; - my $exportType = shift @ARGV; # we chdir into the script's folder such that all relative paths have # a known starting point: @@ -120,7 +139,7 @@ if ($action =~ m[^list-ex]i) { # create OSExport-engine for given export type and start it: my $engine = OpenSLX::OSExport::Engine->new; - $engine->initialize($exportName, $exportType); + $engine->initializeFromExisting($exportName); $engine->purgeExport(); } else { print STDERR _tr("You need to specify exactly one action: @@ -128,6 +147,7 @@ if ($action =~ m[^list-ex]i) { list-exported list-installed list-types + update remove Try '%s --help' for more info.\n", $0); } @@ -153,10 +173,12 @@ slxos-export [options] =over 8 -=item B<< export >> +=item B<< add >> exports the vendor-OS with the given name using the given export type and -adds it to the config-DB, too +adds it to the config-DB, too. The export will be named as the vendor-OS, +but with an additional '-' appended to it (where will be replaced +by the letter A,B,C ...). =item B<< list-exported >> @@ -170,10 +192,14 @@ list all installed vendor-OSes list all supported export types -=item B<< remove >> +=item B<< update >> + +updates the export with the given name, i.e. the contents of the vendor-OS +is synced to the export + +=item B<< remove >> -removes the export with the given name and export type from disk and -config-DB +removes the export with the given name from disk and config-DB =back -- cgit v1.2.3-55-g7522