diff options
Diffstat (limited to 'perl-install/drakcluster')
-rw-r--r-- | perl-install/drakcluster/server_conf.pm | 103 | ||||
-rw-r--r-- | perl-install/drakcluster/server_conf_drakx.pm | 58 |
2 files changed, 161 insertions, 0 deletions
diff --git a/perl-install/drakcluster/server_conf.pm b/perl-install/drakcluster/server_conf.pm new file mode 100644 index 000000000..46a7f9394 --- /dev/null +++ b/perl-install/drakcluster/server_conf.pm @@ -0,0 +1,103 @@ +package drakcluster::server_conf; + +use strict; +use common; + +sub read() { + my %main = getVarsFromSh("$::prefix/etc/clusterserver.conf"); + \%main; +} + +sub done { + my ($conf, $network_interfaces) = @_; + set_automatic_fields($conf, $network_interfaces); + setVarsInSh("$::prefix/etc/clusterserver.conf", $conf); +} + +my %automatic_when_single_network = ( + COMPUTE_INTERFACE => 'ADMIN_INTERFACE', + COMPUTENODENAME => 'NODENAME', + DOMAINCOMP => 'DOMAINNAME', +); + +sub set_automatic_fields { + my ($conf, $network_interfaces) = @_; + if (@$network_interfaces <= 2) { + $conf->{$_} = $conf->{$automatic_when_single_network{$_}} foreach keys %automatic_when_single_network; + } +} + +sub fields { + my ($conf, $network_interfaces, $default_conf) = @_; + my $current_conf = { %$conf }; + put_in_hash($conf, $default_conf); + my @l = ( + [ NODENAME => 'Node name (Administration network)' , check => \&check_non_empty ], + [ COMPUTENODENAME => 'Node Name (Computing network)', check => \&check_non_empty ], + [ STARTNODE => 'IP of the first node', check => \&check_number ], + [ FINISHNODE => 'IP of the last node', check => sub { &check_number || $conf->{STARTNODE} >= $conf->{FINISHNODE} && N("\"The First node\" must have an IP lower than \"the last node\"") } ], + [ ADMIN_INTERFACE => 'Administration Network Interface', list => $network_interfaces ], + [ EXTERNAL_INTERFACE => 'External Network Interface', list => $network_interfaces ], + [ COMPUTE_INTERFACE => 'Computing Network Interface', list => $network_interfaces ], + [ NTPSERVER => N("NTP Server IP Address"), check => sub { &check_ip || check_default(@_, $default_conf->{NTPSERVER}, $current_conf->{NTPSERVER}) } ], + [ DOMAINNAME => N("Administration node domain name"), check => sub { check_default(@_, $default_conf->{DOMAINNAME}, $current_conf->{DOMAINNAME}) } ], + [ NISDOMAINNAME => N("NIS domain name"), check => \&check_non_empty ], + [ DOMAINCOMP => N("Computing domain name"), check => \&check_non_empty ], + [ IPOFFORWARDER => 'IP address of your external DNS', check => sub { $_[0] && check_ip(@_) || check_default(@_, $default_conf->{IPOFFORWARDER}) } ], + [ DNSKEY => 'DNS server dnskey', check => \&check_non_empty ], + [ ADDSEARCH => 'ADDSEARCH ' . N("Domain name of your external network") ], + [ USERADMIN => 'PBS administrator user name', check => \&check_non_empty ], + [ ORIGIN => 'ORIGIN ' . N("Domain that locally posted mails appears to come from"), check => sub { check_default(@_, $default_conf->{DOMAINNAME}, $current_conf->{DOMAINNAME}) } ], + ); + + if (@$network_interfaces <= 2) { + @l = grep { !$automatic_when_single_network{$_->[0]} } @l; + } + + map { + my ($field, $label, %opts) = @$_; + $opts{val} = \$conf->{$field}; + $opts{label} = $label; + \%opts; + } @l; +} + +sub check_field { + my ($in, $field) = @_; + warn "checking $field->{label}\n"; + $field->{check} or return 1; + my $err = $field->{check}->(${$field->{val}}, $field->{label}, warn => $in); + $in->ask_warn('', $err) if $err && $err ne 'already_displayed'; + !$err; +} + + +# CHECKERS ##################################################################### +sub is_ip { + $::isInstall ? &network::network::is_ip : &cluster_fonction_common::is_ip; +} + +sub check_non_empty { + my ($val, $txt) = @_; + !$val && N("Field \"%s\" must not be empty", $txt); +} +sub check_number { + my ($val, $txt) = @_; + $val !~ /^\d+$/ && N("Field \"%s\" must be a number", $txt); +} +sub check_ip { + my ($val, $txt) = @_; + !is_ip($val) && N("Field \"%s\" must be a valid IP address", $txt); +} + +sub check_default { + my ($val, $txt, $warn, $in, $default_val, $pre_val) = @_; + if ($default_val && $val ne $default_val && $val ne $pre_val) { + if ($warn eq 'warn') { + return '' if $in->ask_okcancel('', N("You changed the default value of field \"%s\". Are you sure to do this?", $txt)); + } + 'already_displayed'; + } else { + ''; + } +} diff --git a/perl-install/drakcluster/server_conf_drakx.pm b/perl-install/drakcluster/server_conf_drakx.pm new file mode 100644 index 000000000..07e27b95b --- /dev/null +++ b/perl-install/drakcluster/server_conf_drakx.pm @@ -0,0 +1,58 @@ +package drakcluster::server_conf_drakx; + +use strict; + +use run_program; +use detect_devices; +use network; +use common; +use drakcluster::server_conf; + +# for compatibility +sub drakcluster::server_conf::N { &_ } +sub N { &_ } + +sub generate_rndc() { + run_program::rooted($::prefix, 'rndc-confgen', '-a'); + first(cat_("$::prefix/etc/rndc.key") =~ /secret "(\S*)";/); +} + +sub default_conf { + my ($o) = @_; + { + DOMAINNAME => $o->{netc}{DOMAINNAME}, + NTPSERVER => $o->{intf}{eth0}{IPADDR}, + IPOFFORWARDER => network::dnsServers($o->{netc}), + ORIGIN => $o->{netc}{DOMAINNAME}, + }; +} + +my $force_size; +sub my_gtk::show { + my ($o) = @_; + $o->{rwindow}->set_usize($::windowwidth * 0.9, $::windowheight * 0.9) if $force_size; + $force_size = 0; + $o->{window}->show; + $o->{rwindow}->show; +} + +sub main { + my ($o) = @_; + my @network_interfaces = detect_devices::getNet(); + + my $conf = drakcluster::server_conf::read(); + $conf->{DNSKEY} ||= generate_rndc(); + + my @fields = drakcluster::server_conf::fields($conf, \@network_interfaces, default_conf($o)); + + $force_size = 1; + $o->ask_from('', N("Cluster Server Configuration"), + [ @fields ], complete => sub { + my $i = eval { find_index { !drakcluster::server_conf::check_field($o, $_) } @fields }; + $@ ? 0 : (1, $i); + }) or return; + + drakcluster::server_conf::done($conf, \@network_interfaces); +} + +1; |