ipv6 fix: use -m flag with makehosts command to generate link local addresses in /etc/hosts

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6255 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
ligc 2010-05-27 07:42:49 +00:00
parent 1c68c2a98c
commit fd11704702

View File

@ -3,6 +3,7 @@ package xCAT_plugin::hosts;
use strict;
use warnings;
use xCAT::Table;
use xCAT::NetworkUtils;
use Data::Dumper;
use File::Copy;
use Getopt::Long;
@ -13,10 +14,11 @@ my @hosts; #Hold /etc/hosts data to be written back
my $LONGNAME;
my $OTHERNAMESFIRST;
my $ADDNAMES;
my $MACTOLINKLOCAL;
my %usage=(
makehosts => "Usage: makehosts <noderange> [-d] [-n] [-l] [-a] [-o]\n makehosts -h",
makehosts => "Usage: makehosts <noderange> [-d] [-n] [-l] [-a] [-o] [-m]\n makehosts -h",
);
sub handled_commands {
return {
@ -144,6 +146,7 @@ sub process_request {
'd' => \$DELNODE,
'o|othernamesfirst' => \$OTHERNAMESFIRST,
'a|adddomaintohostnames' => \$ADDNAMES,
'm|mactolinklocal' => \$MACTOLINKLOCAL,
'l|longnamefirst' => \$LONGNAME,))
{
$callback->({data=>$usage{makehosts}});
@ -199,18 +202,36 @@ sub process_request {
}
if ($req->{node}) {
my $hostscache = $hoststab->getNodesAttribs($req->{node},[qw(ip node hostnames otherinterfaces)]);
foreach(@{$req->{node}}) {
my $ref = $hostscache->{$_}->[0]; #$hoststab->getNodeAttribs($_,[qw(ip node hostnames otherinterfaces)]);
if ($DELNODE) {
delnode $ref->{node},$ref->{ip},$ref->{hostnames},$domain;
} else {
addnode $ref->{node},$ref->{ip},$ref->{hostnames},$domain;
if (defined($ref->{otherinterfaces})){
addotherinterfaces $ref->{node},$ref->{otherinterfaces},$domain;
if ($MACTOLINKLOCAL) {
my $mactab = xCAT::Table->new("mac");
my $machash = $mactab->getNodesAttribs($req->{node},['mac']);
foreach my $node (keys %{$machash})
{
my $mac = $machash->{$node}->[0]->{mac};
if (!$mac) {
next;
}
my $linklocal = xCAT::NetworkUtils->linklocaladdr($mac);
if ($DELNODE) {
delnode $node,$linklocal,$node,$domain;
} else {
addnode $node,$linklocal,$node,$domain;
}
}
}
}
} else {
my $hostscache = $hoststab->getNodesAttribs($req->{node},[qw(ip node hostnames otherinterfaces)]);
foreach(@{$req->{node}}) {
my $ref = $hostscache->{$_}->[0]; #$hoststab->getNodeAttribs($_,[qw(ip node hostnames otherinterfaces)]);
if ($DELNODE) {
delnode $ref->{node},$ref->{ip},$ref->{hostnames},$domain;
} else {
addnode $ref->{node},$ref->{ip},$ref->{hostnames},$domain;
if (defined($ref->{otherinterfaces})){
addotherinterfaces $ref->{node},$ref->{otherinterfaces},$domain;
}
}
} #end foreach
} # end else
} else {
if ($DELNODE) {
return;