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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
#! /usr/bin/perl -CLADS
# -----------------------------------------------------------------------------
# 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/
# -----------------------------------------------------------------------------
use strict;
use warnings;
my $abstract = q[
slxos-export
OpenSLX-script to generate an export from a vendor-OS.
];
use Encode;
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;
use OpenSLX::Utils;
my ($helpReq, $manReq, $verbose, $versionReq,);
GetOptions(
'help|?' => \$helpReq,
'man' => \$manReq,
'verbose' => \$verbose,
'version' => \$versionReq,
)
or pod2usage(2);
pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq;
if ($manReq) {
$ENV{LANG} = 'en_EN';
# avoid dubious problem with perldoc in combination with UTF-8 that
# leads to strange dashes and single-quotes being used
pod2usage(-verbose => 2);
}
if ($versionReq) {
system('slxversion');
exit 1;
}
openslxInit();
my $action = shift @ARGV || '';
if ($action =~ m[^list-ex]i) {
print _tr("List of exported vendor-OSes:\n");
foreach my $type (sort keys %supportedExportFileSystems) {
# list all image files, followed by the block devices using it:
my @files = map {
my $image = decode('utf8', $_);
$image =~ s[^.+/][];
$image;
} sort glob("$openslxConfig{'public-path'}/export/$type/*");
my %imageFiles;
foreach my $file (@files) {
if ($file =~ m[^(.+)@(.+)$]) {
# it's a link referring to a block device using this image,
# we collect the name of the block device:
push @{$imageFiles{$1}}, $2;
} else {
# it's an image file, we setup an empty array of block devices:
$imageFiles{$file} = [];
}
}
print join(
'',
map {
my $devices = join(',', @{$imageFiles{$_}});
if (length($devices)) {
my $name = "$type/$_";
"\t$name".substr(' ' x 30, length($name))."($devices)\n";
} else {
"\t$type/$_\n";
}
}
grep {
# filter out RSYNC_TMP folders:
$_ !~ m[###];
}
sort keys %imageFiles
);
}
} elsif ($action =~ m[^list-in]i) {
my @files = glob("$openslxConfig{'private-path'}/stage1/*");
print _tr("List of installed vendor-OSes:\n");
print join(
'',
map {
my $vendorOS = decode('utf8', $_);
$vendorOS =~ s[^.+/][];
"\t$vendorOS\n";
}
sort @files
);
} elsif ($action =~ m[^list-ty]i) {
print _tr("List of supported export types:\n\t");
print join("\n\t", sort @supportedExportTypes) . "\n";
} elsif ($action =~ m[^export]i) {
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 = shift @ARGV;
my $exportType = 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->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[^remove]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);
$engine->purgeExport();
} else {
vlog(0, _tr(unshiftHereDoc(<<' END-OF-HERE'), $0));
You need to specify exactly one action:
export
list-exported
list-installed
list-types
remove
Try '%s --help' for more info.
END-OF-HERE
}
=head1 NAME
slxos-export - OpenSLX-script to generate an export from a vendor-OS.
=head1 SYNOPSIS
slxos-export [options] <action>
=head3 Options
--help brief help message
--man show full documentation
--verbose show more information during execution
--version show version
=head3 Actions
=over 8
=item B<< export <vendor-OS-name> <export-type> >>
exports the vendor-OS with the given name using the given export type and
adds it to the config-DB, too. The export will be named as the vendor-OS,
but with an additional '-<X>' appended to it (where <X> will be replaced
by the chosen export-type).
=item B<< list-exported >>
list all exported vendor-OSes
=item B<< list-installed >>
list all installed vendor-OSes
=item B<< list-types >>
list all supported export types
=item B<< remove <export-name> >>
removes the export with the given name from disk and config-DB
=back
=head1 DESCRIPTION
B<slxos-export> converts an installed vendor-OS into a form that can be accessed
via network by booting clients.
The resulting form of such a conversion is called an I<export> and those come
in different flavors:
=over 8
=item B< Export Type 'nfs'>
NFS (network file system) is a well established networking file system, which
is supported by LINUX since long.
=item B< Export Type 'sqfs-nbd'>
Squash-FS is a rather modern filesystem providing very good compression,
resulting in considerably reduced network traffic during boot (and execution).
However, in order to mount a squash-fs that resides on the server, the client
has to get access to it first. This can be established via a network block
device, which basically "transports" a block device over the network (from
server to client), making it possible to use more or less any file system over
the network.
So, this example translates to 'use a squashfs on a network block device'.
=back
When invoking slxos-export, you have to pass it a vendor-OS name and the export
type you want to use and it will do the conversion (which can take a while, so
please be patient).
The resulting export will be stored under C</srv/openslx/export>.
=head1 OPTIONS
=over 4
=item B<--help>
Prints a brief help message and exits.
=item B<--man>
Prints the manual page and exits.
=item B<--verbose>
Prints more information during execution of any action.
=item B<--version>
Prints the version and exits.
=back
=head1 EXAMPLES
=over 8
=head3 Exporting a Vendor-OS via NFS
=item B<< slxos-export export suse-10.2 nfs >>
Exports the installed vendor-OS suse-10.2 via nfs, the
resulting NFS-export will live in C</srv/openslx/export/nfs/suse-10.2>.
=back
=head3 Exporting a Vendor-OS via NBD
=over 8
=item B<< slxos-export export ubuntu-6.10 sqfs-nbd >>
Exports the installed vendor-OS ubuntu-6.10 via nbd, the resulting
Squash-FS will live in C</srv/openslx/export/nbd/ubuntu-6.10>.
=back
=head3 Removing an Export
=over 8
=item B<< slxos-export remove ubuntu-6.10 nbd >>
Wipes the squash-FS of the export named 'ubuntu-6.10' from disk (i.e. the
file C</srv/openslx/export/nbd/ubuntu-6.10> will be deleted) and
removes that export from the config-DB, too.
=back
=head1 SEE ALSO
slxsettings, slxos-setup, slxconfig, slxconfig-demuxer
=head1 GENERAL OPENSLX OPTIONS
Being a part of OpenSLX, this script supports several other options
which can be used to overrule the OpenSLX settings:
--db-name=<string> name of database
--db-spec=<string> full DBI-specification of database
--db-type=<string> type of database to connect to
--locale=<string> locale to use for translations
--logfile=<string> file to write logging output to
--private-path=<string> path to private data
--public-path=<string> path to public (client-accesible) data
--temp-path=<string> path to temporary data
--verbose-level=<int> level of logging verbosity (0-3)
Please refer to the C<slxsettings>-manpage for a more detailed description
of these options.
=cut
|