summaryrefslogtreecommitdiffstats
path: root/installer/OpenSLX/OSExport
diff options
context:
space:
mode:
Diffstat (limited to 'installer/OpenSLX/OSExport')
-rw-r--r--installer/OpenSLX/OSExport/BlockDevice/AoE.pm98
-rw-r--r--installer/OpenSLX/OSExport/BlockDevice/Base.pm62
-rw-r--r--installer/OpenSLX/OSExport/BlockDevice/NBD.pm91
-rw-r--r--installer/OpenSLX/OSExport/Engine.pm242
-rw-r--r--installer/OpenSLX/OSExport/ExportType/Base.pm128
-rw-r--r--installer/OpenSLX/OSExport/FileSystem/Base.pm81
-rw-r--r--installer/OpenSLX/OSExport/FileSystem/NFS.pm (renamed from installer/OpenSLX/OSExport/ExportType/NFS.pm)53
-rw-r--r--installer/OpenSLX/OSExport/FileSystem/SquashFS.pm (renamed from installer/OpenSLX/OSExport/ExportType/NBD_Squash.pm)159
8 files changed, 624 insertions, 290 deletions
diff --git a/installer/OpenSLX/OSExport/BlockDevice/AoE.pm b/installer/OpenSLX/OSExport/BlockDevice/AoE.pm
new file mode 100644
index 00000000..c8aad4ec
--- /dev/null
+++ b/installer/OpenSLX/OSExport/BlockDevice/AoE.pm
@@ -0,0 +1,98 @@
+# Copyright (c) 2006, 2007 - OpenSLX GmbH
+#
+# This program is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your suggestions, praise, or complaints to feedback@openslx.org
+#
+# General information about OpenSLX can be found at http://openslx.org/
+# -----------------------------------------------------------------------------
+# AoE.pm
+# - provides ATA-over-Ethernet specific overrides of the
+# OpenSLX::OSExport::BlockDevice API.
+# -----------------------------------------------------------------------------
+package OpenSLX::OSExport::BlockDevice::AoE;
+
+use vars qw($VERSION);
+use base qw(OpenSLX::OSExport::BlockDevice::Base);
+$VERSION = 1.01; # API-version . implementation-version
+
+use strict;
+use Carp;
+use File::Basename;
+use OpenSLX::Basics;
+use OpenSLX::ConfigDB qw(:support);
+use OpenSLX::OSExport::BlockDevice::Base 1;
+use OpenSLX::Utils;
+
+#
+#
+# N.B.: currently this is just a stub
+#
+#
+
+
+################################################################################
+### interface methods
+################################################################################
+sub new
+{
+ my $class = shift;
+ my $self = {'name' => 'aoe',};
+ return bless $self, $class;
+}
+
+sub initialize
+{
+ my $self = shift;
+ my $engine = shift;
+ my $fs = shift;
+
+ $self->{'engine'} = $engine;
+ $self->{'fs'} = $fs;
+}
+
+sub getExportPort
+{
+ my $self = shift;
+ my $openslxDB = shift;
+
+ return $openslxDB->incrementGlobalCounter('next-nbd-server-port');
+}
+
+sub generateExportURI
+{
+ my $self = shift;
+ my $export = shift;
+
+ my $server =
+ length($export->{server_ip})
+ ? $export->{server_ip}
+ : generatePlaceholderFor('serverip');
+ $server .= ":$export->{port}" if length($export->{port});
+
+ return "aoe://$server";
+}
+
+sub requiredBlockDeviceModules
+{
+ my $self = shift;
+
+ return 'aoe';
+}
+
+sub showExportConfigInfo
+{
+ my $self = shift;
+ my $export = shift;
+
+ print(('#' x 80) . "\n");
+ print _tr(
+ "Please make sure you start a corresponding aoe-server:\n\t%s\n",
+ "... (don't know how this is done yet)"
+ );
+ print(('#' x 80) . "\n");
+}
+
+1;
diff --git a/installer/OpenSLX/OSExport/BlockDevice/Base.pm b/installer/OpenSLX/OSExport/BlockDevice/Base.pm
new file mode 100644
index 00000000..938dc6db
--- /dev/null
+++ b/installer/OpenSLX/OSExport/BlockDevice/Base.pm
@@ -0,0 +1,62 @@
+# Copyright (c) 2006, 2007 - OpenSLX GmbH
+#
+# This program is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your suggestions, praise, or complaints to feedback@openslx.org
+#
+# General information about OpenSLX can be found at http://openslx.org/
+# -----------------------------------------------------------------------------
+# Base.pm
+# - provides empty base of the OpenSLX OSExport::BlockDevice API.
+# -----------------------------------------------------------------------------
+package OpenSLX::OSExport::BlockDevice::Base;
+
+use vars qw($VERSION);
+$VERSION = 1.01; # API-version . implementation-version
+
+use strict;
+use Carp;
+
+use OpenSLX::Basics;
+use OpenSLX::Utils;
+
+################################################################################
+### interface methods
+################################################################################
+sub new
+{
+ confess "Creating OpenSLX::OSExport::BlockDevice::Base-objects directly makes no sense!";
+}
+
+sub initialize
+{
+}
+
+sub getExportPort
+{
+}
+
+sub generateExportURI
+{
+}
+
+sub requiredBlockDeviceModules
+{
+}
+
+sub showExportConfigInfo
+{
+}
+
+1;
+################################################################################
+
+=pod
+
+=head1 NAME
+
+OpenSLX::OSExport::BlockDevice::Base - the base class for all OSExport::BlockDevices
+
+=cut
diff --git a/installer/OpenSLX/OSExport/BlockDevice/NBD.pm b/installer/OpenSLX/OSExport/BlockDevice/NBD.pm
new file mode 100644
index 00000000..8afaa97f
--- /dev/null
+++ b/installer/OpenSLX/OSExport/BlockDevice/NBD.pm
@@ -0,0 +1,91 @@
+# Copyright (c) 2006, 2007 - OpenSLX GmbH
+#
+# This program is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your suggestions, praise, or complaints to feedback@openslx.org
+#
+# General information about OpenSLX can be found at http://openslx.org/
+# -----------------------------------------------------------------------------
+# NBD.pm
+# - provides NBD+Squashfs-specific overrides of the
+# OpenSLX::OSExport::BlockDevice API.
+# -----------------------------------------------------------------------------
+package OpenSLX::OSExport::BlockDevice::NBD;
+
+use vars qw($VERSION);
+use base qw(OpenSLX::OSExport::BlockDevice::Base);
+$VERSION = 1.01; # API-version . implementation-version
+
+use strict;
+use Carp;
+use File::Basename;
+use OpenSLX::Basics;
+use OpenSLX::ConfigDB qw(:support);
+use OpenSLX::OSExport::BlockDevice::Base 1;
+use OpenSLX::Utils;
+
+################################################################################
+### interface methods
+################################################################################
+sub new
+{
+ my $class = shift;
+ my $self = {'name' => 'nbd',};
+ return bless $self, $class;
+}
+
+sub initialize
+{
+ my $self = shift;
+ my $engine = shift;
+ my $fs = shift;
+
+ $self->{'engine'} = $engine;
+ $self->{'fs'} = $fs;
+}
+
+sub getExportPort
+{
+ my $self = shift;
+ my $openslxDB = shift;
+
+ return $openslxDB->incrementGlobalCounter('next-nbd-server-port');
+}
+
+sub generateExportURI
+{
+ my $self = shift;
+ my $export = shift;
+
+ my $server =
+ length($export->{server_ip})
+ ? $export->{server_ip}
+ : generatePlaceholderFor('serverip');
+ $server .= ":$export->{port}" if length($export->{port});
+
+ return "nbd://$server";
+}
+
+sub requiredBlockDeviceModules
+{
+ my $self = shift;
+
+ return 'nbd';
+}
+
+sub showExportConfigInfo
+{
+ my $self = shift;
+ my $export = shift;
+
+ print(('#' x 80) . "\n");
+ print _tr(
+ "Please make sure you start a corresponding nbd-server:\n\t%s\n",
+ "nbd-server $export->{port} $self->{fs}->{'export-path'} -r"
+ );
+ print(('#' x 80) . "\n");
+}
+
+1;
diff --git a/installer/OpenSLX/OSExport/Engine.pm b/installer/OpenSLX/OSExport/Engine.pm
index 6668416a..5d08c177 100644
--- a/installer/OpenSLX/OSExport/Engine.pm
+++ b/installer/OpenSLX/OSExport/Engine.pm
@@ -14,13 +14,14 @@
package OpenSLX::OSExport::Engine;
use vars qw(@ISA @EXPORT $VERSION);
-$VERSION = 1.01; # API-version . implementation-version
+$VERSION = 1.01; # API-version . implementation-version
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
- %supportedExportTypes %supportedDistros
+ %supportedExportFileSystems %supportedExportBlockDevices
+ @supportedExportTypes %supportedDistros
);
use strict;
@@ -30,28 +31,27 @@ use File::Basename;
use OpenSLX::Basics;
use OpenSLX::Utils;
-use vars qw(%supportedExportTypes %supportedDistros);
+use vars qw(
+ %supportedExportFileSystems %supportedExportBlockDevices
+ @supportedExportTypes %supportedDistros
+);
-%supportedExportTypes = (
- 'nfs'
- => { module => 'NFS' },
- 'nbd'
- => { module => 'NBD_Squash' },
+%supportedExportFileSystems = (
+ 'nfs' => 'NFS',
+ 'sqfs' => 'SquashFS',
);
+%supportedExportBlockDevices = ('nbd' => 'NBD', 'aoe' => 'AoE');
+
+@supportedExportTypes = ('nfs', 'sqfs-aoe', 'sqfs-nbd');
+
%supportedDistros = (
- '<any>'
- => { module => 'Any' },
- 'debian'
- => { module => 'Debian' },
- 'fedora'
- => { module => 'Fedora' },
- 'gentoo'
- => { module => 'Gentoo' },
- 'suse'
- => { module => 'SUSE' },
- 'ubuntu'
- => { module => 'Ubuntu' },
+ '<any>' => {module => 'Any'},
+ 'debian' => {module => 'Debian'},
+ 'fedora' => {module => 'Fedora'},
+ 'gentoo' => {module => 'Gentoo'},
+ 'suse' => {module => 'SUSE'},
+ 'ubuntu' => {module => 'Ubuntu'},
);
################################################################################
@@ -61,55 +61,52 @@ sub new
{
my $class = shift;
- my $self = {
- };
+ my $self = {};
return bless $self, $class;
}
sub initializeFromExisting
{
- my $self = shift;
+ my $self = shift;
my $exportName = shift;
my $openslxDB = instantiateClass("OpenSLX::ConfigDB");
$openslxDB->connect();
- my $export
- = $openslxDB->fetchExportByFilter({'name' => $exportName});
+ 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} });
+ my $vendorOS =
+ $openslxDB->fetchVendorOSByFilter({'id' => $export->{vendor_os_id}});
$openslxDB->disconnect();
- $self->_initialize($vendorOS->{name}, $vendorOS->{id},
- $export->{name}, $export->{type});
+ $self->_initialize($vendorOS->{name}, $vendorOS->{id}, $export->{name},
+ $export->{type});
}
sub initializeForNew
{
- my $self = shift;
+ my $self = shift;
my $vendorOSName = shift;
- my $exportType = lc(shift);
+ my $exportType = lc(shift);
my $openslxDB = instantiateClass("OpenSLX::ConfigDB");
$openslxDB->connect();
- my $vendorOS
- = $openslxDB->fetchVendorOSByFilter({ 'name' => $vendorOSName });
+ my $vendorOS = $openslxDB->fetchVendorOSByFilter({'name' => $vendorOSName});
if (!defined $vendorOS) {
die _tr("vendor-OS '%s' not found in DB, giving up!", $vendorOSName);
}
- my $exportName = "$vendorOSName-$exportType";
+ my $exportName = "$vendorOSName:$exportType";
$openslxDB->disconnect();
- $self->_initialize($vendorOS->{name}, $vendorOS->{id},
- $exportName, $exportType);
+ $self->_initialize($vendorOS->{name}, $vendorOS->{id}, $exportName,
+ $exportType);
}
sub exportVendorOS
@@ -117,27 +114,37 @@ 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.");
+ 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'}
+ $self->{'exporter'}->exportVendorOS($self->{'vendor-os-path'},);
+ vlog(
+ 0,
+ _tr(
+ "vendor-OS '%s' successfully exported to '%s'!",
+ $self->{'vendor-os-path'},
+ $self->{exporter}->{'export-path'}
+ )
);
- vlog 0, _tr("vendor-OS '%s' successfully exported to '%s'!",
- $self->{'vendor-os-path'}, $self->{'export-path'});
- $self->addExportToConfigDB();
+ $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();
+ if ($self->{'exporter'}->purgeExport()) {
+ vlog(
+ 0,
+ _tr(
+ "export '%s' successfully removed!",
+ $self->{exporter}->{'export-path'}
+ )
+ );
+ }
+ $self->_removeExportFromConfigDB();
}
sub generateExportURI
@@ -159,23 +166,28 @@ sub requiredFSMods
################################################################################
sub _initialize
{
- my $self = shift;
+ my $self = shift;
my $vendorOSName = shift;
- my $vendorOSId = shift;
- my $exportName = shift;
- my $exportType = lc(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";
+ my $vendorOSId = shift;
+ my $exportName = shift;
+ my $exportType = lc(shift);
+
+ if (!grep { $_ eq $exportType } @supportedExportTypes) {
+ vlog(0,
+ _tr("Sorry, export type '%s' is unsupported.\n", $exportType)
+ . _tr("List of supported export types:\n\t")
+ . join("\n\t", sort @supportedExportTypes));
exit 1;
}
+ $exportType =~ m[^(\w+)(?:-(\w+))?$];
+ my $exportFS = lc($1);
+ my $exportBD = lc($2);
+ vlog(2, "export-fs='$exportFS' export-bd='$exportBD'");
$self->{'vendor-os-name'} = $vendorOSName;
- $self->{'vendor-os-id'} = $vendorOSId;
- $self->{'export-name'} = $exportName;
- $self->{'export-type'} = $exportType;
+ $self->{'vendor-os-id'} = $vendorOSId;
+ $self->{'export-name'} = $exportName;
+ $self->{'export-type'} = $exportType;
$vendorOSName =~ m[^(.+?\-[^-]+)];
my $distroName = $1;
$self->{'distro-name'} = $distroName;
@@ -194,55 +206,78 @@ sub _initialize
}
}
my $distroModuleName = $supportedDistros{lc($distroName)}->{module};
- my $distro
- = instantiateClass("OpenSLX::OSExport::Distro::$distroModuleName");
+ my $distro =
+ instantiateClass("OpenSLX::OSExport::Distro::$distroModuleName");
$distro->initialize($self);
$self->{distro} = $distro;
# load module for the requested export type:
- my $typeModuleName = $supportedExportTypes{lc($exportType)}->{module};
- my $exporter
- = instantiateClass("OpenSLX::OSExport::ExportType::$typeModuleName");
- $exporter->initialize($self);
+ my $fsModuleName = $supportedExportFileSystems{$exportFS};
+ my $exporter =
+ instantiateClass("OpenSLX::OSExport::FileSystem::$fsModuleName");
+ if (length($exportBD)) {
+ my $blockModuleName = $supportedExportBlockDevices{$exportBD};
+ my $blockDevice =
+ instantiateClass("OpenSLX::OSExport::BlockDevice::$blockModuleName");
+ $blockDevice->initialize($self, $exporter);
+ $exporter->initialize($self, $blockDevice);
+ } else {
+ $exporter->initialize($self);
+ }
$self->{'exporter'} = $exporter;
# setup source and target paths:
- $self->{'vendor-os-path'}
- = "$openslxConfig{'private-path'}/stage1/$vendorOSName";
- my $exportBasePath = "$openslxConfig{'public-path'}/export";
- $self->{'export-path'} = "$exportBasePath/$exportType/$vendorOSName";
- vlog 1, _tr("vendor-OS from '%s' will be exported to '%s'",
- $self->{'vendor-os-path'}, $self->{'export-path'});
+ $self->{'vendor-os-path'} =
+ "$openslxConfig{'private-path'}/stage1/$vendorOSName";
+ vlog(
+ 1,
+ _tr(
+ "vendor-OS from '%s' will be exported to '%s'",
+ $self->{'vendor-os-path'},
+ $exporter->{'export-path'}
+ )
+ );
}
-sub addExportToConfigDB
+sub _addExportToConfigDB
{
my $self = shift;
my $openslxDB = instantiateClass("OpenSLX::ConfigDB");
$openslxDB->connect();
- my $export
- = $openslxDB->fetchExportByFilter({
- 'name' => $self->{'export-name'},
+ my $export = $openslxDB->fetchExportByFilter(
+ {
+ 'name' => $self->{'export-name'},
'vendor_os_id' => $self->{'vendor-os-id'},
- });
+ }
+ );
if (defined $export) {
- vlog 0, _tr("No need to change export '%s' in OpenSLX-database.\n",
- $self->{'export-name'});
+ vlog(
+ 0,
+ _tr(
+ "No need to change export '%s' in OpenSLX-database.\n",
+ $self->{'export-name'}
+ )
+ );
$self->{exporter}->showExportConfigInfo($export);
} else {
$export = {
'vendor_os_id' => $self->{'vendor-os-id'},
- 'name' => $self->{'export-name'},
- 'type' => $self->{'export-type'},
+ 'name' => $self->{'export-name'},
+ 'type' => $self->{'export-type'},
};
-
+
my $id = $self->{exporter}->addExportToConfigDB($export, $openslxDB);
- vlog 0, _tr("Export '%s' has been added to DB (ID=%s)...\n",
- $self->{'export-name'}, $id);
+ vlog(
+ 0,
+ _tr(
+ "Export '%s' has been added to DB (ID=%s)...\n",
+ $self->{'export-name'}, $id
+ )
+ );
- $self->{exporter}->showExportConfigInfo($export) if $id;
+ $self->{exporter}->showExportConfigInfo($export) if $id;
# now create a default system for that export, using the standard kernel:
system("slxconfig add-system $self->{'export-name'}");
@@ -251,7 +286,7 @@ sub addExportToConfigDB
$openslxDB->disconnect();
}
-sub removeExportFromConfigDB
+sub _removeExportFromConfigDB
{
my $self = shift;
@@ -260,26 +295,32 @@ sub removeExportFromConfigDB
# remove export from DB:
my $exportName = $self->{'export-name'};
- my $export
- = $openslxDB->fetchExportByFilter({
- 'name' => $exportName,
- });
+ my $export = $openslxDB->fetchExportByFilter({'name' => $exportName,});
if (!defined $export) {
- vlog 0, _tr("Export '%s' doesn't exist in OpenSLX-database.\n",
- $exportName);
+ vlog(
+ 0,
+ _tr(
+ "Export '%s' doesn't exist in OpenSLX-database.\n", $exportName
+ )
+ );
} else {
# remove all systems using this export and then remove the
# export itself:
- my @systemIDs
- = map { $_->{id} }
- $openslxDB->fetchSystemByFilter(
- { 'export_id' => $export->{id} }, 'id'
- );
- vlog 1, _tr("removing systems '%s' from DB, since they belong to the export being deleted.\n",
- join ',', @systemIDs);
+ my @systemIDs =
+ map { $_->{id} }
+ $openslxDB->fetchSystemByFilter({'export_id' => $export->{id}}, 'id');
+ vlog(
+ 1,
+ _tr(
+ "removing systems '%s' from DB, since they belong to the export"
+ . " being deleted.\n",
+ join ',',
+ @systemIDs
+ )
+ );
$openslxDB->removeSystem(\@systemIDs);
$openslxDB->removeExport($export->{id});
- vlog 0, _tr("Export '%s' has been removed from DB.\n", $exportName);
+ vlog(0, _tr("Export '%s' has been removed from DB.\n", $exportName));
}
$openslxDB->disconnect();
@@ -301,3 +342,4 @@ OpenSLX::OSExport::Engine -
...
=cut
+
diff --git a/installer/OpenSLX/OSExport/ExportType/Base.pm b/installer/OpenSLX/OSExport/ExportType/Base.pm
deleted file mode 100644
index 7e0aa464..00000000
--- a/installer/OpenSLX/OSExport/ExportType/Base.pm
+++ /dev/null
@@ -1,128 +0,0 @@
-# Copyright (c) 2006, 2007 - OpenSLX GmbH
-#
-# This program is free software distributed under the GPL version 2.
-# See http://openslx.org/COPYING
-#
-# If you have any feedback please consult http://openslx.org/feedback and
-# send your suggestions, praise, or complaints to feedback@openslx.org
-#
-# General information about OpenSLX can be found at http://openslx.org/
-# -----------------------------------------------------------------------------
-# Base.pm
-# - provides empty base of the OpenSLX OSExport::ExportType API.
-# -----------------------------------------------------------------------------
-package OpenSLX::OSExport::ExportType::Base;
-
-use vars qw($VERSION);
-$VERSION = 1.01; # API-version . implementation-version
-
-use strict;
-use Carp;
-
-use OpenSLX::Basics;
-use OpenSLX::Utils;
-
-################################################################################
-### 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;
-}
-
-sub exportVendorOS
-{
-}
-
-sub purgeExport
-{
-}
-
-sub checkRequirements
-{
- return 1;
-}
-
-sub addExportToConfigDB
-{
- my $self = shift;
- my $export = shift;
- my $openslxDB = shift;
-
- return $openslxDB->addExport($export);
-}
-
-sub generateExportURI
-{
-}
-
-sub requiredFSMods
-{
-}
-
-sub showExportConfigInfo
-{
-}
-
-################################################################################
-### implementation methods
-################################################################################
-sub determineIncludeExcludeList
-{
- my $self = shift;
-
- # Rsync uses a first match strategy, so we mix the local specifications
- # in front of the filterset given by the package (as the local filters
- # should always overrule the vendor filters):
- my $distroName = $self->{engine}->{'distro-name'};
- my $localFilterFile
- = "$openslxConfig{'config-path'}/distro-info/$distroName/export-filter";
- my $includeExcludeList = slurpFile($localFilterFile, 1);
- $includeExcludeList .= $self->{engine}->{distro}->{'export-filter'};
- $includeExcludeList =~ s[^\s+][]igms;
- # remove any leading whitespace, as rsync doesn't like it
- return $includeExcludeList;
-}
-
-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/FileSystem/Base.pm b/installer/OpenSLX/OSExport/FileSystem/Base.pm
new file mode 100644
index 00000000..bb6f42d3
--- /dev/null
+++ b/installer/OpenSLX/OSExport/FileSystem/Base.pm
@@ -0,0 +1,81 @@
+# Copyright (c) 2006, 2007 - OpenSLX GmbH
+#
+# This program is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your suggestions, praise, or complaints to feedback@openslx.org
+#
+# General information about OpenSLX can be found at http://openslx.org/
+# -----------------------------------------------------------------------------
+# Base.pm
+# - provides empty base of the OpenSLX OSExport::FileSystem API.
+# -----------------------------------------------------------------------------
+package OpenSLX::OSExport::FileSystem::Base;
+
+use vars qw($VERSION);
+$VERSION = 1.01; # API-version . implementation-version
+
+use strict;
+use Carp;
+
+use OpenSLX::Basics;
+use OpenSLX::Utils;
+
+################################################################################
+### interface methods
+################################################################################
+sub new
+{
+ confess "Creating OpenSLX::OSExport::FileSystem::Base-objects directly makes no sense!";
+}
+
+sub initialize
+{
+}
+
+sub exportVendorOS
+{
+}
+
+sub purgeExport
+{
+}
+
+sub checkRequirements
+{
+ return 1;
+}
+
+sub addExportToConfigDB
+{
+ my $self = shift;
+ my $export = shift;
+ my $openslxDB = shift;
+
+ return $openslxDB->addExport($export);
+}
+
+sub generateExportURI
+{
+}
+
+sub requiredFSMods
+{
+}
+
+sub showExportConfigInfo
+{
+}
+
+1;
+
+################################################################################
+
+=pod
+
+=head1 NAME
+
+OpenSLX::OSExport::FileSystem::Base - the base class for all OSExport::FileSystems
+
+=cut
diff --git a/installer/OpenSLX/OSExport/ExportType/NFS.pm b/installer/OpenSLX/OSExport/FileSystem/NFS.pm
index 12fa4bfc..36926d61 100644
--- a/installer/OpenSLX/OSExport/ExportType/NFS.pm
+++ b/installer/OpenSLX/OSExport/FileSystem/NFS.pm
@@ -9,12 +9,12 @@
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
# NFS.pm
-# - provides NFS-specific overrides of the OpenSLX::OSExport::ExportType API.
+# - provides NFS-specific overrides of the OpenSLX::OSExport::FileSystem API.
# -----------------------------------------------------------------------------
-package OpenSLX::OSExport::ExportType::NFS;
+package OpenSLX::OSExport::FileSystem::NFS;
use vars qw($VERSION);
-use base qw(OpenSLX::OSExport::ExportType::Base);
+use base qw(OpenSLX::OSExport::FileSystem::Base);
$VERSION = 1.01; # API-version . implementation-version
use strict;
@@ -23,7 +23,7 @@ use File::Basename;
use OpenSLX::Basics;
use OpenSLX::ConfigDB qw(:support);
use OpenSLX::Utils;
-use OpenSLX::OSExport::ExportType::Base 1;
+use OpenSLX::OSExport::FileSystem::Base 1;
################################################################################
### interface methods
@@ -32,30 +32,40 @@ sub new
{
my $class = shift;
my $self = {
- 'name' => 'NFS',
+ 'name' => 'nfs',
};
return bless $self, $class;
}
+sub initialize
+{
+ my $self = shift;
+ my $engine = shift;
+
+ $self->{'engine'} = $engine;
+ my $exportBasePath = "$openslxConfig{'public-path'}/export";
+ $self->{'export-path'} = "$exportBasePath/nfs/$engine->{'vendor-os-name'}";
+}
+
sub exportVendorOS
{
my $self = shift;
my $source = shift;
- my $target = shift;
- $self->copyViaRsync($source, $target);
+ my $target = $self->{'export-path'};
+ $self->_copyViaRsync($source, $target);
}
sub purgeExport
{
my $self = shift;
- my $target = shift;
+ my $target = $self->{'export-path'};
if (system("rm -r $target")) {
- vlog 0, _tr("unable to remove export '%s'!", $target);
+ vlog(0, _tr("unable to remove export '%s'!", $target));
return 0;
}
- 1;
+ return 1;
}
sub generateExportURI
@@ -98,7 +108,7 @@ sub showExportConfigInfo
################################################################################
### implementation methods
################################################################################
-sub copyViaRsync
+sub _copyViaRsync
{
my $self = shift;
my $source = shift;
@@ -108,8 +118,8 @@ sub copyViaRsync
die _tr("unable to create directory '%s', giving up! (%s)\n",
$target, $!);
}
- my $includeExcludeList = $self->determineIncludeExcludeList();
- vlog 1, _tr("using include-exclude-filter:\n%s\n", $includeExcludeList);
+ my $includeExcludeList = $self->_determineIncludeExcludeList();
+ vlog(1, _tr("using include-exclude-filter:\n%s\n", $includeExcludeList));
open(RSYNC, "| rsync -av --delete --exclude-from=- $source/ $target")
or die _tr("unable to start rsync for source '%s', giving up! (%s)",
$source, $!);
@@ -120,4 +130,21 @@ sub copyViaRsync
}
}
+sub _determineIncludeExcludeList
+{
+ my $self = shift;
+
+ # Rsync uses a first match strategy, so we mix the local specifications
+ # in front of the filterset given by the package (as the local filters
+ # should always overrule the vendor filters):
+ my $distroName = $self->{engine}->{'distro-name'};
+ my $localFilterFile
+ = "$openslxConfig{'config-path'}/distro-info/$distroName/export-filter";
+ my $includeExcludeList = slurpFile($localFilterFile, 1);
+ $includeExcludeList .= $self->{engine}->{distro}->{'export-filter'};
+ $includeExcludeList =~ s[^\s+][]igms;
+ # remove any leading whitespace, as rsync doesn't like it
+ return $includeExcludeList;
+}
+
1;
diff --git a/installer/OpenSLX/OSExport/ExportType/NBD_Squash.pm b/installer/OpenSLX/OSExport/FileSystem/SquashFS.pm
index a1ec0c26..5983e2c2 100644
--- a/installer/OpenSLX/OSExport/ExportType/NBD_Squash.pm
+++ b/installer/OpenSLX/OSExport/FileSystem/SquashFS.pm
@@ -8,13 +8,14 @@
#
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
-# NBD_Squash.pm
-# - provides NBD+Squashfs-specific overrides of the OpenSLX::OSExport::ExportType API.
+# SquashFS.pm
+# - provides SquashFS-specific overrides of the OpenSLX::OSExport::ExportType
+# API.
# -----------------------------------------------------------------------------
-package OpenSLX::OSExport::ExportType::NBD_Squash;
+package OpenSLX::OSExport::FileSystem::SquashFS;
use vars qw($VERSION);
-use base qw(OpenSLX::OSExport::ExportType::Base);
+use base qw(OpenSLX::OSExport::FileSystem::Base);
$VERSION = 1.01; # API-version . implementation-version
use strict;
@@ -22,7 +23,7 @@ use Carp;
use File::Basename;
use OpenSLX::Basics;
use OpenSLX::ConfigDB qw(:support);
-use OpenSLX::OSExport::ExportType::Base 1;
+use OpenSLX::OSExport::FileSystem::Base 1;
use OpenSLX::Utils;
################################################################################
@@ -32,36 +33,53 @@ sub new
{
my $class = shift;
my $self = {
- 'name' => 'NBD_Squash',
+ 'name' => 'sqfs',
};
return bless $self, $class;
}
+sub initialize
+{
+ my $self = shift;
+ my $engine = shift;
+ my $blockDevice = shift || confess('need to pass in block-device!');
+
+ $self->{'engine'} = $engine;
+ $self->{'block-device'} = $blockDevice;
+ my $exportBasePath = "$openslxConfig{'public-path'}/export";
+ $self->{'export-path'}
+ = "$exportBasePath/sqfs/$engine->{'vendor-os-name'}";
+}
+
sub exportVendorOS
{
my $self = shift;
my $source = shift;
- my $target = shift;
- my $includeExcludeList = $self->determineIncludeExcludeList();
+ my $includeExcludeList = $self->_determineIncludeExcludeList();
# in order to do the filtering as part of mksquashfs, we need to map
# our internal (rsync-)filter format to regexes:
$includeExcludeList
- = mapRsyncFilter2Regex($source, $includeExcludeList);
- vlog 1, _tr("using include-exclude-filter:\n%s\n", $includeExcludeList);
- $self->createSquashFS($source, $target, $includeExcludeList);
+ = $self->_mapRsyncFilter2Regex($source, $includeExcludeList);
+ vlog(1, _tr("using include-exclude-filter:\n%s\n", $includeExcludeList));
+ my $target = $self->{'export-path'};
+# $self->_createSquashFS($source, $target, $includeExcludeList);
+ $self->_addBlockDeviceTagToExport($target);
}
sub purgeExport
{
my $self = shift;
- my $target = shift;
- if (system("rm $target")) {
- vlog 0, _tr("unable to remove export '%s'!", $target);
- return 0;
+ my $target = $self->{'export-path'};
+ if ($self->_removeBlockDeviceTagFromExport($target)) {
+ # no more tags, we can remove the image:
+ if (slxsystem("rm $target")) {
+ vlog(0, _tr("unable to remove export '%s'!", $target));
+ return 0;
+ }
}
- 1;
+ return 1;
}
sub checkRequirements
@@ -76,17 +94,22 @@ sub checkRequirements
die _tr("unable to determine version of kernel '%s'!", $kernel);
}
my $kernelVer = $1;
- my $nbdMod = locateKernelModule(
- $vendorOSPath,
- 'nbd.ko',
- ["$vendorOSPath/lib/modules/$kernelVer/kernel/drivers/block"]
- );
- if (!defined $nbdMod) {
- warn _tr("unable to find nbd-module for kernel version '%s'.",
- $kernelVer);
- return undef;
+ my @blockMods;
+ my @blockModNames = $self->{'block-device'}->requiredBlockDeviceModules();
+ foreach my $blockModName (@blockModNames) {
+ my $blockMod = $self->_locateKernelModule(
+ $vendorOSPath,
+ "$blockModName.ko",
+ ["$vendorOSPath/lib/modules/$kernelVer/kernel/drivers/block"]
+ );
+ if (!defined $blockMod) {
+ warn _tr("unable to find blockdevice-module '%s' for kernel version '%s'.",
+ $blockModName, $kernelVer);
+ return undef;
+ }
+ push @blockMods, $blockMod;
}
- my $squashfsMod = locateKernelModule(
+ my $squashfsMod = $self->_locateKernelModule(
$vendorOSPath,
'squashfs.ko',
["$vendorOSPath/lib/modules/$kernelVer/kernel/fs/squashfs",
@@ -97,8 +120,9 @@ sub checkRequirements
$kernelVer);
return undef;
}
+ push @blockMods, $squashfsMod;
if (defined $info) {
- $info->{'kernel-mods'} = [ $nbdMod, $squashfsMod ];
+ $info->{'kernel-mods'} = \@blockMods;
};
return 1;
}
@@ -109,8 +133,7 @@ sub addExportToConfigDB
my $export = shift;
my $openslxDB = shift;
- $export->{port}
- = $openslxDB->incrementGlobalCounter('next-nbd-server-port');
+ $export->{port} = $self->{'block-device'}->getExportPort($openslxDB);
my $res = $openslxDB->addExport($export);
return $res;
@@ -122,20 +145,18 @@ sub generateExportURI
my $export = shift;
my $vendorOS = shift;
- my $server
- = length($export->{server_ip})
- ? $export->{server_ip}
- : generatePlaceholderFor('serverip');
- $server .= ":$export->{port}" if length($export->{port});
-
- return "nbd://$server/squashfs";
+ my $URI = $self->{'block-device'}->generateExportURI($export);
+ $URI .= '/squashfs';
+ return $URI;
}
sub requiredFSMods
{
my $self = shift;
- return 'nbd squashfs';
+ my @mods = $self->{'block-device'}->requiredBlockDeviceModules();
+ push @mods, 'squashfs ';
+ return join ' ', @mods;
}
sub showExportConfigInfo
@@ -143,17 +164,14 @@ sub showExportConfigInfo
my $self = shift;
my $export = shift;
- print (('#' x 80)."\n");
- print _tr("Please make sure you start a corresponding nbd-server:\n\t%s\n",
- "nbd-server $export->{port} $self->{engine}->{'export-path'} -r");
- print (('#' x 80)."\n");
+ $self->{'block-device'}->showExportConfigInfo($export);
}
################################################################################
### implementation methods
################################################################################
-sub createSquashFS
+sub _createSquashFS
{
my $self = shift;
my $source = shift;
@@ -181,7 +199,7 @@ sub createSquashFS
close(FILTERFILE);
# ... invoke mksquashfs ...
- vlog 0, _tr("invoking mksquashfs...");
+ vlog(0, _tr("invoking mksquashfs..."));
my $mksquashfsBinary
= "$openslxConfig{'base-path'}/share/squashfs/mksquashfs";
my $res = system("$mksquashfsBinary $source $target -ff $filterFile");
@@ -193,8 +211,26 @@ sub createSquashFS
}
}
-sub mapRsyncFilter2Regex
+sub _determineIncludeExcludeList
+{
+ my $self = shift;
+
+ # Rsync uses a first match strategy, so we mix the local specifications
+ # in front of the filterset given by the package (as the local filters
+ # should always overrule the vendor filters):
+ my $distroName = $self->{engine}->{'distro-name'};
+ my $localFilterFile
+ = "$openslxConfig{'config-path'}/distro-info/$distroName/export-filter";
+ my $includeExcludeList = slurpFile($localFilterFile, 1);
+ $includeExcludeList .= $self->{engine}->{distro}->{'export-filter'};
+ $includeExcludeList =~ s[^\s+][]igms;
+ # remove any leading whitespace, as rsync doesn't like it
+ return $includeExcludeList;
+}
+
+sub _mapRsyncFilter2Regex
{
+ my $self = shift;
my $sourcePath = shift;
return
@@ -227,16 +263,17 @@ sub mapRsyncFilter2Regex
split "\n", shift;
}
-sub locateKernelModule
+sub _locateKernelModule
{
+ my $self = shift;
my $vendorOSPath = shift;
my $moduleName = shift;
my $defaultPaths = shift;
- vlog 1, _tr("locating kernel-module '%s'", $moduleName);
+ vlog(1, _tr("locating kernel-module '%s'", $moduleName));
# check default paths first:
foreach my $defPath (@$defaultPaths) {
- vlog 2, "trying $defPath/$moduleName";
+ vlog(2, "trying $defPath/$moduleName");
my $target = followLink("$defPath/$moduleName", $vendorOSPath);
return $target unless !-e $target;
}
@@ -244,13 +281,13 @@ sub locateKernelModule
use File::Find;
my $location;
my $locationAge = 9999999;
- vlog 2, "searching in $vendorOSPath/lib/modules";
+ vlog(2, "searching in $vendorOSPath/lib/modules");
find sub {
return unless $_ eq $moduleName;
if (-M _ < $locationAge) {
$locationAge = -M _;
$location = $File::Find::name;
- vlog 2, "located at $location (age=$locationAge days)";
+ vlog(2, "located at $location (age=$locationAge days)");
}
}, "$vendorOSPath/lib/modules";
if (defined $location) {
@@ -259,4 +296,28 @@ sub locateKernelModule
return undef;
}
+sub _addBlockDeviceTagToExport
+{
+ my $self = shift;
+ my $target = shift;
+
+ my $tagName = "$target".'@'.lc($self->{'block-device'}->{name});
+ linkFile(basename($target), $tagName);
+}
+
+sub _removeBlockDeviceTagFromExport
+{
+ my $self = shift;
+ my $target = shift;
+
+ my $tagName = "$target".'@'.lc($self->{'block-device'}->{name});
+ slxsystem("rm $tagName");
+ # now find out whether or not there are any other tags left:
+ my $vendorOSName = basename($target);
+ opendir(DIR, dirname($target));
+ my @tags = grep { /^vendorOSName\@/ } readdir(DIR);
+ return @tags ? 0 : 1;
+ # return 1 if no more tags (i.e. it is safe to remove the image)
+}
+
1;