From c4c5fc621681cbb2a8d160b4a265debe4469c5d8 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 22 Feb 2018 11:08:04 -0500 Subject: [PATCH] Allow restricting service node pools Service node pools would go as far as the network allowed. Honor the servicenode attribute to limit visibility to the service nodes that are relevant and any owner of a dynamic range. Also allow execution if the dhcp server is not running (e.g. shutting down dhcp server on the master node to allow only the service nodes to provide services). --- xCAT-server/lib/xcat/plugins/dhcp.pm | 51 +++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index 13ce40aa4..ab73461ec 100644 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -990,7 +990,8 @@ sub check_options #my @output = xCAT::Utils->runcmd("service $DHCPSERVER status", -1); #if ($::RUNCMD_RC != 0) { # not running my $ret = 0; - $ret = xCAT::Utils->checkservicestatus("dhcp"); + # If dhcp is shut off on a master node, then it may still be valid... for now + #$ret = xCAT::Utils->checkservicestatus("dhcp"); if ($ret != 0) { my $rsp = {}; @@ -1302,6 +1303,53 @@ sub preprocess_request my $reqcopy = {%$req}; $reqcopy->{'_xcatdest'} = $entries[0]; push @requests, $reqcopy; + } else { + my $nettab = xCAT::Table->new('networks'); + my @nets = $nettab->getAllAttribs('dhcpserver'); + my @dhcpservers; + foreach (@nets) { + if ($_->{dhcpserver}) { + push @dhcpservers, $_->{dhcpserver}; + } + } + my %localnodehash; + my %dispatchhash; + my $nrtab = xCAT::Table->new('noderes'); + my $nrents = $nrtab->getNodesAttribs($req->{node}, [qw(tftpserver servicenode)]); + foreach my $node (@{ $req->{node} }) + { + my $nodeserver; + my $tent = $nrents->{$node}->[0]; #$nrtab->getNodeAttribs($node, ['tftpserver']); + if ($tent) { $nodeserver = $tent->{tftpserver} } + unless ($tent and $tent->{tftpserver}) + { + $tent = $nrents->{$node}->[0]; #$nrtab->getNodeAttribs($node, ['servicenode']); + if ($tent) { $nodeserver = $tent->{servicenode} } + } + if ($nodeserver) + { + foreach my $ns (split /,/, $nodeserver) { + $dispatchhash{$ns}->{$node} = 1; + } + } + $localnodehash{$node} = 1; + } + my @requests; + my $reqc = {%$req}; + foreach my $dhcps (@dhcpservers) { + my $reqcopy = {%$req}; #deep copy + $reqcopy->{'_xcatdest'} = $dhcps; + $reqcopy->{node} = [ keys %localnodehash ]; + if (scalar(@{ $reqcopy->{node} })) { push @requests, $reqcopy } + } + foreach my $dtarg (keys %dispatchhash) + { #iterate dispatch targets + my $reqcopy = {%$req}; #deep copy + $reqcopy->{'_xcatdest'} = $dtarg; + $reqcopy->{node} = [ keys %{ $dispatchhash{$dtarg} } ]; + push @requests, $reqcopy; + } + return \@requests; } foreach my $s (@snlist) @@ -1317,6 +1365,7 @@ sub preprocess_request } + #print Dumper(@requests); return \@requests;