[pve-devel] [PATCH manager 05/20] ceph: add monhash to monhost string helper

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Aug 25 10:48:07 CEST 2017


modified version of the one we use in the RBD storage
plugin, but input format is slightly different here.

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
 PVE/API2/Ceph.pm | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index d6bc4c6a..f7353884 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -733,6 +733,19 @@ my $get_monitor_hash = sub {
     return $monhash;
 };
 
+my $map_monhash_monhosts = sub {
+    my ($monhash) = @_;
+
+    return join(';', map {
+	my $addr_string = $monhash->{$_}->{addr};
+	$addr_string =~ s!/\d+$!!; #drop nonce
+	my ($host, $port) = PVE::Tools::parse_host_and_port($addr_string);
+	$port = defined($port) ? ":$port" : '';
+	$host = "[$host]" if Net::IP::ip_is_ipv6($host);
+	"${host}${port}";
+    } keys %$monhash);
+};
+
 __PACKAGE__->register_method ({
     name => 'listmon',
     path => 'mon',
-- 
2.11.0





More information about the pve-devel mailing list