enhance the dhcp unicast for some specific cases on nameservers and gateway value

This commit is contained in:
immarvin 2014-04-17 03:04:54 -07:00
parent 32a4c828ad
commit 534265abe9
4 changed files with 158 additions and 45 deletions

View File

@ -19,6 +19,7 @@ use File::Path;
use Math::BigInt;
use Socket;
use xCAT::GlobalDef;
use Data::Dumper;
use strict;
use warnings "all";
my $socket6support = eval { require Socket6 };
@ -2028,6 +2029,61 @@ sub getSubnetGateway
}
#-------------------------------------------------------------------------------
=head3 getNodeNameservers
Description:
Get nameservers of specified nodes.
The priority: noderes.nameservers > networks.nameservers > site.nameservers
Arguments:
node: node name list
Returns:
Return a hash ref, of the $nameservers{$node}
undef - Failed to get the nameservers
Globals:
none
Error:
none
Example:
my $nameservers = xCAT::NetworkUtils::getNodeNameservers(\@node);
Comments:
none
=cut
#-------------------------------------------------------------------------------
sub getNodeNameservers{
my $nodes=shift;
if( $nodes =~ /xCAT::NetworkUtils/)
{
$nodes=shift;
}
my @nodelist = @$nodes;
my %nodenameservers;
my $nrtab = xCAT::Table->new('noderes',-create=>0);
my %nrhash = %{$nrtab->getNodesAttribs(\@nodelist,['nameservers'])};
my $nettab = xCAT::Table->new("networks");
my %nethash = xCAT::DBobjUtils->getNetwkInfo( \@nodelist );
my @nameservers = xCAT::TableUtils->get_site_attribute("nameservers");
my $sitenameservers=$nameservers[0];
foreach my $node (@nodelist){
if ($nrhash{$node} and $nrhash{$node}->[0] and $nrhash{$node}->[0]->{nameservers})
{
$nodenameservers{$node}=$nrhash{$node}->[0]->{nameservers};
}elsif($nethash{$node}{nameservers})
{
$nodenameservers{$node}=$nethash{$node}{nameservers};
}elsif($sitenameservers)
{
$nodenameservers{$node}=$sitenameservers;
}
}
return \%nodenameservers;
}
#-------------------------------------------------------------------------------
=head3 getNodeNetworkCfg

View File

