summaryrefslogtreecommitdiffstats
path: root/installer/OpenSLX/OSExport/Engine.pm
blob: 413f5fde761610012de47b6883aa5838b9a163ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# 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 %supportedDistros
);

use strict;
use Carp;
use File::Basename;
use OpenSLX::Basics;

use vars qw(%supportedExportTypes %supportedDistros);

%supportedExportTypes = (
	'nfs'
		=> { module => 'NFS' },
	'nbd'
		=> { module => 'NBD' },
	'nbd-squashfs'
		=> { module => 'NBD_Squash' },
);

%supportedDistros = (
	'debian-3.1'
		=> { module => 'Debian_3_1' },
	'debian-4.0'
		=> { module => 'Debian_4_0' },
	'fedora-6'
		=> { module => 'Fedora_6' },
	'fedora-6-x86_64'
		=> { module => 'Fedora_6_x86_64' },
	'gentoo-2005.1'
		=> { module => 'Gentoo_2005_1' },
	'gentoo-2006.1'
		=> { module => 'Gentoo_2006_1' },
	'mandriva-2007.0'
		=> { module => 'Mandriva_2007_0' },
	'suse-9.3'
		=> { module => 'SUSE_9_3' },
	'suse-10.0'
		=> { module => 'SUSE_10_0' },
	'suse-10.0-x86_64'
		=> { module => 'SUSE_10_0_x86_64' },
	'suse-10.1'
		=> { module => 'SUSE_10_1' },
	'suse-10.1-x86_64'
		=> { module => 'SUSE_10_1_x86_64' },
	'suse-10.2'
		=> { module => 'SUSE_10_2' },
	'suse-10.2-x86_64'
		=> { module => 'SUSE_10_2_x86_64' },
	'ubuntu-6.06'
		=> { module => 'Ubuntu_6_06' },
	'ubuntu-6.10'
		=> { module => 'Ubuntu_6_10' },
);

################################################################################
### 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 distro:
	my $distroModule
		= "OpenSLX::OSExport::Distro::"
			.$supportedDistros{lc($distroName)}->{module};
	unless (eval "require $distroModule") {
		if ($! == 2) {
			die _tr("Distro-module <%s> not found!\n", $distroModule);
		} else {
			die _tr("Unable to load distro-module <%s> (%s)\n", $distroModule, $@);
		}
	}
	my $modVersion = $distroModule->VERSION;
	if ($modVersion < 1.01) {
		die _tr('Could not load module <%s> (Version <%s> required, but <%s> found)',
				$distroModule, 1.01, $modVersion);
	}
	$distroModule->import;
	my $distro = $distroModule->new;
	$distro->initialize($self);
	$self->{distro} = $distro;

	# 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;

print "adding the export to the config-DB is not implemented yet, sorry!\n";
return;

	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