[pve-devel] [PATCH cluster 2/3] remote_node_ip: replace fallback method with new PVE::Network helper

Thomas Lamprecht t.lamprecht at proxmox.com
Tue May 2 11:51:21 CEST 2017


reduces code reuse
Note that the wantarray check exists in the used helper, so the
return signature of remote_node_ip stayed the same here

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 data/PVE/Cluster.pm | 21 +--------------------
 1 file changed, 1 insertion(+), 20 deletions(-)

diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index f764e8a..2509465 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -1027,26 +1027,7 @@ sub remote_node_ip {
     }
 
     # fallback: try to get IP by other means
-    my ($family, $packed_ip);
-
-    eval {
-	my @res = PVE::Tools::getaddrinfo_all($nodename);
-	$family = $res[0]->{family};
-	$packed_ip = (PVE::Tools::unpack_sockaddr_in46($res[0]->{addr}))[2];
-    };
-
-    if ($@) {
-	die "hostname lookup failed:\n$@" if !$noerr;
-	return undef;
-    }
-
-    my $ip = Socket::inet_ntop($family, $packed_ip);
-    if ($ip =~ m/^127\.|^::1$/) {
-	die "hostname lookup failed - got local IP address ($nodename = $ip)\n" if !$noerr;
-	return undef;
-    }
-
-    return wantarray ? ($ip, $family) : $ip;
+    return PVE::Network::get_ip_from_hostname($nodename, $noerr);
 }
 
 sub get_local_migration_ip {
-- 
2.11.0





More information about the pve-devel mailing list