From 13fa0118b647e8d84b645f3624f3b2b8b8e08c10 Mon Sep 17 00:00:00 2001 From: ertaozh Date: Thu, 28 Jul 2016 04:31:31 -0400 Subject: [PATCH 1/2] Deal with the scenario that more than 1 nic connecting to the provisioning network --- xCAT-server/lib/xcat/plugins/nodediscover.pm | 33 +++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/nodediscover.pm b/xCAT-server/lib/xcat/plugins/nodediscover.pm index 93d461fd0..8d2b57d0c 100644 --- a/xCAT-server/lib/xcat/plugins/nodediscover.pm +++ b/xCAT-server/lib/xcat/plugins/nodediscover.pm @@ -246,6 +246,8 @@ sub process_request { my $mactab = xCAT::Table->new("mac", -create => 1); my @ifinfo; my %usednames; + my %usednames_for_net; + my @hostnames_to_update = (); my %bydriverindex; my $forcenic = 0; #-1 is force skip, 0 is use default behavior, 1 is force to be declared even if hosttag is skipped to do so foreach (@{ $request->{mac} }) { @@ -283,10 +285,20 @@ sub process_request { my $ipn = unpack("N", inet_aton($ip)); my $mask = 2**$netbits - 1 << (32 - $netbits); my $netn = inet_ntoa(pack("N", $ipn & $mask)); - my $hosttag = gethosttag($node, $netn, @ifinfo[1], \%usednames); + my $hosttag; + if ($usednames_for_net{$netn}) { + $hosttag = $usednames_for_net{$netn}; + if ($hosttag eq $node) { + $hosttag .= "-$ifinfo[1]"; + push @hostnames_to_update, $hosttag; + } + } else { + $hosttag = gethosttag($node, $netn, @ifinfo[1], \%usednames); + } print Dumper($hosttag) . "\n"; if ($hosttag) { $usednames{$hosttag} = 1; + $usednames_for_net{$netn} = $hosttag; if ($hosttag eq $node) { $macstring .= $currmac . "|"; } else { @@ -308,6 +320,25 @@ sub process_request { } $macstring =~ s/\|\z//; $mactab->setNodeAttribs($node, { mac => $macstring }); + if (scalar @hostnames_to_update) { + my $hosttab = xCAT::Table->new('hosts'); + if ($hosttab) { + my ($ent) = $hosttab->getNodeAttribs($node, ['hostnames']); + if ($ent and $ent->{hostnames}) { + my @hostnames_array = split /,/, $ent->{hostnames}; + push @hostnames_to_update,@hostnames_array; + } + my %allhostnames = map { $_=>1 } @hostnames_to_update; + my $hostnames = join(",", (keys %allhostnames)); + $hosttab->setNodeAttribs($node, { hostnames => $hostnames }); + $hosttab->commit(); + } + my %request = ( + command => ['makehosts'], + node => [$node] + ); + $doreq->(\%request); + } my %request = ( command => ['makedhcp'], node => [$node] From 4efa05ddb5fe181f9a54113d1d1c7b0b6fb66c8d Mon Sep 17 00:00:00 2001 From: ertaozh Date: Sun, 31 Jul 2016 22:58:47 -0400 Subject: [PATCH 2/2] Deal with hostname which is alias of the predefined node --- xCAT-server/lib/xcat/plugins/nodediscover.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/nodediscover.pm b/xCAT-server/lib/xcat/plugins/nodediscover.pm index 8d2b57d0c..e992f6d0e 100644 --- a/xCAT-server/lib/xcat/plugins/nodediscover.pm +++ b/xCAT-server/lib/xcat/plugins/nodediscover.pm @@ -285,15 +285,15 @@ sub process_request { my $ipn = unpack("N", inet_aton($ip)); my $mask = 2**$netbits - 1 << (32 - $netbits); my $netn = inet_ntoa(pack("N", $ipn & $mask)); - my $hosttag; - if ($usednames_for_net{$netn}) { - $hosttag = $usednames_for_net{$netn}; - if ($hosttag eq $node) { - $hosttag .= "-$ifinfo[1]"; + my $hosttag = gethosttag($node, $netn, @ifinfo[1], \%usednames); + unless ($hosttag) { + my $nettagname = $usednames_for_net{$netn}; + # For nics not in the install network, don't deal with them if not an avaliable hostname get + # In case another nic in install network get a hosttag other than nodename, need to compare the IP address they can convert to + if ($nettagname and (inet_aton($nettagname) eq inet_aton($node))) { + $hosttag = "$node-$ifinfo[1]"; push @hostnames_to_update, $hosttag; } - } else { - $hosttag = gethosttag($node, $netn, @ifinfo[1], \%usednames); } print Dumper($hosttag) . "\n"; if ($hosttag) {