summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--installer/OpenSLX/OSExport/Engine.pm174
-rw-r--r--installer/OpenSLX/OSExport/ExportType/Base.pm83
-rw-r--r--installer/OpenSLX/OSExport/ExportType/NFS.pm83
-rwxr-xr-xinstaller/slxos-export141
4 files changed, 481 insertions, 0 deletions
diff --git a/installer/OpenSLX/OSExport/Engine.pm b/installer/OpenSLX/OSExport/Engine.pm
new file mode 100644
index 00000000..ed7a2900
--- /dev/null
+++ b/installer/OpenSLX/OSExport/Engine.pm
@@ -0,0 +1,174 @@
+# Engine.pm - provides driver engine for the OSExport API.
+#
+# (c) 2006 - OpenSLX.com
+#
+# Oliver Tappe <ot@openslx.com>
+#
+package OpenSLX::OSExport::Engine;
+
+use vars qw(@ISA @EXPORT $VERSION);
+$VERSION = 1.01; # API-version . implementation-version
+
+use Exporter;
+@ISA = qw(Exporter);
+
+@EXPORT = qw(
+ %supportedExportTypes
+);
+
+use strict;
+use Carp;
+use File::Basename;
+use OpenSLX::Basics;
+
+use vars qw(%supportedExportTypes);
+
+%supportedExportTypes = (
+ 'nfs'
+ => { module => 'NFS' },
+ 'nbd'
+ => { module => 'NBD' },
+ 'nbd-squashfs'
+ => { module => 'NBD_Squash' },
+);
+
+################################################################################
+### interface methods
+################################################################################
+sub new
+{
+ my $class = shift;
+
+ my $self = {
+ };
+
+ return bless $self, $class;
+}
+
+sub initialize
+{
+ my $self = shift;
+ my $vendorOSName = shift;
+ my $exportType = shift;
+
+ if (!exists $supportedExportTypes{lc($exportType)}) {
+ print _tr("Sorry, export type '%s' is unsupported.\n", $exportType);
+ print _tr("List of supported export types:\n\t");
+ print join("\n\t", sort keys %supportedExportTypes)."\n";
+ exit 1;
+ }
+
+ $self->{'vendor-os-name'} = $vendorOSName;
+ $vendorOSName =~ m[^(.+?\-[^-]+)];
+ my $distroName = $1;
+ $self->{'distro-name'} = $distroName;
+
+ # load module for the requested export type:
+ my $exportTypeModule
+ = "OpenSLX::OSExport::ExportType::"
+ .$supportedExportTypes{lc($exportType)}->{module};
+ unless (eval "require $exportTypeModule") {
+ if ($! == 2) {
+ die _tr("Export-type-module <%s> not found!\n", $exportTypeModule);
+ } else {
+ die _tr("Unable to load export-type-module <%s> (%s)\n", $exportTypeModule, $@);
+ }
+ }
+ my $modVersion = $exportTypeModule->VERSION;
+ if ($modVersion < 1.01) {
+ die _tr('Could not load module <%s> (Version <%s> required, but <%s> found)',
+ $exportTypeModule, 1.01, $modVersion);
+ }
+ $exportTypeModule->import;
+ my $exporter = $exportTypeModule->new;
+ $exporter->initialize($self);
+ $self->{'exporter'} = $exporter;
+
+ # setup source and target paths:
+ $self->{'vendor-os-path'}
+ = "$openslxConfig{'stage1-path'}/$vendorOSName";
+ $self->{'export-path'}
+ = "$openslxConfig{'export-path'}/$exportType/$vendorOSName";
+ vlog 1, _tr("vendor-OS from '%s' will be exported to '%s'",
+ $self->{'vendor-os-path'}, $self->{'export-path'});
+}
+
+sub exportVendorOS
+{
+ my $self = shift;
+
+ $self->{'exporter'}->exportVendorOS(
+ $self->{'vendor-os-path'},
+ $self->{'export-path'}
+ );
+ $self->addExportToConfigDB();
+}
+
+################################################################################
+### implementation methods
+################################################################################
+sub addExportToConfigDB
+{
+ my $self = shift;
+
+ my $configDBModule = "OpenSLX::ConfigDB";
+ unless (eval "require $configDBModule") {
+ if ($! == 2) {
+ vlog 1, _tr("ConfigDB-module not found, unable to access OpenSLX-database.\n");
+ } else {
+ die _tr("Unable to load ConfigDB-module <%s> (%s)\n", $configDBModule, $@);
+ }
+ } else {
+ my $modVersion = $configDBModule->VERSION;
+ if ($modVersion < 1.01) {
+ die _tr('Could not load module <%s> (Version <%s> required, but <%s> found)',
+ $configDBModule, 1.01, $modVersion);
+ }
+ $configDBModule->import(qw(:access :manipulation));
+ my $openslxDB = connectConfigDB();
+ # insert new export if it doesn't already exist in DB:
+ my $exportName = $self->{'vendor-os-name'};
+ my $export = fetchExportsByFilter(
+ $openslxDB, { 'name' => $exportName }, 'id'
+ );
+ if (defined $export) {
+ changeExport(
+ $openslxDB,
+ {
+ 'name' => $exportName,
+ 'path' => $self->{'vendor-os-name'},
+ }
+ );
+ vlog 0, _tr("Export <%s> has been updated in DB.\n", $exportName);
+ } else {
+ my $id = addExport(
+ $openslxDB,
+ {
+ 'name' => $exportName,
+ 'path' => $self->{'vendor-os-name'},
+ }
+ );
+ vlog 0, _tr("Export <%s> has been added to DB (ID=%s).\n",
+ $exportName, $id);
+ }
+
+ disconnectConfigDB($openslxDB);
+ }
+}
+
+1;
+################################################################################
+
+=pod
+
+=head1 NAME
+
+OpenSLX::OSExport::Engine -
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+...
+
+=cut
diff --git a/installer/OpenSLX/OSExport/ExportType/Base.pm b/installer/OpenSLX/OSExport/ExportType/Base.pm
new file mode 100644
index 00000000..c65f39e0
--- /dev/null
+++ b/installer/OpenSLX/OSExport/ExportType/Base.pm
@@ -0,0 +1,83 @@
+# Base.pm - provides empty base of the OpenSLX OSExport::ExportType API.
+#
+# (c) 2006 - OpenSLX.com
+#
+# Oliver Tappe <ot@openslx.com>
+#
+package OpenSLX::OSExport::ExportType::Base;
+
+use vars qw($VERSION);
+$VERSION = 1.01; # API-version . implementation-version
+
+use strict;
+use Carp;
+
+################################################################################
+### interface methods
+################################################################################
+sub new
+{
+ confess "Creating OpenSLX::OSExport::ExportType::Base-objects directly makes no sense!";
+}
+
+sub initialize
+{
+ my $self = shift;
+ my $engine = shift;
+
+ $self->{'engine'} = $engine;
+
+ # read filter information:
+ my (@includeList, @excludeList);
+ my $distroName = $engine->{'distro-name'};
+ my $filterFile = "../lib/distro-info/$distroName/export-filter";
+ if (open(FILTER, "< $filterFile")) {
+ while(<FILTER>) {
+ chomp;
+ push @includeList, "$_" if /^\+\s+/;
+ push @excludeList, "$_" if /^\-\s+/;
+ }
+ close(FILTER);
+ }
+ $self->{'exclude-list'} = \@excludeList;
+ $self->{'include-list'} = \@includeList;
+}
+
+sub exportVendorOS
+{
+}
+
+1;
+################################################################################
+
+=pod
+
+=head1 NAME
+
+OpenSLX::OSExport::ExportType::Base - the base class for all OSExport::ExportTypes
+
+=head1 SYNOPSIS
+
+ package OpenSLX::OSExport::ExportType::coolnewexporter;
+
+ use vars qw(@ISA $VERSION);
+ @ISA = ('OpenSLX::OSExport::ExportType::Base');
+ $VERSION = 1.01;
+
+ use coolnewexporter;
+
+ sub new
+ {
+ my $class = shift;
+ my $self = {};
+ return bless $self, $class;
+ }
+
+ # override all methods of OpenSLX::OSExport::ExportType::Base in order to
+ # implement the support for a new export-type
+ ...
+
+I<The synopsis above outlines a class that implements a
+OSExport::ExportType for the (imaginary) export-type B<coolnewexporter>>
+
+=cut
diff --git a/installer/OpenSLX/OSExport/ExportType/NFS.pm b/installer/OpenSLX/OSExport/ExportType/NFS.pm
new file mode 100644
index 00000000..8bb8f7e5
--- /dev/null
+++ b/installer/OpenSLX/OSExport/ExportType/NFS.pm
@@ -0,0 +1,83 @@
+# NFS.pm
+# - provides NFS-specific overrides of the OpenSLX::OSExport::ExportType API.
+#
+# (c) 2006 - OpenSLX.com
+#
+# Oliver Tappe <ot@openslx.com>
+#
+package OpenSLX::OSExport::ExportType::NFS;
+
+use vars qw(@ISA $VERSION);
+@ISA = ('OpenSLX::OSExport::ExportType::Base');
+$VERSION = 1.01; # API-version . implementation-version
+
+use strict;
+use Carp;
+use File::Basename;
+use OpenSLX::Basics;
+use OpenSLX::Utils;
+use OpenSLX::OSExport::ExportType::Base 1.01;
+
+################################################################################
+### interface methods
+################################################################################
+sub new
+{
+ my $class = shift;
+ my $self = {
+ 'name' => 'NFS',
+ };
+ return bless $self, $class;
+}
+
+sub initialize
+{
+ my $self = shift;
+ my $engine = shift;
+
+ $self->SUPER::initialize($engine);
+}
+
+sub exportVendorOS
+{
+ my $self = shift;
+ my $source = shift;
+ my $target = shift;
+
+ $self->exportViaRsync($source, $target);
+ $self->addTargetToNfsExports($target);
+}
+
+################################################################################
+### implementation methods
+################################################################################
+
+sub exportViaRsync
+{
+ my $self = shift;
+ my $source = shift;
+ my $target = shift;
+
+ my $excludeIncludeList
+ = join("\n", @{$self->{'include-list'}}, @{$self->{'exclude-list'}});
+ vlog 1, "using exclude-include-filter:\n$excludeIncludeList\n";
+ open(RSYNC, "| rsync -av --delete --exclude-from=- $source/ $target")
+ or die _tr("unable to start rsync for source '%s', giving up! (%s)",
+ $source, $!);
+ print RSYNC $excludeIncludeList;
+ if (!close(RSYNC)) {
+ die _tr("unable to export to target '%s', giving up! (%s)",
+ $target, $!);
+ }
+}
+
+sub addTargetToNfsExports
+{
+ my $self = shift;
+ my $target = shift;
+
+ my $exports = slurpFile("/etc/exports");
+print "$exports\n";
+}
+
+1;
diff --git a/installer/slxos-export b/installer/slxos-export
new file mode 100755
index 00000000..9b179e53
--- /dev/null
+++ b/installer/slxos-export
@@ -0,0 +1,141 @@
+#! /usr/bin/perl
+#
+# slxos-export
+#
+# (c) 2006 - OpenSLX.com
+#
+# Oliver Tappe <ot@openslx.com>
+#
+use strict;
+
+my $abstract = q[
+slxos-export
+ This script exports an OpenSLX-stage1-system (a.k.a. vendor-OS) into
+ an OpenSLX-stage2-system (a.k.a. export), which can be an NFS-export,
+ an NBD-image containing a squash-fs.
+];
+
+use Getopt::Long qw(:config pass_through);
+use Pod::Usage;
+
+# add the folder this script lives in and the lib-folder to perl's
+# search path for modules:
+use FindBin;
+use lib "$FindBin::RealBin";
+use lib "$FindBin::RealBin/../lib";
+
+use lib "$FindBin::RealBin/../config-db";
+ # development path to config-db
+
+use OpenSLX::Basics;
+use OpenSLX::OSExport::Engine;
+
+my (
+ $helpReq,
+ $manReq,
+ $listReq,
+ $verbose,
+ $versionReq,
+);
+
+GetOptions(
+ 'help|?' => \$helpReq,
+ 'list' => \$listReq,
+ 'man' => \$manReq,
+ 'verbose' => \$verbose,
+ '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();
+
+if ($listReq) {
+ print _tr("List of supported export types:\n\t");
+ print join("\n\t", keys %supportedExportTypes)."\n";
+ exit 1;
+}
+
+if (scalar(@ARGV) != 2) {
+ print STDERR _tr("You need to specify exactly one vendor-os-name and one export-type!\n");
+ pod2usage(2);
+}
+my $vendorOSName = $ARGV[0];
+my $exportType = $ARGV[1];
+
+# 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 ossetup-engine for given distro and start it:
+my $engine = OpenSLX::OSExport::Engine->new;
+$engine->initialize($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();
+
+__END__
+
+=head1 NAME
+
+slxos-export - OpenSLX-script to export a stage1-system (a.k.a. vendor-OS) into
+a stage2-system (a.k.a. export).
+The export itself can be done via several different types, e.g. via NFS or
+via a squashfs inside of a network block device.
+
+=head1 SYNOPSIS
+
+slxos-export [options] <vendor-os-name> <export-type>
+
+ Options:
+ --help brief help message
+ --list show available export-types
+ --man show full documentation
+ --version show version
+
+=head1 OPTIONS
+
+=over 8
+
+=item B<--help>
+
+Prints a brief help message and exits.
+
+=item B<--man>
+
+Prints the manual page and exits.
+
+=item B<--selection=<string>>
+
+Many distributions offer several different package selections for
+installation. With this option you can specify which of these you
+would like to use.
+
+If you pass an unknown selection, you will see a list of the selections
+that are available.
+
+In clone-mode, the selection specifies the name by which the cloned system
+will be known (exact name will be '<distro>-<selection>' instead of
+'<distro>-cloned-from-<rsync-source>').
+
+=item B<--source=<string>>
+
+When cloning a vendor-OS, slxos-export needs to know where to fetch
+the existing OS-files from. You can specify the rsync-uri with this
+option.
+
+=item B<--version>
+
+Prints the version and exits.
+
+=back
+
+=cut \ No newline at end of file