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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
|
# 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/
# -----------------------------------------------------------------------------
# AttributeRoster.pm
# - provides information about all available attributes
# -----------------------------------------------------------------------------
package OpenSLX::AttributeRoster;
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use OpenSLX::Basics;
use OpenSLX::OSPlugin::Engine;
use OpenSLX::OSPlugin::Roster;
use OpenSLX::Utils;
my %AttributeInfo;
#=item C<_init()>
#
#Integrates info about all known attributes (from core and from the plugins)
#into one big hash.
#Returns info about all attributes.
#
#=cut
#
sub _init
{
my $class = shift;
# set core attributes
%AttributeInfo = (
'automnt_dir' => {
applies_to_systems => 1,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
!!!descriptive text missing here!!!
End-of-Here
content_regex => undef,
content_descr => undef,
default => '',
},
'automnt_src' => {
applies_to_systems => 1,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
!!!descriptive text missing here!!!
End-of-Here
content_regex => undef,
content_descr => undef,
default => '',
},
'boot_type' => {
applies_to_systems => 0,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
Selects the boot technology for this client.
Currently the following boot types are supported:
pxe (is the default)
uses PXE to boot client over LAN
preboot
generates a set of images (see preboot_media) that can
be used to remotely boot the systems referred to by
this client
End-of-Here
content_regex => qr{^(pxe|preboot)$},
content_descr => '"pxe" or "preboot"',
default => 'pxe',
},
'boot_uri' => {
applies_to_systems => 0,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
specifies the wget(able) address of the remote bootloader
archive that shall be loaded from the preboot environment
End-of-Here
content_regex => undef,
content_descr => 'an uri supported by wget',
default => '',
},
'country' => {
applies_to_systems => 1,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
!!!descriptive text missing here!!!
End-of-Here
content_regex => undef,
content_descr => undef,
default => 'de',
},
'hidden' => {
applies_to_systems => 1,
applies_to_clients => 0,
description => unshiftHereDoc(<<' End-of-Here'),
specifies whether or not this system is offered for booting
End-of-Here
content_regex => qr{^(0|1)$},
content_descr => '0: system is bootable - 1: system is hidden',
default => '0',
},
'kernel_params' => {
applies_to_systems => 1,
applies_to_clients => 0,
description => unshiftHereDoc(<<' End-of-Here'),
params to build kernel cmdline for this system
End-of-Here
content_regex => undef,
content_descr => 'kernel cmdline fragment',
default => 'quiet',
},
'kernel_params_client' => {
applies_to_systems => 0,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
client-specific params for kernel cmdline
End-of-Here
content_regex => undef,
content_descr => 'kernel cmdline fragment',
default => '',
},
'preboot_media' => {
applies_to_systems => 0,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
List of preboot media supported by this client.
Currently the following preboot media are supported:
cd
generates a bootable CD-image that can be used to
remotely boot the systems referred to by this client
End-of-Here
content_regex => undef,
content_descr => undef,
default => '',
},
'ramfs_fsmods' => {
applies_to_systems => 1,
applies_to_clients => 0,
description => unshiftHereDoc(<<' End-of-Here'),
list of filesystem kernel modules to load
End-of-Here
content_regex => undef,
content_descr => undef,
default => '',
},
'ramfs_miscmods' => {
applies_to_systems => 1,
applies_to_clients => 0,
description => unshiftHereDoc(<<' End-of-Here'),
list of miscellaneous kernel modules to load
End-of-Here
content_regex => undef,
content_descr => undef,
default => '',
},
'ramfs_nicmods' => {
applies_to_systems => 1,
applies_to_clients => 0,
description => unshiftHereDoc(<<' End-of-Here'),
list of network card modules to load
End-of-Here
content_regex => qr{^\s*([-\w]+\s*)*$},
content_descr => 'a space-separated list of NIC modules',
default => 'forcedeth e1000 e100 tg3 via-rhine r8169 pcnet32',
},
'ramfs_firmmods' => {
applies_to_systems => 1,
applies_to_clients => 0,
description => unshiftHereDoc(<<' End-of-Here'),
list of wifi network card modules to load
End-of-Here
content_regex => qr{^\s*([-\w]+\s*)*$},
content_descr => 'a space-separated list of firmware modules',
default => 'tigon e100',
},
'hw_local_disk' => {
applies_to_systems => 1,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
how to handle local disk deploament - no/slxonly/all
End-of-Here
content_regex => undef,
content_descr => 'how to handle local disk (no/slxonly/all)',
default => 'all',
},
'scratch' => {
applies_to_systems => 1,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
!!!descriptive text missing here!!!
End-of-Here
content_regex => undef,
content_descr => undef,
default => '',
},
'start_atd' => {
applies_to_systems => 1,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
!!!descriptive text missing here!!!
End-of-Here
content_regex => undef,
content_descr => undef,
default => 'no',
},
'start_cron' => {
applies_to_systems => 1,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
!!!descriptive text missing here!!!
End-of-Here
content_regex => undef,
content_descr => undef,
default => 'no',
},
'start_dreshal' => {
applies_to_systems => 1,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
!!!descriptive text missing here!!!
End-of-Here
content_regex => undef,
content_descr => undef,
default => 'yes',
},
'start_ntp' => {
applies_to_systems => 1,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
!!!descriptive text missing here!!!
End-of-Here
content_regex => undef,
content_descr => undef,
default => 'initial',
},
'start_nfsv4' => {
applies_to_systems => 1,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
!!!descriptive text missing here!!!
End-of-Here
content_regex => undef,
content_descr => undef,
default => 'no',
},
'start_snmp' => {
applies_to_systems => 1,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
!!!descriptive text missing here!!!
End-of-Here
content_regex => undef,
content_descr => undef,
default => 'no',
},
'start_sshd' => {
applies_to_systems => 1,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
!!!descriptive text missing here!!!
End-of-Here
content_regex => undef,
content_descr => undef,
default => 'yes',
},
'timezone' => {
applies_to_systems => 1,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
textual timezone (e.g. 'Europe/Berlin')
End-of-Here
content_regex => undef,
content_descr => undef,
default => 'Europe/Berlin',
},
'unbootable' => {
applies_to_systems => 0,
applies_to_clients => 1,
description => unshiftHereDoc(<<' End-of-Here'),
specifies whether or not this client is allowed to boot
End-of-Here
content_regex => qr{^(0|1)$},
content_descr => '0: client can boot - 1: client is blocked',
default => '0',
},
);
# and add all plugin attributes, too
OpenSLX::OSPlugin::Roster->addAllStage3AttributesToHash(\%AttributeInfo);
return 1;
}
=item C<getAttrInfo()>
Returns info about all attributes.
=over
=item Return Value
An hash-ref with info about all known attributes.
=back
=cut
sub getAttrInfo
{
my $class = shift;
my $params = shift || {};
$class->_init() if !%AttributeInfo;
if (defined $params->{name}) {
my $attrInfo = $AttributeInfo{$params->{name}};
return if !defined $attrInfo;
return { $params->{name} => $AttributeInfo{$params->{name}} };
}
elsif (defined $params->{scope}) {
my %MatchingAttributeInfo;
my $selectedScope = lc($params->{scope});
foreach my $attr (keys %AttributeInfo) {
my $attrScope = '';
if ($attr =~ m{^(.+?)::}) {
$attrScope = lc($1);
}
if ((!$attrScope && $selectedScope eq 'core')
|| $attrScope eq $selectedScope) {
$MatchingAttributeInfo{$attr} = $AttributeInfo{$attr};
}
}
return \%MatchingAttributeInfo;
}
return \%AttributeInfo;
}
=item C<getStage3Attrs()>
Returns the stage3 attribute names (which apply to systems or clients).
=over
=item Return Value
An array of attribute names.
=back
=cut
sub getStage3Attrs
{
my $class = shift;
$class->_init() if !%AttributeInfo;
return
grep {
$AttributeInfo{$_}->{applies_to_systems}
|| $AttributeInfo{$_}->{applies_to_client}
}
keys %AttributeInfo
}
=item C<getSystemAttrs()>
Returns the attribute names that apply to systems.
=over
=item Return Value
An array of attribute names.
=back
=cut
sub getSystemAttrs
{
my $class = shift;
$class->_init() if !%AttributeInfo;
return
grep { $AttributeInfo{$_}->{"applies_to_systems"} }
keys %AttributeInfo
}
=item C<getClientAttrs()>
Returns the attribute names that apply to clients.
=over
=item Return Value
An array of attribute names.
=back
=cut
sub getClientAttrs
{
my $class = shift;
$class->_init() if !%AttributeInfo;
return
grep { $AttributeInfo{$_}->{"applies_to_clients"} }
keys %AttributeInfo
}
=item C<findProblematicValues()>
Checks if the given stage3 attribute values are allowed (and make sense).
This method returns an array-ref of problems found. If there were no problems,
this methods returns undef.
=cut
sub findProblematicValues
{
my $class = shift;
my $stage3Attrs = shift || {};
my $vendorOSName = shift;
my $installedPlugins = shift;
$class->_init() if !%AttributeInfo;
my @problems;
my %attrsByPlugin;
foreach my $key (sort keys %{$stage3Attrs}) {
my $value = $stage3Attrs->{$key};
if ($key =~ m{^(.+)::.+?$}) {
my $pluginName = $1;
if ($installedPlugins
&& !grep { $_->{plugin_name} eq $pluginName } @$installedPlugins) {
# avoid checking attributes of plugins that are not installed
next;
}
$attrsByPlugin{$pluginName} ||= {};
$attrsByPlugin{$pluginName}->{$key} = $value;
}
# undefined values are always allowed
next if !defined $value;
# check the value against the regex of the attribute (if any)
my $attrInfo = $AttributeInfo{$key};
if (!$attrInfo) {
push @problems, _tr('attribute "%s" is unknown!', $key);
next;
}
my $regex = $attrInfo->{content_regex};
if ($regex && $value !~ $regex) {
push @problems, _tr(
"the value '%s' for attribute %s is not allowed.\nAllowed values are: %s",
$value, $key, $attrInfo->{content_descr}
);
}
}
# if no vendorOS-name has been provided or there are no plugins installed,
# we can't do any further checks
if ($vendorOSName && $installedPlugins) {
# now give each installed plugin a chance to check it's own attributes
# by itself
foreach my $pluginInfo (
sort { $a->{plugin_name} cmp $b->{plugin_name} } @$installedPlugins
) {
my $pluginName = $pluginInfo->{plugin_name};
vlog 2, "checking attrs of plugin: $pluginName\n";
# create & start OSPlugin-engine for vendor-OS and current plugin
my $engine = OpenSLX::OSPlugin::Engine->new;
if (!$engine->initialize($pluginName, $vendorOSName)) {
warn _tr(
'unable to create engine for plugin "%s"!', $pluginName
);
next;
}
$engine->checkStage3AttrValues(
$attrsByPlugin{$pluginName}, \@problems
);
}
}
return if !@problems;
return \@problems;
}
=item C<computeMD5HashOverAllAttrs()>
Returns a MD5 hash representing the list of all attributes (including plugins).
=cut
sub computeMD5HashOverAllAttrs
{
my $class = shift;
$class->_init() if !%AttributeInfo;
my %attrNames;
@attrNames{keys %AttributeInfo} = ();
my $pluginInfo = OpenSLX::OSPlugin::Roster->getAvailablePlugins();
if ($pluginInfo) {
foreach my $pluginName (sort keys %$pluginInfo) {
my $attrInfo
= OpenSLX::OSPlugin::Roster->getPluginAttrInfo($pluginName);
@attrNames{keys %$attrInfo} = ();
}
}
my $attrNamesAsString = join ',', sort keys %attrNames;
return md5_hex($attrNamesAsString);
}
1;
|