]> git.proxmox.com Git - pve-storage.git/commitdiff
CephConfig: refactor host port parsing
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 27 Jun 2019 08:43:11 +0000 (10:43 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 27 Jun 2019 14:16:36 +0000 (16:16 +0200)
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/CephConfig.pm

index 3ff49eeecdc77adc7ef5716e59b1c69dbc05ca10..31bb887d56386b8a8bc761009044d61941664966 100644 (file)
@@ -100,6 +100,17 @@ my $ceph_get_key = sub {
     return $secret;
 };
 
+my $get_host = sub {
+    my ($hostport) = @_;
+    my ($host, $port) = PVE::Tools::parse_host_and_port($hostport);
+    if (!defined($host)) {
+       return "";
+    }
+    $port = defined($port) ? ":$port" : '';
+    $host = "[$host]" if Net::IP::ip_is_ipv6($host);
+    return "${host}${port}";
+};
+
 sub get_monaddr_list {
     my ($configfile) = shift;
 
@@ -119,12 +130,7 @@ sub hostlist {
     my ($list_text, $separator) = @_;
 
     my @monhostlist = PVE::Tools::split_list($list_text);
-    return join($separator, map {
-       my ($host, $port) = PVE::Tools::parse_host_and_port($_);
-       $port = defined($port) ? ":$port" : '';
-       $host = "[$host]" if Net::IP::ip_is_ipv6($host);
-       "${host}${port}"
-    } @monhostlist);
+    return join($separator, map { $get_host->($_) } @monhostlist);
 }
 
 my $ceph_check_keyfile = sub {