[pve-devel] [PATCH v2 manager 10/14] api: ceph: mon: add ips_from_mon_host helper

Fabian Ebner f.ebner at proxmox.com
Mon May 10 14:18:22 CEST 2021


Partially based on pve-storage's CephConfig.pm get_monaddr_list, but the
interface is not the best for the use case here.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

New in v2.

 PVE/API2/Ceph/MON.pm | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/PVE/API2/Ceph/MON.pm b/PVE/API2/Ceph/MON.pm
index f7af3c37..e4e8ecfb 100644
--- a/PVE/API2/Ceph/MON.pm
+++ b/PVE/API2/Ceph/MON.pm
@@ -62,6 +62,30 @@ my $find_mon_ip = sub {
     }
 };
 
+my $ips_from_mon_host = sub {
+    my ($mon_host) = @_;
+
+    my $ips = [];
+
+    my @hosts = PVE::Tools::split_list($mon_host);
+
+    for my $host (@hosts) {
+	$host =~ s|^\[?v\d+\:||; # remove beginning of vector
+	$host =~ s|/\d+\]?||; # remove end of vector
+
+	($host) = PVE::Tools::parse_host_and_port($host);
+	next if !defined($host);
+
+	# filter out hostnames
+	my $ip = PVE::JSONSchema::pve_verify_ip($host, 1);
+	next if !defined($ip);
+
+	push @{$ips}, $ip;
+    }
+
+    return $ips;
+};
+
 my $assert_mon_prerequisites = sub {
     my ($cfg, $monhash, $monid, $monip) = @_;
 
-- 
2.20.1





More information about the pve-devel mailing list