From 4ea33650c2b9d9d1db69fef6aea365dd427cfd96 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Wed, 29 Jul 2009 17:43:04 +0000 Subject: [PATCH] -Change determinehostname to only strip if required to get a valid node name. If there is no valid nodename to match, the output of hostname is returned verbatim without domain stripping. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@3899 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Utils.pm | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index f7e3d51a5..737289943 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -2697,10 +2697,31 @@ sub determinehostname } $hostname = $thostname[0]; - # strip off domain, if there - my @shorthost = split(/\./, $hostname); + #get all potentially valid abbreviations, and pick the one that is ok + #by 'noderange' + my @hostnamecandidates; + my $nodename; + while ($hostname =~ /\./) { + push @hostnamecandidates,$hostname; + $hostname =~ s/\.[^\.]*//; + } + push @hostnamecandidates,$hostname; + my $checkhostnames = join(',',@hostnamecandidates); + my @validnodenames = xCAT::NodeRange::noderange($checkhostnames); + unless (scalar @validnodenames) { #If the node in question is not in table, take output literrally. + push @validnodenames,$hostnamecandidates[0]; + } + use Data::Dumper; + print Dumper \@validnodenames; + #now, noderange doesn't guarantee the order, so we search the preference order, most to least specific. + foreach (@hostnamecandidates) { + if (grep /^$_$/,@validnodenames) { + $nodename = $_; + last; + } + } my @ips = xCAT::Utils->gethost_ips; - my @hostinfo = (@ips, $shorthost[0]); + my @hostinfo = (@ips, $nodename); return @hostinfo; }