From 8713caef5be39e87e199d51499ee58edbb7e967e Mon Sep 17 00:00:00 2001 From: lissav Date: Thu, 30 Apr 2009 16:52:55 +0000 Subject: [PATCH] handle multiple addresses and aliases git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@3278 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- .../lib/xcat/plugins/makeknownhosts.pm | 63 ++++++++++++------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/makeknownhosts.pm b/xCAT-server/lib/xcat/plugins/makeknownhosts.pm index 33a4bac34..c1d19aea4 100644 --- a/xCAT-server/lib/xcat/plugins/makeknownhosts.pm +++ b/xCAT-server/lib/xcat/plugins/makeknownhosts.pm @@ -201,7 +201,7 @@ sub add_known_host my ($node, $callback) = @_; my $cmd; my $line; - my $ip_address; + my @ip_address; my $home = xCAT::Utils->getHomeDir("root"); my $known_hosts = "$home/.ssh/known_hosts"; @@ -211,36 +211,55 @@ sub add_known_host my $addrtype; my $length; my @addrs; - if (($hostname, $aliases, $addrtype, $length, @addrs) = - gethostbyname($node)) - { - $ip_address = inet_ntoa($addrs[0]); - } + + # get the key $cmd = "cat $hostkey"; my @output = xCAT::Utils->runcmd($cmd, 0); if ($::RUNCMD_RC != 0) { my $rsp = {}; - $rsp->{data}->[0] = "Could $cmd, cannot create known_hosts"; + $rsp->{data}->[0] = "$cmd failed, cannot build known_hosts file"; xCAT::MsgUtils->message("E", $rsp, $callback, 1); return 1; } - if (defined $hostname) { - chop($output[0]); - $line = "\""; - $line .= "$hostname,$ip_address "; - $line .= $output[0]; - $line .= "\""; - $cmd = "echo $line >> $known_hosts"; - xCAT::Utils->runcmd($cmd, 0); + chop($output[0]); + my $ip_address = ""; + if (($hostname, $aliases, $addrtype, $length, @addrs) = + gethostbyname($node)) + { + foreach my $ipaddr (@addrs) + { + $ip_address .= inet_ntoa($ipaddr); + $ip_address .= ","; + } + } + chop($ip_address); + my @newaliaslist = split (/ /,$aliases); - if ($::RUNCMD_RC != 0) - { - my $rsp = {}; - $rsp->{data}->[0] = "$cmd failed, cannot create known_hosts"; - xCAT::MsgUtils->message("E", $rsp, $callback, 1); - return 1; - } + my $aliaslist=""; + foreach my $entry (@newaliaslist) { + $aliaslist .= "$entry,"; + } + + if (defined $hostname) + { + $line = "\""; + $line .= "$hostname,"; + $line .= "$aliaslist"; + $line .= "$ip_address"; + $line .= " "; + $line .= $output[0]; + $line .= "\""; + $cmd = "echo $line >> $known_hosts"; + xCAT::Utils->runcmd($cmd, 0); + + if ($::RUNCMD_RC != 0) + { + my $rsp = {}; + $rsp->{data}->[0] = "$cmd failed, cannot create known_hosts"; + xCAT::MsgUtils->message("E", $rsp, $callback, 1); + return 1; + } } return 0; }