Support dns master/slave configuration
This commit is contained in:
parent
91347e0a9b
commit
f7812a2517
2
perl-xCAT/xCAT/Schema.pm
Normal file → Executable file
2
perl-xCAT/xCAT/Schema.pm
Normal file → Executable file
@ -845,7 +845,7 @@ servicenode => {
|
||||
table_desc => 'List of all Service Nodes and services that will be set up on the Service Node.',
|
||||
descriptions => {
|
||||
node => 'The hostname of the service node as known by the Management Node.',
|
||||
nameserver => 'Do we set up DNS on this service node? Valid values:yes or 1, no or 0. If yes, creates named.conf file with forwarding to the management node and starts named. If no or 0, it does not change the current state of the service. ',
|
||||
nameserver => 'Do we set up DNS on this service node? Valid values: 2, 1, no or 0. If 2, creates named.conf as dns slave, using the management node as dns master, and starts named. If 1, creates named.conf file with forwarding to the management node and starts named. If no or 0, it does not change the current state of the service. ',
|
||||
dhcpserver => 'Do we set up DHCP on this service node? Not supported on AIX. Valid values:yes or 1, no or 0. If yes, runs makedhcp -n. If no or 0, it does not change the current state of the service. ',
|
||||
tftpserver => 'Do we set up TFTP on this service node? Not supported on AIX. Valid values:yes or 1, no or 0. If yes, configures and starts atftp. If no or 0, it does not change the current state of the service. ',
|
||||
nfsserver => 'Do we set up file services (HTTP,FTP,or NFS) on this service node? For AIX will only setup NFS, not HTTP or FTP. Valid values:yes or 1, no or 0.If no or 0, it does not change the current state of the service. ',
|
||||
|
2
perl-xCAT/xCAT/ServiceNodeUtils.pm
Normal file → Executable file
2
perl-xCAT/xCAT/ServiceNodeUtils.pm
Normal file → Executable file
@ -163,6 +163,8 @@ sub isServiceReq
|
||||
if (($value eq "1") || ($value eq "YES"))
|
||||
{
|
||||
$servicehash->{$service} = "1";
|
||||
} elsif ($value eq "2") {
|
||||
$servicehash->{$service} = "2";
|
||||
} else {
|
||||
$servicehash->{$service} = "0";
|
||||
}
|
||||
|
26
xCAT-server/lib/xcat/plugins/AAsn.pm
Normal file → Executable file
26
xCAT-server/lib/xcat/plugins/AAsn.pm
Normal file → Executable file
@ -144,10 +144,10 @@ sub init_plugin
|
||||
|
||||
}
|
||||
}
|
||||
if ($servicelist->{"nameserver"} == 1)
|
||||
if (($servicelist->{"nameserver"} == 1) || ($servicelist->{"nameserver"} == 2) )
|
||||
{
|
||||
|
||||
&setup_DNS(); # setup DNS
|
||||
&setup_DNS($servicelist); # setup DNS
|
||||
|
||||
}
|
||||
if ($servicelist->{"nfsserver"} == 1)
|
||||
@ -687,6 +687,7 @@ sub setup_FTP
|
||||
#-----------------------------------------------------------------------------
|
||||
sub setup_DNS
|
||||
{
|
||||
my $srvclist = shift;
|
||||
|
||||
my $XCATROOT = "/opt/xcat"; # default
|
||||
|
||||
@ -695,9 +696,24 @@ sub setup_DNS
|
||||
$XCATROOT = $ENV{'XCATROOT'};
|
||||
}
|
||||
|
||||
# setup the named.conf file
|
||||
system("$XCATROOT/sbin/makenamed.conf");
|
||||
|
||||
if ($srvclist->{"nameserver"} == 1)
|
||||
{
|
||||
# setup the named.conf file as dns forwarding/caching
|
||||
system("$XCATROOT/sbin/makenamed.conf");
|
||||
}
|
||||
else
|
||||
{
|
||||
# setup the named.conf file as dns slave
|
||||
my $cmdref;
|
||||
$cmdref->{command}->[0] = "makedns";
|
||||
$cmdref->{arg}->[0] = "-s";
|
||||
$cmdref->{cwd}->[0] = "/opt/xcat/sbin";
|
||||
no strict "refs";
|
||||
my $modname = "ddns";
|
||||
${"xCAT_plugin::" . $modname . "::"}{process_request}
|
||||
->($cmdref, \&xCAT::Client::handle_response);
|
||||
}
|
||||
|
||||
# turn DNS on
|
||||
|
||||
my $distro = xCAT::Utils->osver();
|
||||
|
123
xCAT-server/lib/xcat/plugins/ddns.pm
Normal file → Executable file
123
xCAT-server/lib/xcat/plugins/ddns.pm
Normal file → Executable file
@ -207,6 +207,7 @@ sub process_request {
|
||||
my $help;
|
||||
my $deletemode=0;
|
||||
my $external=0;
|
||||
my $slave=0;
|
||||
if ($request->{arg}) {
|
||||
$hadargs=1;
|
||||
@ARGV=@{$request->{arg}};
|
||||
@ -218,6 +219,7 @@ sub process_request {
|
||||
'n|new' => \$zapfiles,
|
||||
'd|delete' => \$deletemode,
|
||||
'e|external' => \$external,
|
||||
's|slave' => \$slave,
|
||||
'h|help' => \$help,
|
||||
)) {
|
||||
#xCAT::SvrUtils::sendmsg([1,"TODO: makedns Usage message"], $callback);
|
||||
@ -493,6 +495,16 @@ sub process_request {
|
||||
$ctx->{forwarders}=\@forwarders;
|
||||
}
|
||||
|
||||
my @slave_ips;
|
||||
my $dns_slaves = get_dns_slave();
|
||||
if (scalar @$dns_slaves) {
|
||||
foreach my $slave_hn (@$dns_slaves) {
|
||||
my $slave_ip = xCAT::NetworkUtils->getipaddr($slave_hn);
|
||||
push @slave_ips, $slave_ip;
|
||||
}
|
||||
$ctx->{slaves}=\@slave_ips;
|
||||
}
|
||||
|
||||
$ctx->{zonestotouch}->{$ctx->{domain}}=1;
|
||||
foreach (@networks) {
|
||||
if ($_->{domain}) {
|
||||
@ -570,9 +582,13 @@ sub process_request {
|
||||
$ctx->{zonesdir} = get_zonesdir();
|
||||
chmod 0775, $ctx->{dbdir}; # assure dynamic dns can actually execute against the directory
|
||||
|
||||
update_namedconf($ctx);
|
||||
update_zones($ctx);
|
||||
|
||||
update_namedconf($ctx, $slave);
|
||||
|
||||
unless ($slave)
|
||||
{
|
||||
update_zones($ctx);
|
||||
}
|
||||
|
||||
if ($ctx->{restartneeded}) {
|
||||
xCAT::SvrUtils::sendmsg("Restarting $service", $callback);
|
||||
|
||||
@ -628,6 +644,11 @@ sub process_request {
|
||||
}
|
||||
}
|
||||
|
||||
if ($slave)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
# check if named is active before update dns records.
|
||||
if (xCAT::Utils->isAIX())
|
||||
{
|
||||
@ -843,6 +864,7 @@ sub update_zones {
|
||||
|
||||
sub update_namedconf {
|
||||
my $ctx = shift;
|
||||
my $slave = shift;
|
||||
my $namedlocation = get_conf();
|
||||
my $nameconf;
|
||||
my @newnamed;
|
||||
@ -872,6 +894,20 @@ sub update_namedconf {
|
||||
push @newnamed,"\t\t".$_.";\n";
|
||||
}
|
||||
push @newnamed,"\t};\n";
|
||||
} elsif ($ctx->{slaves} and $line =~ /allow-transfer {/) {
|
||||
push @newnamed,"\tallow-transfer \{\n";
|
||||
$skip=1;
|
||||
foreach (@{$ctx->{slaves}}) {
|
||||
push @newnamed,"\t\t".$_.";\n";
|
||||
}
|
||||
push @newnamed,"\t};\n";
|
||||
} elsif ($ctx->{slaves} and $line =~ /also-notify {/) {
|
||||
push @newnamed,"\talso-notify \{\n";
|
||||
$skip=1;
|
||||
foreach (@{$ctx->{slaves}}) {
|
||||
push @newnamed,"\t\t".$_.";\n";
|
||||
}
|
||||
push @newnamed,"\t};\n";
|
||||
} elsif ($skip) {
|
||||
if ($line =~ /};/) {
|
||||
$skip = 0;
|
||||
@ -975,23 +1011,52 @@ sub update_namedconf {
|
||||
}
|
||||
push @newnamed,"\t};\n";
|
||||
}
|
||||
if ($slave) {
|
||||
push @newnamed,"\tallow-transfer { any; };\n";
|
||||
} else {
|
||||
if ($ctx->{slaves}) {
|
||||
push @newnamed,"\tnotify yes;\n";
|
||||
push @newnamed,"\tallow-transfer {\n";
|
||||
foreach (@{$ctx->{slaves}}) {
|
||||
push @newnamed,"\t\t$_;\n";
|
||||
}
|
||||
push @newnamed,"\t};\n";
|
||||
push @newnamed,"\talso-notify {\n";
|
||||
foreach (@{$ctx->{slaves}}) {
|
||||
push @newnamed,"\t\t$_;\n";
|
||||
}
|
||||
push @newnamed,"\t};\n";
|
||||
}
|
||||
}
|
||||
push @newnamed,"};\n\n";
|
||||
}
|
||||
unless ($gotkey) {
|
||||
unless ($ctx->{privkey}) { #need to generate one
|
||||
$ctx->{privkey} = encode_base64(genpassword(32));
|
||||
chomp($ctx->{privkey});
|
||||
}
|
||||
push @newnamed,"key xcat_key {\n","\talgorithm hmac-md5;\n","\tsecret \"".$ctx->{privkey}."\";\n","};\n\n";
|
||||
$ctx->{restartneeded}=1;
|
||||
|
||||
unless ($slave) {
|
||||
unless ($gotkey) {
|
||||
unless ($ctx->{privkey}) { #need to generate one
|
||||
$ctx->{privkey} = encode_base64(genpassword(32));
|
||||
chomp($ctx->{privkey});
|
||||
}
|
||||
push @newnamed,"key xcat_key {\n","\talgorithm hmac-md5;\n","\tsecret \"".$ctx->{privkey}."\";\n","};\n\n";
|
||||
$ctx->{restartneeded}=1;
|
||||
}
|
||||
}
|
||||
|
||||
my $cmd = "grep '^nameserver' /etc/resolv.conf | awk '{print $2}'";
|
||||
my @output=xCAT::Utils->runcmd($cmd, 0);
|
||||
my $zone;
|
||||
foreach $zone (keys %{$ctx->{zonestotouch}}) {
|
||||
if ($didzones{$zone}) { next; }
|
||||
$ctx->{restartneeded}=1; #have to add a zone, a restart will be needed
|
||||
push @newnamed,"zone \"$zone\" in {\n","\ttype master;\n","\tallow-update {\n","\t\tkey xcat_key;\n";
|
||||
foreach (@{$ctx->{dnsupdaters}}) {
|
||||
push @newnamed,"\t\t$_;\n";
|
||||
push @newnamed,"zone \"$zone\" in {\n";
|
||||
if ($slave) {
|
||||
push @newnamed,"\ttype slave;\n";
|
||||
push @newnamed,"\tmasters { $output[0]; };\n";
|
||||
} else {
|
||||
push @newnamed,"\ttype master;\n","\tallow-update {\n","\t\tkey xcat_key;\n";
|
||||
foreach (@{$ctx->{dnsupdaters}}) {
|
||||
push @newnamed,"\t\t$_;\n";
|
||||
}
|
||||
}
|
||||
if ($zone =~ /IN-ADDR\.ARPA/) {
|
||||
my $net = $zone;
|
||||
@ -1009,9 +1074,15 @@ sub update_namedconf {
|
||||
foreach $zone (keys %{$ctx->{adzones}}) {
|
||||
if ($didzones{$zone}) { next; }
|
||||
$ctx->{restartneeded}=1; #have to add a zone, a restart will be needed
|
||||
push @newnamed,"zone \"$zone\" in {\n","\ttype master;\n","\tallow-update {\n","\t\tkey xcat_key;\n";
|
||||
foreach (@{$ctx->{adservers}}) {
|
||||
push @newnamed,"\t\t$_;\n";
|
||||
push @newnamed,"zone \"$zone\" in {\n";
|
||||
if ($slave) {
|
||||
push @newnamed,"\ttype slave;\n";
|
||||
push @newnamed,"\tmasters { $output[0]; };\n";
|
||||
} else {
|
||||
push @newnamed,"\ttype master;\n","\tallow-update {\n","\t\tkey xcat_key;\n";
|
||||
foreach (@{$ctx->{adservers}}) {
|
||||
push @newnamed,"\t\t$_;\n";
|
||||
}
|
||||
}
|
||||
my $zfilename = $zone;
|
||||
#$zfilename =~ s/\..*//;
|
||||
@ -1303,4 +1374,24 @@ sub makedns_usage
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub get_dns_slave
|
||||
{
|
||||
# get all service nodes with servicenode.nameserver=2
|
||||
my @sns;
|
||||
my @slaves;
|
||||
my $sntab = xCAT::Table->new('servicenode');
|
||||
my @ents = $sntab->getAllAttribs('node', 'nameserver');
|
||||
|
||||
foreach my $sn (@ents)
|
||||
{
|
||||
if ($sn->{'nameserver'} == 2)
|
||||
{
|
||||
push @sns, $sn->{'node'};
|
||||
}
|
||||
}
|
||||
|
||||
@slaves = xCAT::NodeRange::noderange(join(',',@sns));
|
||||
return \@slaves;
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user