From 50f1d0be005174b05032c34ae9e251377e3b3ef5 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Thu, 4 Sep 2008 19:36:55 +0000 Subject: * turned the client fields 'boot_type','unbootable' and 'kernel_params' as well as the system fields 'kernel_params' and 'hidden' into attributes * added client-only attribute 'boot_uri' which will soon be evaluated by the preboot-cd boot environment git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@2205 95ad53e4-c205-0410-b2fa-d234c58c8868 --- config-db/OpenSLX/AttributeRoster.pm | 122 +++++++++++++++++-------------- config-db/OpenSLX/ConfigDB.pm | 58 ++++++++++++--- config-db/OpenSLX/DBSchema.pm | 136 +++++++++++++++++++++++------------ config-db/t/12-system.t | 6 +- config-db/t/13-client.t | 7 +- 5 files changed, 211 insertions(+), 118 deletions(-) (limited to 'config-db') diff --git a/config-db/OpenSLX/AttributeRoster.pm b/config-db/OpenSLX/AttributeRoster.pm index ac5c9bd4..3c359e82 100644 --- a/config-db/OpenSLX/AttributeRoster.pm +++ b/config-db/OpenSLX/AttributeRoster.pm @@ -59,6 +59,33 @@ sub _init 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-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 => qr{^(pxe|preboot-cd)$}, + content_descr => '"pxe" or "preboot-cd"', + 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, @@ -69,6 +96,36 @@ sub _init 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 => '', + }, 'ramfs_fsmods' => { applies_to_systems => 1, applies_to_clients => 0, @@ -99,17 +156,6 @@ sub _init content_descr => 'a space-separated list of NIC modules', default => 'forcedeth e1000 e100 tg3 via-rhine r8169 pcnet32', }, -# TODO: check if we still need this, as it is not being used anywhere -# 'sane_scanner' => { -# 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 => '', -# }, 'scratch' => { applies_to_systems => 1, applies_to_clients => 1, @@ -120,28 +166,6 @@ sub _init content_descr => undef, default => '', }, -# TODO: check if we still need this, as it is not being used anywhere -# 'slxgrp' => { -# 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 => '', -# }, -# TODO: check if we still need this, as it is not being used anywhere -# 'start_alsasound' => { -# 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_atd' => { applies_to_systems => 1, applies_to_clients => 1, @@ -192,28 +216,6 @@ sub _init content_descr => undef, default => 'no', }, -# TODO: check if we still need this, as it is not being used anywhere -# 'start_printer' => { -# 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', -# }, -# TODO: check if we still need this, as it is not being used anywhere -# 'start_samba' => { -# 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 => 'may', -# }, 'start_snmp' => { applies_to_systems => 1, applies_to_clients => 1, @@ -244,6 +246,16 @@ sub _init 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 diff --git a/config-db/OpenSLX/ConfigDB.pm b/config-db/OpenSLX/ConfigDB.pm index b781a08a..3cffb74b 100644 --- a/config-db/OpenSLX/ConfigDB.pm +++ b/config-db/OpenSLX/ConfigDB.pm @@ -306,28 +306,66 @@ sub synchronizeAttributesWithDB return if !$defaultSystem; # fetch all known attributes from attribute roster and merge these - # into the existing attributes of the default system + # into the existing attributes of the default system and client my $attrInfo = OpenSLX::AttributeRoster->getAttrInfo(); - # add new attributes to default system - my @newAttrs - = grep { !exists $defaultSystem->{attrs}->{$_} } keys %{$attrInfo}; - foreach my $attr (@newAttrs) { + # add new system attributes to default system + my @newSystemAttrs + = grep { + $attrInfo->{$_}->{applies_to_systems} + && !exists $defaultSystem->{attrs}->{$_} + } keys %{$attrInfo}; + foreach my $attr (@newSystemAttrs) { $defaultSystem->{attrs}->{$attr} = $attrInfo->{$attr}->{default}; } - # remove unknown attributes from default system - my @unknownAttrs - = grep { !exists $attrInfo->{$_} } keys %{$defaultSystem->{attrs}}; - foreach my $unknownAttr (@unknownAttrs) { + # remove unknown system attributes from default system + my @unknownSystemAttrs + = grep { + !exists $attrInfo->{$_} + || !$attrInfo->{$_}->{applies_to_systems} + } keys %{$defaultSystem->{attrs}}; + foreach my $unknownAttr (@unknownSystemAttrs) { delete $defaultSystem->{attrs}->{$unknownAttr}; } # now write back the updated default system if necessary - if (@newAttrs || @unknownAttrs) { + if (@newSystemAttrs || @unknownSystemAttrs) { return if !$self->changeSystem(0, $defaultSystem); } + my $defaultClient = $self->fetchClientByID(0); + return if !$defaultClient; + + # add new client attributes to default client (deal only with + # attributes that are client-only) + my @newClientAttrs + = grep { + $attrInfo->{$_}->{applies_to_clients} + && !$attrInfo->{$_}->{applies_to_systems} + && !exists $defaultClient->{attrs}->{$_} + } keys %{$attrInfo}; + foreach my $attr (@newClientAttrs) { + $defaultClient->{attrs}->{$attr} = $attrInfo->{$attr}->{default}; + } + + # remove unknown client attributes from default client (deal only with + # attributes that are client-only) + my @unknownClientAttrs + = grep { + !exists $attrInfo->{$_} + || !$attrInfo->{$_}->{applies_to_clients} + || $attrInfo->{$_}->{applies_to_systems} + } keys %{$defaultClient->{attrs}}; + foreach my $unknownAttr (@unknownClientAttrs) { + delete $defaultClient->{attrs}->{$unknownAttr}; + } + + # now write back the updated default client if necessary + if (@newClientAttrs || @unknownClientAttrs) { + return if !$self->changeClient(0, $defaultClient); + } + return 1; } diff --git a/config-db/OpenSLX/DBSchema.pm b/config-db/OpenSLX/DBSchema.pm index 24f46fc6..976d9c6a 100644 --- a/config-db/OpenSLX/DBSchema.pm +++ b/config-db/OpenSLX/DBSchema.pm @@ -34,7 +34,7 @@ use OpenSLX::Basics; ### fk => foreign key (integer) ################################################################################ -my $VERSION = 0.33; +my $VERSION = 0.34; my $DbSchema = { 'version' => $VERSION, @@ -43,20 +43,16 @@ my $DbSchema = { # 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 + '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) + 'mac:s.20', # MAC of NIC used for booting + 'comment:s.1024', # internal comment (optional, for admins) ], 'vals' => [ { # add default client 'id' => 0, 'name' => '<<>>', 'comment' => 'internal client that holds default values', - 'unbootable' => 0, }, ], }, @@ -64,16 +60,16 @@ my $DbSchema = { # 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_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 + 'client_id:fk', # foreign key + 'system_id:fk', # foreign key ], }, 'export' => { @@ -85,12 +81,12 @@ my $DbSchema = { 'name:s.64', # unique name of export, is automatically # constructed like this: # - - 'vendor_os_id:fk', # foreign key - 'comment:s.1024', # internal comment (optional, for admins) + '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 + '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: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 @@ -101,8 +97,8 @@ my $DbSchema = { 'global_info' => { # a home for global counters and other info 'cols' => [ - 'id:s.32', # key - 'value:s.128', # value + 'id:s.32', # key + 'value:s.128', # value ], 'vals' => [ { # add nbd-server-port @@ -118,34 +114,34 @@ my $DbSchema = { # 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 + '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) + '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_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_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 + 'group_id:fk', # foreign key + 'system_id:fk', # foreign key ], }, 'installed_plugin' => { @@ -153,8 +149,8 @@ my $DbSchema = { # vendor-OS 'cols' => [ 'id:pk', # primary key - 'vendor_os_id:fk', # foreign key - 'plugin_name:s.64', # name of installed plugin + 'vendor_os_id:fk', # foreign key + 'plugin_name:s.64', # name of installed plugin # (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 @@ -166,8 +162,8 @@ my $DbSchema = { 'cols' => [ 'id:pk', # primary key 'installed_plugin_id:fk', # foreign key to installed plugin - 'name:s.128', # attribute name - 'value:s.255', # attribute value + 'name:s.128', # attribute name + 'value:s.255', # attribute value ], }, 'meta' => { @@ -192,24 +188,21 @@ my $DbSchema = { # clients associated with this system 'cols' => [ 'id:pk', # primary key - 'export_id:fk', # foreign key + 'export_id:fk', # foreign key 'name:s.64', # unique name of system, is automatically # constructed like this: # -- - 'label:s.64', # name visible to user (pxe-label) + '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 + 'kernel:s.128', # path to kernel file, relative to /boot 'description:s.512',# visible description (for PXE TEXT) - 'comment:s.1024', # internal comment (optional, for admins) + 'comment:s.1024', # internal comment (optional, for admins) ], 'vals' => [ { # add default system 'id' => 0, 'name' => '<<>>', - 'hidden' => 1, 'comment' => 'internal system that holds default values', }, ], @@ -218,9 +211,9 @@ my $DbSchema = { # 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 + 'system_id:fk', # foreign key to system + 'name:s.128', # attribute name + 'value:s.255', # attribute value ], }, 'vendor_os' => { @@ -233,8 +226,8 @@ my $DbSchema = { # 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 + '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 ], }, @@ -744,6 +737,59 @@ sub _schemaUpgradeDBFrom ] ); + return 1; + }, + 0.34 => sub { + my $metaDB = shift; + + # turn client fields 'boot_type', 'kernel_params' and 'unbootable' + # into attributes: + foreach my $client ($metaDB->fetchClientByFilter()) { + my $attrs = $metaDB->fetchClientAttrs($client->{id}); + $attrs->{boot_type} = $client->{boot_type} || 'pxe'; + $attrs->{kernel_params_client} = $client->{kernel_params}; + $attrs->{unbootable} = $client->{unbootable}; + $metaDB->setClientAttrs($client->{id}, $attrs); + } + $metaDB->schemaDropColumns( + 'client', + [ + 'boot_type', + 'kernel_params', + 'unbootable', + ], + [ + 'id:pk', + 'name:s.128', + 'mac:s.20', + 'comment:s.1024', + ] + ); + + # turn system fields 'hidden' and 'kernel_params' into attributes: + foreach my $system ($metaDB->fetchSystemByFilter()) { + my $attrs = $metaDB->fetchSystemAttrs($system->{id}); + $attrs->{hidden} = $system->{hidden}; + $attrs->{kernel_params} = $system->{kernel_params}; + $metaDB->setSystemAttrs($system->{id}, $attrs); + } + $metaDB->schemaDropColumns( + 'system', + [ + 'hidden', + 'kernel_params', + ], + [ + 'id:pk', + 'export_id:fk', + 'name:s.64', + 'label:s.64', + 'kernel:s.128', + 'description:s.512', + 'comment:s.1024', + ] + ); + return 1; }, ); diff --git a/config-db/t/12-system.t b/config-db/t/12-system.t index 7ed740a9..d10c6a76 100644 --- a/config-db/t/12-system.t +++ b/config-db/t/12-system.t @@ -61,7 +61,6 @@ my $fullSystem = { 'export_id' => 3, 'comment' => 'nuff said', 'label' => 'BlingBling System - really kuul!', - 'kernel_params' => 'debug=3 console=ttyS1', 'hidden' => '1', 'attrs' => { 'automnt_dir' => 'a', @@ -71,6 +70,7 @@ my $fullSystem = { 'hw_graphic' => 'e', 'hw_monitor' => 'f', 'hw_mouse' => 'g', + 'kernel_params' => 'debug=3 console=ttyS1', 'late_dm' => 'h', 'netbios_workgroup' => 'i', 'nis_domain' => 'j', @@ -117,7 +117,6 @@ is($system3->{kernel}, 'vmlinuz-2.6.22.13-0.3-default', 'sys is($system3->{export_id}, '3', 'system 3 - export_id'); is($system3->{comment}, 'nuff said', 'system 3 - comment'); is($system3->{label}, 'BlingBling System - really kuul!', 'system 3 - label'); -is($system3->{kernel_params}, 'debug=3 console=ttyS1', 'system 3 - kernel_params'); is($system3->{hidden}, '1', 'system 3 - hidden'); is($system3->{attrs}->{automnt_dir}, 'a', 'system 3 - attr automnt_dir'); is($system3->{attrs}->{automnt_src}, 'b', 'system 3 - attr automnt_src'); @@ -126,6 +125,7 @@ is($system3->{attrs}->{dm_allow_shutdown}, 'd', 'system 3 - attr dm is($system3->{attrs}->{hw_graphic}, 'e', 'system 3 - attr hw_graphic'); is($system3->{attrs}->{hw_monitor}, 'f', 'system 3 - attr hw_monitor'); is($system3->{attrs}->{hw_mouse}, 'g', 'system 3 - attr hw_mouse'); +is($system3->{attrs}->{kernel_params}, 'debug=3 console=ttyS1', 'system 3 - attr kernel_params'); is($system3->{attrs}->{late_dm}, 'h', 'system 3 - attr late_dm'); is($system3->{attrs}->{netbios_workgroup}, 'i', 'system 3 - attr netbios_workgroup'); is($system3->{attrs}->{nis_domain}, 'j', 'system 3 - attr nis_domain'); @@ -178,9 +178,9 @@ is($system1->{export_id}, '1', 'system 1 - export_id'); is($system1->{kernel}, 'vmlinuz', 'system 1 - kernel'); is($system1->{comment}, '', 'system 1 - comment'); is($system1->{label}, 'sys-1', 'system 1 - label'); -is($system1->{kernel_params}, undef, 'system 1 - kernel_params'); is($system1->{hidden}, undef, 'system 1 - hidden'); is(keys %{$system1->{attrs}}, 3, 'system 1 - attribute count'); +is($system1->{attrs}->{kernel_params}, undef, 'system 1 - attr kernel_params'); is($system1->{attrs}->{ramfs_fsmods}, 'squashfs', 'system 1 - attr ramfs_fsmods'); is($system1->{attrs}->{ramfs_nicmods}, 'e1000 forcedeth r8169', 'system 1 - attr ramfs_nicmods'); is($system1->{attrs}->{start_sshd}, 'yes', 'system 1 - attr start_sshd'); diff --git a/config-db/t/13-client.t b/config-db/t/13-client.t index c9c77db9..c618d5db 100644 --- a/config-db/t/13-client.t +++ b/config-db/t/13-client.t @@ -60,7 +60,6 @@ my $fullClient = { 'name' => 'cli-nr-3', 'mac' => '01:02:03:04:05:03', 'comment' => 'nuff said', - 'kernel_params' => 'debug=3 console=ttyS1', 'unbootable' => '0', 'boot_type' => 'pxe', 'attrs' => { @@ -71,6 +70,7 @@ my $fullClient = { 'hw_graphic' => 'e', 'hw_monitor' => 'f', 'hw_mouse' => 'g', + 'kernel_params_client' => 'debug=3 console=ttyS1', 'late_dm' => 'h', 'netbios_workgroup' => 'i', 'nis_domain' => 'j', @@ -113,7 +113,6 @@ is($client3->{name}, 'cli-nr-3', 'client 3 - name'); is($client3->{mac}, '01:02:03:04:05:03', 'client 3 - mac'); is($client3->{comment}, 'nuff said', 'client 3 - comment'); is($client3->{boot_type}, 'pxe', 'client 3 - boot_type'); -is($client3->{kernel_params}, 'debug=3 console=ttyS1', 'client 3 - kernel_params'); is($client3->{unbootable}, '0', 'client 3 - unbootable'); is($client3->{attrs}->{automnt_dir}, 'a', 'client 3 - attr automnt_dir'); is($client3->{attrs}->{automnt_src}, 'b', 'client 3 - attr automnt_src'); @@ -122,6 +121,7 @@ is($client3->{attrs}->{dm_allow_shutdown}, 'd', 'client 3 - attr dm is($client3->{attrs}->{hw_graphic}, 'e', 'client 3 - attr hw_graphic'); is($client3->{attrs}->{hw_monitor}, 'f', 'client 3 - attr hw_monitor'); is($client3->{attrs}->{hw_mouse}, 'g', 'client 3 - attr hw_mouse'); +is($client3->{attrs}->{kernel_params_client}, 'debug=3 console=ttyS1', 'client 3 - attr kernel_params_client'); is($client3->{attrs}->{late_dm}, 'h', 'client 3 - attr late_dm'); is($client3->{attrs}->{netbios_workgroup}, 'i', 'client 3 - attr netbios_workgroup'); is($client3->{attrs}->{nis_domain}, 'j', 'client 3 - attr nis_domain'); @@ -169,10 +169,7 @@ ok( is($client1->{id}, 1, 'client 1 - id'); is($client1->{name}, 'cli-1', 'client 1 - name'); is($client1->{mac}, '01:02:03:04:05:01', 'client 1 - mac'); -is($client1->{unbootable}, undef, 'client 1 - unbootable'); is($client1->{comment}, '', 'client 1 - comment'); -is($client1->{boot_type}, 'pxe', 'client 1 - boot_type'); -is($client1->{kernel_params}, undef, 'client 1 - kernel_params'); is(keys %{$client1->{attrs}}, 3, 'client 1 - attribute count'); is($client1->{attrs}->{slxgrp}, 'slxgrp', 'client 1 - attr slxgrp'); is($client1->{attrs}->{start_snmp}, 'no', 'client 1 - attr start_snmp'); -- cgit v1.2.3-55-g7522