so it can be reused for modifying the storage definitions

Signed-off-by: Fabian Grünbichler <f.gruenbich...@proxmox.com>
---
 PVE/API2/Ceph.pm | 72 +++++++++++++++++++++++++++++---------------------------
 1 file changed, 37 insertions(+), 35 deletions(-)

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index c4d6ffcb..d6bc4c6a 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -697,6 +697,42 @@ __PACKAGE__->register_method ({
 
     }});
 
+my $get_monitor_hash = sub {
+    my $cfg = PVE::CephTools::parse_ceph_config();
+
+    my $monhash = {};
+    foreach my $section (keys %$cfg) {
+       my $d = $cfg->{$section};
+       if ($section =~ m/^mon\.(\S+)$/) {
+           my $monid = $1;
+           if ($d->{'mon addr'} && $d->{'host'}) {
+               $monhash->{$monid} = {
+                   addr => $d->{'mon addr'},
+                   host => $d->{'host'},
+                   name => $monid,
+               }
+           }
+       }
+    }
+
+    eval {
+       my $rados = PVE::RADOS->new();
+       my $monstat = $rados->mon_command({ prefix => 'mon_status' });
+       my $mons = $monstat->{monmap}->{mons};
+       foreach my $d (@$mons) {
+           next if !defined($d->{name});
+           $monhash->{$d->{name}}->{rank} = $d->{rank};
+           $monhash->{$d->{name}}->{addr} = $d->{addr};
+           if (grep { $_ eq $d->{rank} } @{$monstat->{quorum}}) {
+               $monhash->{$d->{name}}->{quorum} = 1;
+           }
+       }
+    };
+    warn $@ if $@;
+
+    return $monhash;
+};
+
 __PACKAGE__->register_method ({
     name => 'listmon',
     path => 'mon',
@@ -729,41 +765,7 @@ __PACKAGE__->register_method ({
 
        PVE::CephTools::check_ceph_inited();
 
-       my $res = [];
-
-       my $cfg = PVE::CephTools::parse_ceph_config();
-
-       my $monhash = {};
-       foreach my $section (keys %$cfg) {
-           my $d = $cfg->{$section};
-           if ($section =~ m/^mon\.(\S+)$/) {
-               my $monid = $1;
-               if ($d->{'mon addr'} && $d->{'host'}) {
-                   $monhash->{$monid} = {
-                       addr => $d->{'mon addr'},
-                       host => $d->{'host'},
-                       name => $monid,
-                   }
-               }
-           }
-       }
-
-       eval {
-           my $rados = PVE::RADOS->new();
-           my $monstat = $rados->mon_command({ prefix => 'mon_status' });
-           my $mons = $monstat->{monmap}->{mons};
-           foreach my $d (@$mons) {
-               next if !defined($d->{name});
-               $monhash->{$d->{name}}->{rank} = $d->{rank};
-               $monhash->{$d->{name}}->{addr} = $d->{addr};
-               if (grep { $_ eq $d->{rank} } @{$monstat->{quorum}}) {
-                   $monhash->{$d->{name}}->{quorum} = 1;
-               }
-           }
-       };
-       warn $@ if $@;
-
-       return PVE::RESTHandler::hash_to_array($monhash, 'name');
+       return PVE::RESTHandler::hash_to_array($get_monitor_hash->(), 'name');
     }});
 
 __PACKAGE__->register_method ({
-- 
2.11.0


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to