From 1c0f2b5bef5628f809a38e0dcfb08271a3f1eb00 Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Wed, 8 Oct 2014 13:33:23 -0400 Subject: [PATCH] clean up formatting of dhpc.pm --- xCAT-server/lib/xcat/plugins/dhcp.pm | 117 +++++++++++++-------------- 1 file changed, 57 insertions(+), 60 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index e5b919447..fc40e2e57 100755 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -1208,28 +1208,27 @@ sub process_request # if option is query then call listnode for each node and return if ($opt{q}) - { + { # call listnode for each node requested foreach my $node ( @{$req->{node}} ) { listnode($node,$callback); } - return; + return; } # if current node is a servicenode, make sure that it is also a dhcpserver my $isok=1; if (xCAT::Utils->isServiceNode()) { - $isok=0; - my @hostinfo=xCAT::NetworkUtils->determinehostname(); - my %iphash=(); - foreach(@hostinfo) {$iphash{$_}=1;} - my @sn = xCAT::ServiceNodeUtils->getSNList('dhcpserver'); - foreach my $s (@sn) - { - if (exists($iphash{$s})) { - $isok=1; - } - } + $isok=0; + my @hostinfo=xCAT::NetworkUtils->determinehostname(); + my %iphash=(); + foreach(@hostinfo) {$iphash{$_}=1;} + my @sn = xCAT::ServiceNodeUtils->getSNList('dhcpserver'); + foreach my $s (@sn) { + if (exists($iphash{$s})) { + $isok=1; + } + } } if($isok == 0) { #do nothing if it is a service node, but not dhcpserver @@ -1332,39 +1331,35 @@ sub process_request @dhcpconf = (); @dhcp6conf = (); - my $dhcplockfd; - open($dhcplockfd,">","/tmp/xcat/dhcplock"); - flock($dhcplockfd,LOCK_EX); - if ($::XCATSITEVALS{externaldhcpservers}) { #do nothing if remote dhcpservers at this point - } elsif ($opt{n}) - { - if (-e $dhcpconffile) - { - if ($^O eq 'aix') - { - # save NIM aix entries - to be restored later - my $aixconf; - open($aixconf, $dhcpconffile); - if ($aixconf) - { - my $save=0; - while (<$aixconf>) - { - if ($save) { - push @aixcfg, $_; - } + my $dhcplockfd; + open($dhcplockfd,">","/tmp/xcat/dhcplock"); + flock($dhcplockfd,LOCK_EX); + if ($::XCATSITEVALS{externaldhcpservers}) { + # do nothing if remote dhcpservers at this point + } elsif ($opt{n}) { + if (-e $dhcpconffile) { + if ($^O eq 'aix') { + # save NIM aix entries - to be restored later + my $aixconf; + open($aixconf, $dhcpconffile); + if ($aixconf) { + my $save=0; + while (<$aixconf>) { + if ($save) { + push @aixcfg, $_; + } - if ($_ =~ /#Network configuration end\n/) { - $save++; - } - } - close($aixconf); - } - $restartdhcp=1; - @dhcpconf = (); - } + if ($_ =~ /#Network configuration end\n/) { + $save++; + } + } + close($aixconf); + } + $restartdhcp=1; + @dhcpconf = (); + } - my $rsp; + my $rsp; push @{$rsp->{data}}, "Renamed existing dhcp configuration file to $dhcpconffile.xcatbak\n"; xCAT::MsgUtils->message("I", $rsp, $callback); @@ -1400,11 +1395,11 @@ sub process_request @dhcp6conf = (); } } - my $nettab = xCAT::Table->new("networks"); - my @vnets = $nettab->getAllAttribs('net','mgtifname','mask','dynamicrange','nameservers','ddnsdomain', 'domain'); + my $nettab = xCAT::Table->new("networks"); + my @vnets = $nettab->getAllAttribs('net','mgtifname','mask','dynamicrange','nameservers','ddnsdomain', 'domain'); - # get a list of all domains listed in xCAT network defs - # - include the site domain - if any + # get a list of all domains listed in xCAT network defs + # - include the site domain - if any my $nettab = xCAT::Table->new("networks"); my @doms = $nettab->getAllAttribs('domain'); foreach(@doms){ @@ -1416,9 +1411,9 @@ sub process_request # add the site domain if ($site_domain) { - if (!grep(/^$site_domain$/, @alldomains)) { - push (@alldomains, $site_domain); - } + if (!grep(/^$site_domain$/, @alldomains)) { + push (@alldomains, $site_domain); + } } foreach (@vnets) { @@ -1450,18 +1445,19 @@ sub process_request } } - foreach(@vnets){ + foreach(@vnets){ #TODO: v6 relayed networks? - my $n = $_->{net}; - my $if = $_->{mgtifname}; - my $nm = $_->{mask}; + my $n = $_->{net}; + my $if = $_->{mgtifname}; + my $nm = $_->{mask}; if ($if =~ /!remote!/ and $n !~ /:/) { #only take in networks with special interface, but only v4 for now - push @nrn, "$n:$if:$nm"; + push @nrn, "$n:$if:$nm"; } - } + } if ($querynics) - { #Use netstat to determine activenics only when no site ent. - #TODO: IPv6 auto-detect, or just really really insist people define dhcpinterfaces or suffer doom? + { + # Use netstat to determine activenics only when no site ent. + # TODO: IPv6 auto-detect, or just really really insist people define dhcpinterfaces or suffer doom? foreach (@nrn) { my @ent = split /:/; @@ -1496,6 +1492,7 @@ sub process_request my %missingfiles = ( "dhcpd"=>1, "dhcpd6"=>1, "dhcp3-server"=>1 ); foreach $dhcpver ("dhcpd","dhcpd6","dhcp3-server", "isc-dhcp-server") { if (-e "/etc/sysconfig/$dhcpver") { + # for dhcpd, dhcpd6 if ($dhcpver eq "dhcpd") { delete($missingfiles{dhcpd}); delete($missingfiles{"dhcp3-server"}); @@ -1516,7 +1513,7 @@ sub process_request if (/!remote!/) { next; } $ifarg .= " $_"; } - $ifarg =~ s/^ //; + $ifarg = s/\=\" /\=\"/; $ifarg .= "\"\n"; while () {