2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-06-18 04:10:46 +00:00

add hostname lookup by ip for switchdiscover command

This commit is contained in:
Casandra Qiu
2015-05-21 16:14:50 -04:00
parent 065a97db46
commit 62099a7866

View File

@ -543,9 +543,9 @@ sub nmap_scan {
# If --range options, take iprange, otherwise
# use noderange to discover switches.
##################################################
my $ranges = get_ip_ranges($request);
my $ranges = get_ip_ranges($request);
$ccmd = "/usr/bin/nmap -sn -oX - @$ranges";
$ccmd = "/usr/bin/nmap -sn -oX - @$ranges";
print $ccmd;
my $result = xCAT::Utils->runcmd($ccmd, 0);
if ($::RUNCMD_RC != 0)
@ -629,8 +629,8 @@ sub snmp_scan {
ip : IP address passed by the switch after scan
Returns:
hose: hostname of the switch
if host is empty, format hostname as switch and ip combination
ex: switch-9-114-5-6
if host is empty, try to lookup use ip address, otherwise format hostname
as switch and ip combination. ex: switch-9-114-5-6
=cut
#--------------------------------------------------------------------------------
sub get_hostname {
@ -638,9 +638,12 @@ sub get_hostname {
my $ip = shift;
if ( !$host ) {
my $ip_str = $ip;
$ip_str =~ s/\./\-/g;
$host = "switch-$ip_str";
$host = gethostbyaddr( inet_aton($ip), AF_INET );
if ( !$host ) {
my $ip_str = $ip;
$ip_str =~ s/\./\-/g;
$host = "switch-$ip_str";
}
}
return $host;
}