From 6dd2846577deefd4d4798bc8cc86eaf1d69b3227 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Tue, 23 Jul 2019 16:33:58 +0200 Subject: [PATCH] ceph: add perl flag GET and PUT call use PUT for setting or unsetting, as POST/DELETE (like the old node specific API used) makes no sense. One does not creates or deletes the flag, they are always here. One just updates their value Signed-off-by: Thomas Lamprecht --- PVE/API2/Cluster/Ceph.pm | 78 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/PVE/API2/Cluster/Ceph.pm b/PVE/API2/Cluster/Ceph.pm index ef9c9daa..fa79d077 100644 --- a/PVE/API2/Cluster/Ceph.pm +++ b/PVE/API2/Cluster/Ceph.pm @@ -252,4 +252,82 @@ __PACKAGE__->register_method ({ return $rpcenv->fork_worker('cephsetflags', undef, $user, $worker); }}); + +__PACKAGE__->register_method ({ + name => 'get_flag', + path => 'flags/{flag}', + method => 'GET', + description => "Get the status of a specific ceph flag.", + protected => 1, + permissions => { + check => ['perm', '/', [ 'Sys.Audit' ]], + }, + parameters => { + additionalProperties => 0, + properties => { + flag => { + description => "The name of the flag name to get.", + type => 'string', enum => $possible_flags_list, + }, + }, + }, + returns => { + type => 'boolean', + }, + code => sub { + my ($param) = @_; + + PVE::Ceph::Tools::check_ceph_configured(); + + my $realflag = PVE::Ceph::Tools::get_real_flag_name($param->{flag}); + + my $setflags = $get_current_set_flags->(); + if ($setflags->{$realflag}) { + return 1; + } + + return 0; + }}); + +__PACKAGE__->register_method ({ + name => 'update_flag', + path => 'flags/{flag}', + method => 'PUT', + description => "Set or clear (unset) a specific ceph flag", + protected => 1, + permissions => { + check => ['perm', '/', [ 'Sys.Modify' ]], + }, + parameters => { + additionalProperties => 0, + properties => { + flag => { + description => 'The ceph flag to update', + type => 'string', + enum => $possible_flags_list, + }, + value => { + description => 'The new value of the flag', + type => 'boolean', + }, + }, + }, + returns => { type => 'null' }, + code => sub { + my ($param) = @_; + + PVE::Ceph::Tools::check_ceph_configured(); + + my $cmd = $param->{value} ? 'set' : 'unset'; + + my $rados = PVE::RADOS->new(); + $rados->mon_command({ + prefix => "osd $cmd", + key => $param->{flag}, + }); + + return undef; + }}); + + 1;