[pve-devel] [PATCH manager v2 1/5] ceph: add GET 'flags2'

Dominik Csapak d.csapak at proxmox.com
Tue Jul 23 09:52:25 CEST 2019


we want a GET api call where we return all available flags with
description, but the GET 'flags' api call already returns a string
and not an array, so we cannot use that

instead, we add a new api call that returns that feature and
with e.g. pve 7 we can remove the 'flags' api call and
rename 'flags2' to 'flags'

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v1:
* better comment for flagmap
* rename to 'flags2'
* use check_ceph_configured

 PVE/API2/Ceph.pm | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index f7394ae4..132c426f 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -96,6 +96,7 @@ __PACKAGE__->register_method ({
 	    { name => 'log' },
 	    { name => 'disks' },
 	    { name => 'flags' },
+	    { name => 'flags2' },
 	    { name => 'rules' },
 	];
 
@@ -819,6 +820,61 @@ my $possible_flags = {
     },
 };
 
+# the 'pause' flag gets always set to both 'pauserd' and 'pausewr'
+# so decide that the 'pause' flag is set if we detect 'pauserd'
+my $flagmap = {
+    'pause' => 'pauserd',
+};
+
+__PACKAGE__->register_method ({
+    name => 'flags2',
+    path => 'flags2',
+    method => 'GET',
+    description => "get the status of all ceph flags",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Audit' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	},
+    },
+    returns => { type => 'array' },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::Ceph::Tools::check_ceph_configured();
+
+	my $rados = PVE::RADOS->new();
+
+	my $stat = $rados->mon_command({ prefix => 'osd dump' });
+	my $setflags = {};
+	foreach my $flag (PVE::Tools::split_list($stat->{flags} // '')) {
+	    $setflags->{$flag} = 1;
+	}
+
+	my $res = [];
+	foreach my $flag (sort keys %$possible_flags) {
+	    my $el = {
+		name => $flag,
+		description => $possible_flags->{$flag}->{description},
+		value => 0,
+	    };
+
+	    my $realflag = $flagmap->{$flag} // $flag;
+	    if ($setflags->{$realflag}) {
+		$el->{value} = 1;
+	    }
+
+	    push @$res, $el;
+	}
+
+	return $res;
+    }});
+
 __PACKAGE__->register_method ({
     name => 'get_flags',
     path => 'flags',
-- 
2.20.1





More information about the pve-devel mailing list