[pve-devel] [PATCH manager v2 2/5] add ceph flags api calls

Dominik Csapak d.csapak at proxmox.com
Wed Nov 30 11:52:07 CET 2016


we add a get/post/delete api call for ceph flags

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes to v1:
 * new get call
 * separated set/unset in a post/delete call
 PVE/API2/Ceph.pm | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index 3dd1439..b0c9ddc 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -535,6 +535,7 @@ __PACKAGE__->register_method ({
 	    { name => 'config' },
 	    { name => 'log' },
 	    { name => 'disks' },
+	    { name => 'flags' },
 	];
 
 	return $result;
@@ -1312,6 +1313,126 @@ __PACKAGE__->register_method ({
     }});
 
 __PACKAGE__->register_method ({
+    name => 'get_flags',
+    path => 'flags',
+    method => 'GET',
+    description => "get all set ceph flags",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Audit' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	},
+    },
+    returns => { type => 'string' },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::CephTools::check_ceph_inited();
+
+	my $pve_ckeyring_path = PVE::CephTools::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' });
+
+	return $stat->{flags} // '';
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'set_flag',
+    path => 'flags/{flag}',
+    method => 'POST',
+    description => "Set a ceph flag",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Modify' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    flag => {
+		description => 'The ceph flag to set/unset',
+		type => 'string',
+		enum => [ 'full', 'pause', 'noup', 'nodown', 'noout', 'noin', 'nobackfill', 'norebalance', 'norecover', 'noscrub', 'nodeep-scrub', 'notieragent'],
+	    },
+	},
+    },
+    returns => { type => 'null' },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::CephTools::check_ceph_inited();
+
+	my $pve_ckeyring_path = PVE::CephTools::get_config('pve_ckeyring_path');
+
+	die "not fully configured - missing '$pve_ckeyring_path'\n"
+	    if ! -f $pve_ckeyring_path;
+
+	my $set = $param->{set} // !$param->{unset};
+	my $rados = PVE::RADOS->new();
+
+	$rados->mon_command({
+	    prefix => "osd set",
+	    key => $param->{flag},
+	});
+
+	return undef;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'unset_flag',
+    path => 'flags/{flag}',
+    method => 'DELETE',
+    description => "Unset a ceph flag",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Modify' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    flag => {
+		description => 'The ceph flag to set/unset',
+		type => 'string',
+		enum => [ 'full', 'pause', 'noup', 'nodown', 'noout', 'noin', 'nobackfill', 'norebalance', 'norecover', 'noscrub', 'nodeep-scrub', 'notieragent'],
+	    },
+	},
+    },
+    returns => { type => 'null' },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::CephTools::check_ceph_inited();
+
+	my $pve_ckeyring_path = PVE::CephTools::get_config('pve_ckeyring_path');
+
+	die "not fully configured - missing '$pve_ckeyring_path'\n"
+	    if ! -f $pve_ckeyring_path;
+
+	my $set = $param->{set} // !$param->{unset};
+	my $rados = PVE::RADOS->new();
+
+	$rados->mon_command({
+	    prefix => "osd unset",
+	    key => $param->{flag},
+	});
+
+	return undef;
+    }});
+
+__PACKAGE__->register_method ({
     name => 'destroypool',
     path => 'pools/{name}',
     method => 'DELETE',
-- 
2.1.4





More information about the pve-devel mailing list