From: Dominik Csapak Date: Thu, 27 Jun 2019 08:43:11 +0000 (+0200) Subject: CephConfig: refactor host port parsing X-Git-Url: https://git.proxmox.com/?p=pve-storage.git;a=commitdiff_plain;h=c8a3234574c7276a86ca2eadc76785534f476982 CephConfig: refactor host port parsing Signed-off-by: Dominik Csapak --- diff --git a/PVE/CephConfig.pm b/PVE/CephConfig.pm index 3ff49ee..31bb887 100644 --- a/PVE/CephConfig.pm +++ b/PVE/CephConfig.pm @@ -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 {