]> git.proxmox.com Git - pve-manager.git/commitdiff
ceph: factor out the service info generation
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 4 Jun 2019 12:47:43 +0000 (14:47 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 4 Jun 2019 12:57:10 +0000 (14:57 +0200)
and include a call to $type metadata to include the version

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/API2/Ceph/MDS.pm
PVE/API2/Ceph/MGR.pm
PVE/API2/Ceph/MON.pm
PVE/Ceph/Services.pm

index 1948969026482a6b92cf741281fd4e83abfd84eb..532eb404542cc9487c82079682503d1d2dbb65b1 100644 (file)
@@ -71,26 +71,11 @@ __PACKAGE__->register_method ({
        my $res = [];
 
        my $cfg = cfs_read_file('ceph.conf');
+       my $rados = PVE::RADOS->new();
 
-       my $mds_hash = {};
-
-       foreach my $section (keys %$cfg) {
-           my $d = $cfg->{$section};
-
-           if ($section =~ m/^mds\.(\S+)$/) {
-               my $mds_id = $1;
-               if (defined($d->{host})) {
-                   $mds_hash->{$mds_id} = {
-                       name => $mds_id,
-                       state => 'unknown',
-                       addr => $d->{host},
-                       host => $d->{host},
-                   };
-               }
-           }
-       }
+       my $mds_hash = PVE::Ceph::Services::get_services_info("mds", $cfg, $rados);
 
-       my $mds_state = PVE::Ceph::Services::get_cluster_mds_state();
+       my $mds_state = PVE::Ceph::Services::get_cluster_mds_state($rados);
        foreach my $name (keys %$mds_state) {
            my $d = $mds_state->{$name};
            # just overwrite, this always provides more info
index 2ded684d8032d1c4f2a56c04fb65a910946166b6..c1d38d7a74f524c4000166901731972dcdaffba1 100644 (file)
@@ -7,6 +7,7 @@ use File::Path;
 
 use PVE::Ceph::Tools;
 use PVE::Ceph::Services;
+use PVE::Cluster qw(cfs_read_file);
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RADOS;
 use PVE::RPCEnvironment;
index 17660039359671d5d1858737bbf7bd4a6ebac04a..59f3019359571dd9d6b8d79e0924c41f990b9214 100644 (file)
@@ -68,7 +68,8 @@ __PACKAGE__->register_method ({
            type => "object",
            properties => {
                name => { type => 'string' },
-               addr => { type => 'string' },
+               addr => { type => 'string', optional => 1 },
+               host => { type => 'string', optional => 1 },
            },
        },
        links => [ { rel => 'child', href => "{name}" } ],
@@ -83,32 +84,23 @@ __PACKAGE__->register_method ({
        my $cfg = cfs_read_file('ceph.conf');
 
        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();
+           $monhash = PVE::Ceph::Services::get_services_info("mon", $cfg, $rados);
            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};
+               $monhash->{$d->{name}}->{state} = 'running';
                if (grep { $_ eq $d->{rank} } @{$monstat->{quorum}}) {
                    $monhash->{$d->{name}}->{quorum} = 1;
                }
            }
+
        };
        warn $@ if $@;
 
index 376216524ff79e7494181312a10bf008e08bf074..0448c7d1298d81dc6c42ce73f1b62da8e88eab0d 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 
 use PVE::Ceph::Tools;
-use PVE::Cluster;
+use PVE::Cluster qw(cfs_read_file);
 use PVE::Tools qw(run_command);
 use PVE::RADOS;
 
@@ -71,6 +71,54 @@ sub ceph_service_cmd {
     run_command(['/bin/systemctl', $action, $service]);
 }
 
+sub get_services_info {
+    my ($type, $cfg, $rados) = @_;
+
+    my $result = {};
+    my $services = get_cluster_service($type);
+
+    foreach my $host (sort keys %$services) {
+       foreach  my $id (sort keys %{$services->{$host}}) {
+           $result->{$id} = $services->{$host}->{$id};
+           $result->{$id}->{host} = $host;
+           $result->{$id}->{name} = $id;
+           $result->{$id}->{state} = 'unknown';
+           if ($result->{$id}->{service}) {
+               $result->{$id}->{state} = 'stopped';
+           }
+       }
+    }
+
+    if (!$cfg) {
+       $cfg = cfs_read_file('ceph.conf');
+    }
+
+    foreach my $section (keys %$cfg) {
+       my $d = $cfg->{$section};
+       if ($section =~ m/^$type\.(\S+)$/) {
+           my $id = $1;
+           my $addr = $d->{"$type addr"} // $d->{"${type}_addr"} // $d->{host};
+           $result->{$id}->{name} //= $id;
+           $result->{$id}->{addr} //= $addr;
+           $result->{$id}->{state} //= 'unknown';
+           $result->{$id}->{host} //= $d->{host};
+       }
+    }
+
+    if (!$rados) {
+       $rados = PVE::RADOS->new();
+    }
+    my $metadata = $rados->mon_command({ prefix => "$type metadata" });
+    foreach my $service (@$metadata) {
+       $result->{$service->{name}}->{ceph_version_short} = $service->{ceph_version_short};
+       $result->{$service->{name}}->{ceph_version} = $service->{ceph_version};
+       $result->{$service->{name}}->{host} //= $service->{hostname};
+       $result->{$service->{name}}->{addr} //= $service->{addr};
+    }
+
+    return $result;
+}
+
 # MDS
 
 sub list_local_mds_ids {