]> git.proxmox.com Git - pve-manager.git/commitdiff
api: ceph: add ceph/cfg path, deprecate ceph/config and ceph/configdb
authorAaron Lauterer <a.lauterer@proxmox.com>
Mon, 20 Mar 2023 10:50:54 +0000 (11:50 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 20 Mar 2023 14:31:04 +0000 (15:31 +0100)
Consolidating the different config paths lets us add more as needed
without polluting our API with too many 'configxxx' endpoints.

The config and configdb paths are renamed under the ceph/cfg path:
* config -> raw (returns the ceph.conf file as is)
* configdb -> db (returns the ceph config db contents)

The old paths are still available and need to be dropped at some point.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by:  Dominik Csapak <d.csapak@proxmox.com>
PVE/API2/Ceph.pm
PVE/API2/Ceph/Cfg.pm [new file with mode: 0644]
PVE/API2/Ceph/Makefile

index 3dcd549eb33541e02be167eaed1e2e007272850f..28df05c39f3e4d988d442d9e591c033318a99229 100644 (file)
@@ -18,6 +18,7 @@ use PVE::RPCEnvironment;
 use PVE::Storage;
 use PVE::Tools qw(run_command file_get_contents file_set_contents extract_param);
 
+use PVE::API2::Ceph::Cfg;
 use PVE::API2::Ceph::OSD;
 use PVE::API2::Ceph::FS;
 use PVE::API2::Ceph::MDS;
@@ -31,6 +32,11 @@ use base qw(PVE::RESTHandler);
 
 my $pve_osd_default_journal_size = 1024*5;
 
+__PACKAGE__->register_method ({
+    subclass => "PVE::API2::Ceph::Cfg",
+    path => 'cfg',
+});
+
 __PACKAGE__->register_method ({
     subclass => "PVE::API2::Ceph::OSD",
     path => 'osd',
@@ -95,6 +101,7 @@ __PACKAGE__->register_method ({
 
        my $result = [
            { name => 'cmd-safety' },
+           { name => 'cfg' },
            { name => 'config' },
            { name => 'configdb' },
            { name => 'crush' },
@@ -116,6 +123,8 @@ __PACKAGE__->register_method ({
        return $result;
     }});
 
+
+# TODO: deprecrated, remove with PVE 8
 __PACKAGE__->register_method ({
     name => 'config',
     path => 'config',
@@ -124,7 +133,7 @@ __PACKAGE__->register_method ({
     permissions => {
        check => ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any => 1],
     },
-    description => "Get the Ceph configuration file.",
+    description => "Get the Ceph configuration file. Deprecated, please use `/nodes/{node}/ceph/cfg/raw.",
     parameters => {
        additionalProperties => 0,
        properties => {
@@ -142,6 +151,7 @@ __PACKAGE__->register_method ({
 
     }});
 
+# TODO: deprecrated, remove with PVE 8
 __PACKAGE__->register_method ({
     name => 'configdb',
     path => 'configdb',
@@ -151,7 +161,7 @@ __PACKAGE__->register_method ({
     permissions => {
        check => ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any => 1],
     },
-    description => "Get the Ceph configuration database.",
+    description => "Get the Ceph configuration database. Deprecated, please use `/nodes/{node}/ceph/cfg/db.",
     parameters => {
        additionalProperties => 0,
        properties => {
@@ -186,7 +196,6 @@ __PACKAGE__->register_method ({
        return $res;
     }});
 
-
 __PACKAGE__->register_method ({
     name => 'init',
     path => 'init',
diff --git a/PVE/API2/Ceph/Cfg.pm b/PVE/API2/Ceph/Cfg.pm
new file mode 100644 (file)
index 0000000..f3c2589
--- /dev/null
@@ -0,0 +1,115 @@
+package PVE::API2::Ceph::Cfg;
+
+use strict;
+use warnings;
+
+use PVE::Ceph::Tools;
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::RADOS;
+use PVE::Tools qw(file_get_contents);
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method ({
+    name => 'index',
+    path => '',
+    method => 'GET',
+    description => "Directory index.",
+    permissions => { user => 'all' },
+    permissions => {
+       check => ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any => 1],
+    },
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+       },
+    },
+    returns => {
+       type => 'array',
+       items => {
+           type => "object",
+           properties => {},
+       },
+       links => [ { rel => 'child', href => "{name}" } ],
+    },
+    code => sub {
+       my ($param) = @_;
+
+       my $result = [
+           { name => 'raw' },
+           { name => 'db' },
+       ];
+
+       return $result;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'raw',
+    path => 'raw',
+    method => 'GET',
+    proxyto => 'node',
+    permissions => {
+       check => ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any => 1],
+    },
+    description => "Get the Ceph configuration file.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+       },
+    },
+    returns => { type => 'string' },
+    code => sub {
+       my ($param) = @_;
+
+       PVE::Ceph::Tools::check_ceph_inited();
+
+       my $path = PVE::Ceph::Tools::get_config('pve_ceph_cfgpath');
+       return file_get_contents($path);
+
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'db',
+    path => 'db',
+    method => 'GET',
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+       check => ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any => 1],
+    },
+    description => "Get the Ceph configuration database.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+       },
+    },
+    returns => {
+       type => 'array',
+       items => {
+           type => 'object',
+           properties => {
+               section => { type => "string", },
+               name => { type => "string", },
+               value => { type => "string", },
+               level => { type => "string", },
+               'can_update_at_runtime' => { type => "boolean", },
+               mask => { type => "string" },
+           },
+       },
+    },
+    code => sub {
+       my ($param) = @_;
+
+       PVE::Ceph::Tools::check_ceph_inited();
+
+       my $rados = PVE::RADOS->new();
+       my $res = $rados->mon_command( { prefix => 'config dump', format => 'json' });
+       foreach my $entry (@$res) {
+           $entry->{can_update_at_runtime} = $entry->{can_update_at_runtime}? 1 : 0; # JSON::true/false -> 1/0
+       }
+
+       return $res;
+    }});
index 5d6f642b2309e55b1b567a3054e2ee245767ba04..5c546bf0a00abbb767e08bea1ef90bfbe1cc6e1e 100644 (file)
@@ -1,6 +1,7 @@
 include ../../../defines.mk
 
 PERLSOURCE=                    \
+       Cfg.pm                  \
        MGR.pm                  \
        MON.pm                  \
        OSD.pm                  \