[pve-devel] [PATCH manager v2 2/5] ceph: add PUT 'flags' api call
Dominik Csapak
d.csapak at proxmox.com
Tue Jul 23 09:52:26 CEST 2019
this api call can set multiple flags at once, but does this in a
worker since this can take quiet some time
also we only set/unset flags that are not already set/unset (respectively)
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v1:
* use check_ceph_configured
* better map call
* better flag set/unset check
* better error printing
- print instead of warn
- if error, warn with flag in error output
PVE/API2/Ceph.pm | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index 132c426f..862da4a1 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -904,6 +904,65 @@ __PACKAGE__->register_method ({
return $stat->{flags} // '';
}});
+__PACKAGE__->register_method ({
+ name => 'set_flags',
+ path => 'flags',
+ method => 'PUT',
+ description => "Set/Unset multiple ceph flags at once.",
+ proxyto => 'node',
+ protected => 1,
+ permissions => {
+ check => ['perm', '/', [ 'Sys.Modify' ]],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ %$possible_flags,
+ },
+ },
+ returns => { type => 'string' },
+ code => sub {
+ my ($param) = @_;
+
+ my $rpcenv = PVE::RPCEnvironment::get();
+ my $user = $rpcenv->get_user();
+ PVE::Ceph::Tools::check_ceph_configured();
+
+ my $rados = PVE::RADOS->new();
+
+ my $worker = sub {
+ # reopen rados object
+ my $rados = PVE::RADOS->new();
+ my $stat = $rados->mon_command({ prefix => 'osd dump' });
+ my $setflags = $stat->{flags} // '';
+ $setflags = { map { $_ => 1 } PVE::Tools::split_list($setflags) };
+ my $errors = 0;
+ foreach my $flag (sort keys %$possible_flags) {
+ next if !defined($param->{$flag});
+ my $val = $param->{$flag};
+ my $realflag = $flagmap->{$flag} // $flag;
+ next if !$val == !$setflags->{$realflag}; # we do not set/unset flags to the same state
+
+ my $prefix = $val ? 'set' : 'unset';
+ eval {
+ print "$prefix $flag\n";
+ $rados->mon_command({ prefix => "osd $prefix", key => $flag, });
+ };
+ if (my $err = $@) {
+ warn "error with $flag: '$err'\n";
+ $errors++;
+ }
+ }
+
+ if ($errors) {
+ die "could not set/unset $errors flags\n";
+ }
+ };
+
+ return $rpcenv->fork_worker('cephsetflags', undef, $user, $worker);
+ }});
+
__PACKAGE__->register_method ({
name => 'set_flag',
path => 'flags/{flag}',
--
2.20.1
More information about the pve-devel
mailing list