summaryrefslogtreecommitdiffstats
path: root/config-db/OpenSLX/DBSchema.pm
blob: 801f50a9e11d6df0b7c664c083e01d9d3030cc0f (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
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
# 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/
# -----------------------------------------------------------------------------
# DBSchema.pm
#	- provides database schema of the OpenSLX config-db.
# -----------------------------------------------------------------------------
package OpenSLX::DBSchema;

use strict;
use warnings;

our (@ISA, @EXPORT, $VERSION);

use Exporter;
$VERSION = 0.2;
@ISA = qw(Exporter);

@EXPORT = qw(
	$DbSchema %DbSchemaHistory %AttributeInfo
);

our ($DbSchema, %DbSchemaHistory, %AttributeInfo);


use OpenSLX::Basics;

use POSIX qw(locale_h);
my $lang = setlocale(LC_MESSAGES);
my $country = $lang =~ m[^\w\w_(\w\w)] ? lc($1) : 'us';

################################################################################
### DB-schema definition
### 	This hash-ref describes the current OpenSLX configuration database 
###		schema.
###		Each table is defined by a list of column descriptions (and optionally
###		a list of default values).
### 	A column description is simply the name of the column followed by ':'
### 	followed by the data type description. The following data types are
### 	currently supported:
### 		b		=> boolean (providing the values 1 and 0 only)
### 		i		=> integer (32-bit, signed)
### 		s.20	=> string, followed by length argument (in this case: 20)
### 		pk		=> primary key (integer)
### 		fk		=> foreign key (integer)
################################################################################

$DbSchema = {
	'version' => $VERSION,
	'tables' => {
		'client' => {
			# a client is a PC booting via network
			'cols' => [
				'id:pk',			# primary key
				'name:s.128',		# official name of PC (e.g. as given by sticker
									# on case)
				'mac:s.20',			# MAC of NIC used for booting
				'boot_type:s.20',	# type of remote boot procedure (PXE, ...)
				'unbootable:b',		# unbootable clients simply won't boot
				'kernel_params:s.128',	# client-specific kernel-args (e.g. console)
				'comment:s.1024',	# internal comment (optional, for admins)
			],
			'vals' => [
				{	# add default client
					'id'         => 0,
					'name'       => '<<<default>>>',
					'comment'    => 'internal client that holds default values',
					'unbootable' => 0,
				},
			],
		},
		'client_attr' => {
			# attributes of clients
			'cols' => [
				'id:pk',			# primary key
				'client_id:fk',		# foreign key to client
				'name:s.128',		# attribute name
				'value:s.255',		# attribute value
			],
		},
		'client_system_ref' => {
			# clients referring to the systems they should offer for booting
			'cols' => [
				'client_id:fk',		# foreign key
				'system_id:fk',		# foreign key
			],
		},
		'export' => {
			# an export describes a vendor-OS "wrapped" in some kind of exporting
			# format (NFS or NBD-squash). This represents the rootfs that the
			# clients will see.
			'cols' => [
				'id:pk',			# primary key
				'name:s.64',		# unique name of export, is automatically
									# constructed like this:
									#   <vendor-os-name>-<export-type>
				'vendor_os_id:fk',	# foreign key
				'comment:s.1024',	# internal comment (optional, for admins)
				'type:s.10',		# 'nbd', 'nfs', ...
				'server_ip:s.16',	# IP of exporting server, if empty the
									# boot server will be used
				'port:i',			# some export types need to use a specific
									# port for each incarnation, if that's the
									# case you can specify it here
				'uri:s.255',		# path to export (squashfs or NFS-path), if
									# empty it will be auto-generated by
									# config-demuxer
			],
		},
		'global_info' => {
			# a home for global counters and other info
			'cols' => [
				'id:s.32',			# key
				'value:s.128',		# value
			],
			'vals' => [
				{	# add nbd-server-port
					'id' => 'next-nbd-server-port',
					'value' => '5000',
				},
			],
		},
		'groups' => {
			# a group encapsulates a set of clients as one entity, managing
			# a group-specific attribute set. All the different attribute
			# sets a client inherits via group membership are folded into
			# one resulting attribute set with respect to each group's priority.
			'cols' => [
				'id:pk',			# primary key
				'name:s.128',		# name of group
				'priority:i',		# priority, used for order in group-list
									# (from 0-highest to 99-lowest)
				'comment:s.1024',	# internal comment (optional, for admins)
			],
		},
		'group_attr' => {
			# attributes of groups
			'cols' => [
				'id:pk',			# primary key
				'group_id:fk',		# foreign key to group
				'name:s.128',		# attribute name
				'value:s.255',		# attribute value
			],
		},
		'group_client_ref' => {
			# groups referring to their clients
			'cols' => [
				'group_id:fk',		# foreign key
				'client_id:fk',		# foreign key
			],
		},
		'group_system_ref' => {
			# groups referring to the systems each of their clients should
			# offer for booting
			'cols' => [
				'group_id:fk',		# foreign key
				'system_id:fk',		# foreign key
			],
		},
		'meta' => {
			# information about the database as such
			'cols' => [
				'schema_version:s.5',	# schema-version currently implemented by DB
			],
			'vals' => [
				{
					'schema_version' => $DbSchema->{'version'},
				},
			],
		},
		'system' => {
			# a system describes one bootable instance of an export, it
			# represents a selectable line in the PXE boot menu of all the
			# clients associated with this system
			'cols' => [
				'id:pk',			# primary key
				'export_id:fk',		# foreign key
				'name:s.64',		# unique name of system, is automatically
									# constructed like this:
									#   <vendor-os-name>-<export-type>-<kernel>
				'label:s.64',		# name visible to user (pxe-label)
									# if empty, this will be autocreated from
									# the name
				'kernel:s.128',		# path to kernel file, relative to /boot
				'kernel_params:s.512',	# kernel-param string for pxe
				'hidden:b',				# hidden systems won't be offered for booting
				'comment:s.1024',	# internal comment (optional, for admins)
			],
			'vals' => [
				{	# add default system
					'id' => 0,
					'name' => '<<<default>>>',
					'hidden' => 1,
					'comment' => 'internal system that holds default values',
				},
			],
		},
		'system_attr' => {
			# attributes of systems
			'cols' => [
				'id:pk',			# primary key
				'system_id:fk',		# foreign key to system
				'name:s.128',		# attribute name
				'value:s.255',		# attribute value
			],
			'vals' => [
				# attributes of default system
				{
					'system_id' => 0,
					'name' => 'automnt_dir',
					'value' => '',
				},
				{
					'system_id' => 0,
					'name' => 'automnt_src',
					'value' => '',
				},
				{
					'system_id' => 0,
					'name' => 'country',
					'value' => "$country",
				},
				{
					'system_id' => 0,
					'name' => 'dm_allow_shutdown',
					'value' => 'user',
				},
				{
					'system_id' => 0,
					'name' => 'hw_graphic',
					'value' => '',
				},
				{
					'system_id' => 0,
					'name' => 'hw_monitor',
					'value' => '',
				},
				{
					'system_id' => 0,
					'name' => 'hw_mouse',
					'value' => '',
				},
				{
					'system_id' => 0,
					'name' => 'late_dm',
					'value' => 'no',
				},
				{
					'system_id' => 0,
					'name' => 'netbios_workgroup',
					'value' => 'slx-network',
				},
				{
					'system_id' => 0,
					'name' => 'nis_domain',
					'value' => '',
				},
				{
					'system_id' => 0,
					'name' => 'nis_servers',
					'value' => '',
				},
				{
					'system_id' => 0,
					'name' => 'ramfs_fsmods',
					'value' => '',
				},
				{
					'system_id' => 0,
					'name' => 'ramfs_miscmods',
					'value' => '',
				},
				{
					'system_id' => 0,
					'name' => 'ramfs_nicmods',
					'value' 
						=> 'forcedeth e1000 e100 tg3 via-rhine r8169 pcnet32',
				},
				{
					'system_id' => 0,
					'name' => 'ramfs_screen',
					'value' => '',
				},
				{
					'system_id' => 0,
					'name' => 'sane_scanner',
					'value' => '',
				},
				{
					'system_id' => 0,
					'name' => 'scratch',
					'value' => '',
				},
				{
					'system_id' => 0,
					'name' => 'slxgrp',
					'value' => '',
				},
				{
					'system_id' => 0,
					'name' => 'start_alsasound',
					'value' => 'yes',
				},
				{
					'system_id' => 0,
					'name' => 'start_atd',
					'value' => 'no',
				},
				{
					'system_id' => 0,
					'name' => 'start_cron',
					'value' => 'no',
				},
				{
					'system_id' => 0,
					'name' => 'start_dreshal',
					'value' => 'yes',
				},
				{
					'system_id' => 0,
					'name' => 'start_ntp',
					'value' => 'initial',
				},
				{
					'system_id' => 0,
					'name' => 'start_nfsv4',
					'value' => 'no',
				},
				{
					'system_id' => 0,
					'name' => 'start_printer',
					'value' => 'no',
				},
				{
					'system_id' => 0,
					'name' => 'start_samba',
					'value' => 'may',
				},
				{
					'system_id' => 0,
					'name' => 'start_snmp',
					'value' => 'no',
				},
				{
					'system_id' => 0,
					'name' => 'start_sshd',
					'value' => 'yes',
				},
				{
					'system_id' => 0,
					'name' => 'start_syslog',
					'value' => 'yes',
				},
				{
					'system_id' => 0,
					'name' => 'start_x',
					'value' => 'yes',
				},
				{
					'system_id' => 0,
					'name' => 'start_xdmcp',
					'value' => 'kdm',
				},
				{
					'system_id' => 0,
					'name' => 'tex_enable',
					'value' => 'no',
				},
				{
					'system_id' => 0,
					'name' => 'timezone',
					'value' => 'Europe/Berlin',
				},
				{
					'system_id' => 0,
					'name' => 'tvout',
					'value' => 'no',
				},
				{
					'system_id' => 0,
					'name' => 'vmware',
					'value' => 'no',
				},
			],
		},
		'vendor_os' => {
			# a vendor-OS describes a folder containing an operating system as
			# provided by the vendor (a.k.a. unchanged and thus updatable)
			'cols' => [
				'id:pk',			# primary key
				'name:s.48',		# structured name of OS installation
									# (e.g. suse-9.3-kde, debian-3.1-ppc,
									# suse-10.2-cloned-from-kiwi).
									# This is used as the folder name for the
									# corresponding stage1, too.
				'comment:s.1024',	# internal comment (optional, for admins)
				'clone_source:s.255',	# if vendor-OS was cloned, this contains
										# the rsync-URI pointing to the original
			],
		},
	},
};

################################################################################
###
### Load the available AttrInfo-modules and build a hash containing info about
### all known attributes from the data contained in those modules.
###
################################################################################

%AttributeInfo = ();

my $libPath = "$openslxConfig{'base-path'}/lib";
foreach my $module (glob("$libPath/OpenSLX/AttrInfo/*.pm")) {
	next if $module !~ m{/([^/]+)\.pm$};
	my $class = "OpenSLX::AttrInfo::$1";
	vlog(2, "loading attr-info from module '$module'");
	my $instance = instantiateClass($class);
	my $attrInfo = $instance->AttrInfo();
	foreach my $attr (keys %$attrInfo) {
		$AttributeInfo{$attr} = $attrInfo->{$attr};
	}
}

1;