Add support for external DNS and DHCP servers
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@15906 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -226,6 +226,9 @@ sub process_request { | ||||
|             return; | ||||
|         } | ||||
|     } | ||||
|     if ($::XCATSITEVALS{externaldns}) { | ||||
|     	$external=1; | ||||
|     } | ||||
|  | ||||
|     if ($help) | ||||
|     { | ||||
| @@ -506,67 +509,70 @@ sub process_request { | ||||
|                 my @nservers = split /[ ,]/,$site_entry; | ||||
|                 $ctx->{dnsupdaters} = \@nservers; | ||||
|         } | ||||
|         if ($zapfiles) { #here, we unlink all the existing files to start fresh | ||||
|             if (xCAT::Utils->isAIX()) | ||||
|             { | ||||
|                 system("/usr/bin/stopsrc -s $service"); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 system("service $service stop"); #named may otherwise hold on to stale journal filehandles | ||||
|             } | ||||
|             my $conf = get_conf(); | ||||
|             unlink $conf; | ||||
|             my $DBDir = get_dbdir(); | ||||
|             foreach (<$DBDir/db.*>) { | ||||
|                 unlink $_; | ||||
|             } | ||||
|         } | ||||
|         #We manipulate local namedconf | ||||
|         $ctx->{dbdir} = get_dbdir(); | ||||
|         $ctx->{zonesdir} = get_zonesdir(); | ||||
|         chmod 0775, $ctx->{dbdir}; # assure dynamic dns can actually execute against the directory | ||||
| 	unless ($external) { | ||||
| 	        if ($zapfiles) { #here, we unlink all the existing files to start fresh | ||||
| 	            if (xCAT::Utils->isAIX()) | ||||
| 	            { | ||||
| 	                system("/usr/bin/stopsrc -s $service"); | ||||
| 	            } | ||||
| 	            else | ||||
| 	            { | ||||
| 	                system("service $service stop"); #named may otherwise hold on to stale journal filehandles | ||||
| 	            } | ||||
| 	            my $conf = get_conf(); | ||||
| 	            unlink $conf; | ||||
| 	            my $DBDir = get_dbdir(); | ||||
| 	            foreach (<$DBDir/db.*>) { | ||||
| 	                unlink $_; | ||||
| 	            } | ||||
| 	        } | ||||
| 	        #We manipulate local namedconf | ||||
| 	        $ctx->{dbdir} = get_dbdir(); | ||||
| 	        $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);  | ||||
| 	        update_zones($ctx); | ||||
|  | ||||
|         # check if named is active before update dns records. | ||||
|         if (xCAT::Utils->isAIX()) | ||||
|         { | ||||
|             my $cmd = "/usr/bin/lssrc -s $service |grep active"; | ||||
|             my @output=xCAT::Utils->runcmd($cmd, 0); | ||||
|             if ($::RUNCMD_RC != 0) | ||||
|             { | ||||
|                 system("/usr/bin/startsrc -s $service"); | ||||
|                 xCAT::SvrUtils::sendmsg("Starting named complete", $callback); | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             my $cmd = "service $service status|grep running"; | ||||
|             my @output=xCAT::Utils->runcmd($cmd, 0); | ||||
|             if ($::RUNCMD_RC != 0) | ||||
|             { | ||||
|                 system("service $service start"); | ||||
|                 xCAT::SvrUtils::sendmsg("Starting named complete", $callback); | ||||
|             } | ||||
|         } | ||||
| 	        # check if named is active before update dns records. | ||||
| 	        if (xCAT::Utils->isAIX()) | ||||
| 	        { | ||||
| 	            my $cmd = "/usr/bin/lssrc -s $service |grep active"; | ||||
| 	            my @output=xCAT::Utils->runcmd($cmd, 0); | ||||
| 	            if ($::RUNCMD_RC != 0) | ||||
| 	            { | ||||
| 	                system("/usr/bin/startsrc -s $service"); | ||||
| 	                xCAT::SvrUtils::sendmsg("Starting named complete", $callback); | ||||
| 	            } | ||||
| 	        } | ||||
| 	        else | ||||
| 	        { | ||||
| 	            my $cmd = "service $service status|grep running"; | ||||
| 	            my @output=xCAT::Utils->runcmd($cmd, 0); | ||||
| 	            if ($::RUNCMD_RC != 0) | ||||
| 	            { | ||||
| 	                system("service $service start"); | ||||
| 	                xCAT::SvrUtils::sendmsg("Starting named complete", $callback); | ||||
| 	            } | ||||
| 	        } | ||||
|          | ||||
|         if ($ctx->{restartneeded}) { | ||||
|             xCAT::SvrUtils::sendmsg("Restarting $service", $callback); | ||||
|  | ||||
|         if (xCAT::Utils->isAIX()) | ||||
|         { | ||||
|             system("/usr/bin/stopsrc -s $service"); | ||||
|             system("/usr/bin/startsrc -s $service"); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             system("service $service stop"); | ||||
|             system("service $service start"); | ||||
|         } | ||||
|             xCAT::SvrUtils::sendmsg("Restarting named complete", $callback); | ||||
|         } | ||||
| 	        if ($ctx->{restartneeded}) { | ||||
| 	            xCAT::SvrUtils::sendmsg("Restarting $service", $callback); | ||||
| 	 | ||||
| 	        if (xCAT::Utils->isAIX()) | ||||
| 	        { | ||||
| 	            system("/usr/bin/stopsrc -s $service"); | ||||
| 	            system("/usr/bin/startsrc -s $service"); | ||||
| 	        } | ||||
| 	        else | ||||
| 	        { | ||||
| 	            system("service $service stop"); | ||||
| 	            system("service $service start"); | ||||
| 	        } | ||||
| 	            xCAT::SvrUtils::sendmsg("Restarting named complete", $callback); | ||||
| 		} | ||||
| 	         | ||||
| 	} | ||||
|     } else { | ||||
|         unless ($ctx->{privkey}) { | ||||
|             xCAT::SvrUtils::sendmsg([1,"Unable to update DNS due to lack of credentials in passwd to communicate with remote server"], $callback); | ||||
|   | ||||
| @@ -525,11 +525,13 @@ sub addnode | ||||
|  | ||||
|             print $omshell "create\n"; | ||||
|             print $omshell "close\n"; | ||||
|             unless (grep /#definition for host $node aka host $hostname/, @dhcpconf) | ||||
|             { | ||||
|                 push @dhcpconf, | ||||
|                      "#definition for host $node aka host $hostname can be found in the dhcpd.leases file (typically /var/lib/dhcpd/dhcpd.leases)\n"; | ||||
|             } | ||||
|     	    unless ($::XCATSITEVALS{externaldhcpservers}) {  | ||||
| 	            unless (grep /#definition for host $node aka host $hostname/, @dhcpconf) | ||||
| 	            { | ||||
| 	                push @dhcpconf, | ||||
| 	                     "#definition for host $node aka host $hostname can be found in the dhcpd.leases file (typically /var/lib/dhcpd/dhcpd.leases)\n"; | ||||
|             	} | ||||
| 	    } | ||||
|         } | ||||
|         $count = $count + 2; | ||||
|     } | ||||
| @@ -982,7 +984,8 @@ sub process_request | ||||
|    my $dhcplockfd; | ||||
|    open($dhcplockfd,">","/tmp/xcat/dhcplock"); | ||||
|    flock($dhcplockfd,LOCK_EX); | ||||
|    if (grep /^-n$/, @{$req->{arg}}) | ||||
|    if ($::XCATSITEVALS{externaldhcpservers}) { #do nothing if remote dhcpservers at this point | ||||
|    } elsif (grep /^-n$/, @{$req->{arg}}) | ||||
|     { | ||||
|         if (-e $dhcpconffile) | ||||
|         { | ||||
| @@ -1388,9 +1391,15 @@ sub process_request | ||||
|             print $omshell "key " | ||||
|                 . $ent->{username} . " \"" | ||||
|                 . $ent->{password} . "\"\n"; | ||||
| 	    if ($::XCATSITEVALS{externaldhcpservers}) { | ||||
| 	    	print $omshell "server $::XCATSITEVALS{externaldhcpservers}\n"; | ||||
| 	    } | ||||
|             print $omshell "connect\n"; | ||||
|             if ($usingipv6) { | ||||
|                 open($omshell6, "|/usr/bin/omshell > /dev/null"); | ||||
| 	    	if ($::XCATSITEVALS{externaldhcpservers}) { | ||||
| 		    	print $omshell "server $::XCATSITEVALS{externaldhcpservers}\n"; | ||||
| 		    } | ||||
|                 print $omshell6 "port 7912\n"; | ||||
|                 print $omshell6 "key " | ||||
|                     . $ent->{username} . " \"" | ||||
| @@ -1472,7 +1481,7 @@ sub process_request | ||||
|         } | ||||
|     } | ||||
|     writeout(); | ||||
|     if ($restartdhcp) { | ||||
|     if (not $::XCATSITEVALS{externaldhcpservers} and $restartdhcp) { | ||||
|         if ( $^O eq 'aix') | ||||
|         { | ||||
|             restart_dhcpd_aix(); | ||||
| @@ -1626,6 +1635,7 @@ sub putmyselffirst { | ||||
| } | ||||
| sub addnet6 | ||||
| { | ||||
|     if ($::XCATSITEVALS{externaldhcpservers}) { return; } | ||||
|     my $netentry = shift; | ||||
|     my $net = $netentry->{net}; | ||||
|     my $iface = $netentry->{iface}; | ||||
| @@ -1719,6 +1729,7 @@ sub addnet6 | ||||
| } | ||||
| sub addnet | ||||
| { | ||||
|     if ($::XCATSITEVALS{externaldhcpservers}) { return; } | ||||
|     my $net  = shift; | ||||
|     my $mask = shift; | ||||
|     my $nic; | ||||
| @@ -2130,6 +2141,7 @@ sub gen_aix_net | ||||
|  | ||||
| sub addnic | ||||
| { | ||||
|     if ($::XCATSITEVALS{externaldhcpservers}) { return; } | ||||
|     my $nic        = shift; | ||||
|     my $conf       = shift; | ||||
|     my $firstindex = 0; | ||||
| @@ -2167,6 +2179,7 @@ sub addnic | ||||
|  | ||||
| sub writeout | ||||
| { | ||||
|     if ($::XCATSITEVALS{externaldhcpservers}) { return; } | ||||
|  | ||||
| 	# add the new entries to the dhcp config file | ||||
|     my $targ; | ||||
| @@ -2220,6 +2233,7 @@ sub writeout | ||||
| } | ||||
|  | ||||
| sub newconfig6 { | ||||
|     if ($::XCATSITEVALS{externaldhcpservers}) { return; } | ||||
|     #phase 1, basic working | ||||
|     #phase 2, ddns too, evaluate other stuff from dhcpv4 as applicable | ||||
|     push @dhcp6conf, "#xCAT generated dhcp configuration\n"; | ||||
| @@ -2256,6 +2270,7 @@ sub newconfig6 { | ||||
|  | ||||
| sub newconfig | ||||
| { | ||||
|     if ($::XCATSITEVALS{externaldhcpservers}) { return; } | ||||
|     return newconfig_aix() if ( $^O eq 'aix'); | ||||
|  | ||||
|     # This function puts a standard header in and enough to make omapi work. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user