@ -641,6 +641,9 @@ sub esxipv6setup {
return 'esxcfg-vmknic -i '.$v6addr.'/64 "Management Network"'." #ESXISTATICV6\n";
}
sub kickstartnetwork {
my $line = "network --onboot=yes --bootproto=";
my $hoststab;
@ -659,18 +662,26 @@ sub kickstartnetwork {
} elsif ($::XCATSITEVALS{managedaddressmode} =~ /static/) {
my ($ipaddr,$hostname,$gateway,$netmask)=xCAT::NetworkUtils->getNodeNetworkCfg($node);
unless($ipaddr) { die "cannot resolve the network configuration of $node"; }
if($gateway eq '<xcatmaster>'){
$gateway = xCAT::NetworkUtils->my_ip_facing($ipaddr);
}
$line .="static --device=$suffix --ip=$ipaddr --netmask=$netmask --gateway=$gateway --hostname=$hostname ";
my $nrtab = xCAT::Table->new('noderes',-create=>0);
unless ($nrtab) { die "noderes table should always exist prior to template processing"; }
my $ent = $nrtab->getNodeAttribs($node,['nameservers'],prefetchcache=>1);
unless ($ent and $ent->{nameservers}) { die "attribute nameservers not set for $node"; }
my @nameserverARR=split (",",$ent->{nameservers});
my %nameservers=%{xCAT::NetworkUtils->getNodeNameservers([$node])};
my @nameserverARR=split (",",$nameservers{$node});
my @nameserversIP;
foreach (@nameserverARR)
{
my ($host,$ip) = xCAT::NetworkUtils->gethostnameandip($_);
my $ip;
if($_ eq '<xcatmaster>'){
$ip = xCAT::NetworkUtils->my_ip_facing($gateway);
}else{
(undef,$ip) = xCAT::NetworkUtils->gethostnameandip($_);
}
push @nameserversIP, $ip;
}
if (scalar @nameserversIP) {
@ -702,19 +713,27 @@ sub yast2network {
my ($ipaddr,$hostname,$gateway,$netmask)=xCAT::NetworkUtils->getNodeNetworkCfg($node);
unless($ipaddr) { die "cannot resolve the network configuration of $node"; }
my $nrtab = xCAT::Table->new('noderes',-create=>0);
unless ($nrtab) { die "noderes table should always exist prior to template processing"; }
my $ent = $nrtab->getNodeAttribs($node,['nameservers'],prefetchcache=>1);
unless ($ent and $ent->{nameservers}) { die "attribute nameservers not set for $node"; }
my @nameserverARR=split (",",$ent->{nameservers});
if($gateway eq '<xcatmaster>'){
$gateway = xCAT::NetworkUtils->my_ip_facing($ipaddr);
}
my %nameservers=%{xCAT::NetworkUtils->getNodeNameservers([$node])};
my @nameserverARR=split (",",$nameservers{$node});
my @nameserversIP;
foreach (@nameserverARR)
{
my ($host,$ip) = xCAT::NetworkUtils->gethostnameandip($_);
my $ip;
if($_ eq '<xcatmaster>'){
$ip = xCAT::NetworkUtils->my_ip_facing($gateway);
}else{
(undef,$ip) = xCAT::NetworkUtils->gethostnameandip($_);
}
push @nameserversIP, $ip;
}
# get the domains for each node - one call for all nodes in hosts file
my $nd = xCAT::NetworkUtils->getNodeDomains([$node]);
my %nodedomains = %$nd;
@ -742,7 +761,7 @@ sub yast2network {
'nameservers' => [
{
'config:type' => 'list',
'nameserver' => @nameserversIP
'nameserver' => [@nameserversIP]
}
],
'hostname' => [
@ -889,6 +908,7 @@ sub yast2network {
$line=$xml->XMLout($networkhash);
}
return $line;
}

View File

@ -1378,8 +1378,10 @@ sub mkinstall
}
if ($::XCATSITEVALS{managedaddressmode} =~ /static/){
my($host,$ip)=xCAT::NetworkUtils->gethostnameandip($instserver);
$instserver=$ip;
unless($instserver eq '!myipfn!'){
my($host,$ip)=xCAT::NetworkUtils->gethostnameandip($instserver);
$instserver=$ip;
}
}
my $httpprefix=$pkgdir;
if ($installroot =~ /\/$/) {
@ -1447,20 +1449,38 @@ sub mkinstall
#to avoid multicast dhcp
if($::XCATSITEVALS{managedaddressmode} =~ /static/){
my ($ipaddr,$hostname,$gateway,$netmask)=xCAT::NetworkUtils->getNodeNetworkCfg($node);
unless($ipaddr) { die "cannot resolve the network configuration of $node"; }
unless($ipaddr) {
$callback->(
{
error => [
"cannot resolve the ip address of $node"
],
errorcode => [1]
}
);
}
if($gateway eq '<xcatmaster>'){
$gateway = xCAT::NetworkUtils->my_ip_facing($ipaddr);
}
$kcmdline .=" ip=$ipaddr netmask=$netmask gateway=$gateway hostname=$hostname ";
my $nrtab = xCAT::Table->new('noderes',-create=>0);
unless ($nrtab) { die "noderes table should always exist prior to template processing"; }
my $ent = $nrtab->getNodeAttribs($node,['nameservers'],prefetchcache=>1);
unless ($ent and $ent->{nameservers}) { die "attribute nameservers not set for $node"; }
my @nameserverARR=split (",",$ent->{nameservers});
my @nameserversIP;
foreach (@nameserverARR)
{
my ($host,$ip) = xCAT::NetworkUtils->gethostnameandip($_);
push @nameserversIP, $ip;
}
my %nameservers=%{xCAT::NetworkUtils->getNodeNameservers([$node])};
my @nameserverARR=split (",",$nameservers{$node});
my @nameserversIP;
foreach (@nameserverARR)
{
my $ip;
if($_ eq '<xcatmaster>'){
$ip = xCAT::NetworkUtils->my_ip_facing($gateway);
}else{
(undef,$ip) = xCAT::NetworkUtils->gethostnameandip($_);
}
push @nameserversIP, $ip;
}
if(scalar @nameserversIP){
$kcmdline .=" dns=".join(",",@nameserversIP);

View File

@ -1076,10 +1076,11 @@ sub mkinstall
$netserver = $ent->{nfsserver};
}
if ($::XCATSITEVALS{managedaddressmode} =~ /static/){
my($host,$ip)=xCAT::NetworkUtils->gethostnameandip($netserver);
$netserver=$ip;
unless($netserver eq '!myipfn!'){
my($host,$ip)=xCAT::NetworkUtils->gethostnameandip($netserver);
$netserver=$ip;
}
}
my $httpprefix = $pkgdir;
@ -1150,20 +1151,36 @@ sub mkinstall
#to avoid multicast dhcp
if($::XCATSITEVALS{managedaddressmode} =~ /static/){
my ($ipaddr,$hostname,$gateway,$netmask)=xCAT::NetworkUtils->getNodeNetworkCfg($node);
unless($ipaddr) { die "cannot resolve the network configuration of $node"; }
$kcmdline .=" hostip=$ipaddr netmask=$netmask gateway=$gateway hostname=$hostname ";
my $nrtab = xCAT::Table->new('noderes',-create=>0);
unless ($nrtab) { die "noderes table should always exist prior to template processing"; }
my $ent = $nrtab->getNodeAttribs($node,['nameservers'],prefetchcache=>1);
unless ($ent and $ent->{nameservers}) { die "attribute nameservers not set for $node"; }
my @nameserverARR=split (",",$ent->{nameservers});
my @nameserversIP;
foreach (@nameserverARR)
{
my ($host,$ip) = xCAT::NetworkUtils->gethostnameandip($_);
push @nameserversIP, $ip;
unless($ipaddr) {
$callback->(
{
error => [
"cannot resolve the ip address of $node"
],
errorcode => [1]
}
);
}
if($gateway eq '<xcatmaster>'){
$gateway = xCAT::NetworkUtils->my_ip_facing($ipaddr);
}
$kcmdline .=" hostip=$ipaddr netmask=$netmask gateway=$gateway hostname=$hostname ";
my %nameservers=%{xCAT::NetworkUtils->getNodeNameservers([$node])};
my @nameserverARR=split (",",$nameservers{$node});
my @nameserversIP;
foreach (@nameserverARR)
{
my $ip;
if($_ eq '<xcatmaster>'){
$ip = xCAT::NetworkUtils->my_ip_facing($gateway);
}else{
(undef,$ip) = xCAT::NetworkUtils->gethostnameandip($_);
}
push @nameserversIP, $ip;
}
if(scalar @nameserversIP){
$kcmdline .=" dns=".join(",",@nameserversIP);