[pve-devel] [PATCH manager 03/15] add cluster wide ceph api calls

Dominik Csapak d.csapak at proxmox.com
Mon May 27 14:13:54 CEST 2019


add two new api calls in /cluster/ceph

status:
the same as /nodes/NODE/ceph/status, but accessible without
nodename, which we don't need, as in the hyperconverged case, all nodes
have the ceph.conf which contains the info on how to connect to the
monitors

metadata:
combines data from the cluster filesystem about the services,
as well as the 'ceph YYY metadata' info we get from ceph.
with this info we can convieniently display which services exists,
which are running and which versions they have

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2/Cluster.pm | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 115 insertions(+)

diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm
index cbd7d3de..99dc0c9e 100644
--- a/PVE/API2/Cluster.pm
+++ b/PVE/API2/Cluster.pm
@@ -102,6 +102,7 @@ __PACKAGE__->register_method ({
 	    { name => 'firewall' },
 	    { name => 'config' },
 	    { name => 'acme' },
+	    { name => 'ceph' },
 	    ];
 
 	return $result;
@@ -596,4 +597,118 @@ __PACKAGE__->register_method({
 	die "unable to get any free VMID\n";
     }});
 
+__PACKAGE__->register_method ({
+    name => 'cephindex',
+    path => 'ceph',
+    method => 'GET',
+    description => "Cluster ceph index.",
+    permissions => { user => 'all' },
+    parameters => {
+	additionalProperties => 0,
+	properties => {},
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => {},
+	},
+	links => [ { rel => 'child', href => "{name}" } ],
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $result = [
+	    { name => 'metadata' },
+	    { name => 'status' },
+	    ];
+
+	return $result;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'ceph_metadata',
+    path => 'ceph/metadata',
+    method => 'GET',
+    description => "Get ceph metadata.",
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any => 1],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {},
+    },
+    returns => { type => 'object' },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::Ceph::Tools::check_ceph_inited();
+
+	my $rados = PVE::RADOS->new();
+
+	my $res = {
+	    version => PVE::Cluster::get_node_kv("ceph-version"),
+	};
+
+	for my $type ( qw(mon mgr mds) ) {
+	    my $typedata = PVE::Cluster::get_node_kv("ceph-$type");
+	    my $data = {};
+	    for my $host (sort keys %$typedata) {
+		my $d = eval { decode_json($typedata->{$host}) };
+		for my $service (sort keys %$d) {
+		    $d->{hostname} = $host;
+		    $data->{"$service\@$host"} = $d->{$service};
+		}
+	    }
+
+	    # get data from metadata call and merge 'our' data
+	    my $services = $rados->mon_command({ prefix => "$type metadata" });
+	    for my $service ( @$services ) {
+		my $hostname = $service->{hostname};
+		my $servicename =  $service->{name};
+		my $id = "$servicename\@$hostname";
+
+		if ($data->{$id}) {
+		    # copy values over to the metadata hash
+		    for my $k (keys %$data->{$id}) {
+			$service->{$k} = $data->{$id}->{$k};
+		    }
+		}
+		$data->{$id} = $service;
+	    }
+
+	    $res->{$type} = $data;
+	}
+
+	$res->{osd} = $rados->mon_command({ prefix => "osd metadata" });
+
+	return $res;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'cephstatus',
+    path => 'ceph/status',
+    method => 'GET',
+    description => "Get ceph status.",
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any => 1],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => { },
+    },
+    returns => { type => 'object' },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::Ceph::Tools::check_ceph_inited();
+
+	my $rados = PVE::RADOS->new();
+	my $status = $rados->mon_command({ prefix => 'status' });
+	$status->{health} = $rados->mon_command({ prefix => 'health', detail => 'detail' });
+	return $status;
+    }});
+
 1;
-- 
2.11.0





More information about the pve-devel mailing list