summaryrefslogtreecommitdiffstats
path: root/installer/OpenSLX/OSExport
diff options
context:
space:
mode:
authorOliver Tappe2007-03-12 19:22:58 +0100
committerOliver Tappe2007-03-12 19:22:58 +0100
commit58a64fc6a61e1c42bb93e507b03ce675afda3f66 (patch)
treee0c9f7b710ffffffd6d5bd58dcf8e329a380c97f /installer/OpenSLX/OSExport
parent* now uses OpenSLX::Utils (diff)
downloadcore-58a64fc6a61e1c42bb93e507b03ce675afda3f66.tar.gz
core-58a64fc6a61e1c42bb93e507b03ce675afda3f66.tar.xz
core-58a64fc6a61e1c42bb93e507b03ce675afda3f66.zip
* added slxos-export script and the corresponding engine and exporter implementation for NFS.
git-svn-id: http://svn.openslx.org/svn/openslx/trunk@760 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'installer/OpenSLX/OSExport')
-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
3 files changed, 340 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;