[pve-devel] [PATCH manager 2/6] ceph: add GET 'allflags'

Dominik Csapak d.csapak at proxmox.com
Mon Jul 22 16:08:48 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 'allflags' to 'flags'

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
i am not too attached to the name 'allflags' but could not come up
with a better one

also could not think of any other possibility than adding a seperate
api call besides a breaking api change, but maybe someone has an idea?

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

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index ff7d67a9..72cac7e5 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -824,6 +824,66 @@ my $possible_flags = {
     },
 };
 
+# the 'pause' flag gets set as 'pauserd' and 'pausewr'
+# we have to map those to correctly show and set the pause flag
+my $flagmap = {
+    'pause' => 'pauserd',
+};
+
+__PACKAGE__->register_method ({
+    name => 'get_all_flags',
+    path => 'allflags',
+    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_inited();
+
+	my $pve_ckeyring_path = PVE::Ceph::Tools::get_config('pve_ckeyring_path');
+
+	die "not fully configured - missing '$pve_ckeyring_path'\n"
+	    if ! -f $pve_ckeyring_path;
+
+	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