]> git.proxmox.com Git - pve-manager.git/commitdiff
api/cluster: move ceph calls into sub- directory/module
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 23 Jul 2019 13:28:18 +0000 (15:28 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 23 Jul 2019 13:28:18 +0000 (15:28 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Cluster.pm
PVE/API2/Cluster/Ceph.pm [new file with mode: 0644]
PVE/API2/Cluster/Makefile [new file with mode: 0644]
PVE/API2/Makefile

index 0e455ba826800f20ccfaab6a9fb2e9c801db0506..47a89d2130b8831885bf62807ae730cc6d51db61 100644 (file)
@@ -21,6 +21,7 @@ use PVE::Tools qw(extract_param);
 
 use PVE::API2::ACMEAccount;
 use PVE::API2::Backup;
+use PVE::API2::Cluster::Ceph;
 use PVE::API2::ClusterConfig;
 use PVE::API2::Firewall::Cluster;
 use PVE::API2::HAConfig;
@@ -58,6 +59,11 @@ __PACKAGE__->register_method ({
     path => 'acme',
 });
 
+__PACKAGE__->register_method ({
+    subclass => "PVE::API2::Cluster::Ceph",
+    path => 'ceph',
+});
+
 my $dc_schema = PVE::Cluster::get_datacenter_schema();
 my $dc_properties = { 
     delete => {
@@ -606,116 +612,4 @@ __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::Ceph::Services::get_cluster_service($type);
-           my $data = {};
-           for my $host (sort keys %$typedata) {
-               for my $service (sort keys %{$typedata->{$host}}) {
-                   $data->{"$service\@$host"} = $typedata->{$host}->{$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} // $service->{id};
-               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;
diff --git a/PVE/API2/Cluster/Ceph.pm b/PVE/API2/Cluster/Ceph.pm
new file mode 100644 (file)
index 0000000..d7b8d16
--- /dev/null
@@ -0,0 +1,132 @@
+package PVE::API2::Cluster::Ceph;
+
+use strict;
+use warnings;
+
+use PVE::Ceph::Services;
+use PVE::Ceph::Tools;
+use PVE::Cluster;
+use PVE::Exception qw(raise_param_exc);
+use PVE::RADOS;
+use PVE::RESTHandler;
+use PVE::SafeSyslog;
+use PVE::Tools qw(extract_param);
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method ({
+    name => 'cephindex',
+    path => '',
+    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 => 'metadata',
+    path => '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::Ceph::Services::get_cluster_service($type);
+           my $data = {};
+           for my $host (sort keys %$typedata) {
+               for my $service (sort keys %{$typedata->{$host}}) {
+                   $data->{"$service\@$host"} = $typedata->{$host}->{$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} // $service->{id};
+               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 => 'status',
+    path => '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;
diff --git a/PVE/API2/Cluster/Makefile b/PVE/API2/Cluster/Makefile
new file mode 100644 (file)
index 0000000..8d8388c
--- /dev/null
@@ -0,0 +1,17 @@
+include ../../../defines.mk
+
+# for node independent, cluster-wide applicable, API endpoints
+# ensure we do not conflict with files shipped by pve-cluster!!
+PERLSOURCE=                    \
+       Ceph.pm
+
+all:
+
+.PHONY: clean
+clean:
+       rm -rf *~
+
+.PHONY: install
+install: ${PERLSOURCE}
+       install -d ${PERLLIBDIR}/PVE/API2/Cluster
+       install -m 0644 ${PERLSOURCE} ${PERLLIBDIR}/PVE/API2/Cluster
index c5868d7f94f40f18f297c4518f7f9125abb05e07..8554efa15ab26f6ab834c1979092fe10a2003932 100644 (file)
@@ -1,6 +1,6 @@
 include ../../defines.mk
 
-SUBDIRS=Hardware Ceph
+SUBDIRS=Hardware Ceph Cluster
 
 PERLSOURCE =                   \
        Replication.pm          \