[pve-devel] [PATCH manager 6/7] ceph: move MGR API calls to API2/Ceph/MGR.pm

Dominik Csapak d.csapak at proxmox.com
Wed Dec 19 11:24:46 CET 2018


and adapt the paths

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2/Ceph.pm       |  95 +++-----------------------------------------
 PVE/API2/Ceph/MGR.pm   | 104 +++++++++++++++++++++++++++++++++++++++++++++++++
 PVE/API2/Ceph/Makefile |   1 +
 PVE/CLI/pveceph.pm     |   5 ++-
 4 files changed, 114 insertions(+), 91 deletions(-)
 create mode 100644 PVE/API2/Ceph/MGR.pm

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index 3b93a8f6..60988996 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -21,6 +21,7 @@ use PVE::Tools qw(run_command file_get_contents file_set_contents);
 use PVE::API2::Ceph::OSD;
 use PVE::API2::Ceph::FS;
 use PVE::API2::Ceph::MDS;
+use PVE::API2::Ceph::MGR;
 use PVE::API2::Storage::Config;
 
 use base qw(PVE::RESTHandler);
@@ -38,6 +39,11 @@ __PACKAGE__->register_method ({
 });
 
 __PACKAGE__->register_method ({
+    subclass => "PVE::API2::Ceph::MGR",
+    path => 'mgr',
+});
+
+__PACKAGE__->register_method ({
     subclass => "PVE::API2::Ceph::FS",
     path => 'fs',
 });
@@ -690,95 +696,6 @@ __PACKAGE__->register_method ({
     }});
 
 __PACKAGE__->register_method ({
-    name => 'createmgr',
-    path => 'mgr',
-    method => 'POST',
-    description => "Create Ceph Manager",
-    proxyto => 'node',
-    protected => 1,
-    permissions => {
-	check => ['perm', '/', [ 'Sys.Modify' ]],
-    },
-    parameters => {
-	additionalProperties => 0,
-	properties => {
-	    node => get_standard_option('pve-node'),
-	    id => {
-		type => 'string',
-		optional => 1,
-		pattern => '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
-		description => "The ID for the manager, when omitted the same as the nodename",
-	    },
-	},
-    },
-    returns => { type => 'string' },
-    code => sub {
-	my ($param) = @_;
-
-	PVE::Ceph::Tools::check_ceph_installed('ceph_mgr');
-
-	PVE::Ceph::Tools::check_ceph_inited();
-
-	my $rpcenv = PVE::RPCEnvironment::get();
-
-	my $authuser = $rpcenv->get_user();
-
-	my $mgrid = $param->{id} // $param->{node};
-
-	my $worker = sub  {
-	    my $upid = shift;
-
-	    my $rados = PVE::RADOS->new(timeout => PVE::Ceph::Tools::get_config('long_rados_timeout'));
-
-	    PVE::Ceph::Services::create_mgr($mgrid, $rados);
-	};
-
-	return $rpcenv->fork_worker('cephcreatemgr', "mgr.$mgrid", $authuser, $worker);
-    }});
-
-__PACKAGE__->register_method ({
-    name => 'destroymgr',
-    path => 'mgr/{id}',
-    method => 'DELETE',
-    description => "Destroy Ceph Manager.",
-    proxyto => 'node',
-    protected => 1,
-    permissions => {
-	check => ['perm', '/', [ 'Sys.Modify' ]],
-    },
-    parameters => {
-	additionalProperties => 0,
-	properties => {
-	    node => get_standard_option('pve-node'),
-	    id => {
-		description => 'The ID of the manager',
-		type => 'string',
-		pattern => '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
-	    },
-	},
-    },
-    returns => { type => 'string' },
-    code => sub {
-	my ($param) = @_;
-
-	my $rpcenv = PVE::RPCEnvironment::get();
-
-	my $authuser = $rpcenv->get_user();
-
-	PVE::Ceph::Tools::check_ceph_inited();
-
-	my $mgrid = $param->{id};
-
-	my $worker = sub {
-	    my $upid = shift;
-
-	    PVE::Ceph::Services::destroy_mgr($mgrid);
-	};
-
-	return $rpcenv->fork_worker('cephdestroymgr', "mgr.$mgrid",  $authuser, $worker);
-    }});
-
-__PACKAGE__->register_method ({
     name => 'stop',
     path => 'stop',
     method => 'POST',
diff --git a/PVE/API2/Ceph/MGR.pm b/PVE/API2/Ceph/MGR.pm
new file mode 100644
index 00000000..2ded684d
--- /dev/null
+++ b/PVE/API2/Ceph/MGR.pm
@@ -0,0 +1,104 @@
+package PVE::API2::Ceph::MGR;
+
+use strict;
+use warnings;
+
+use File::Path;
+
+use PVE::Ceph::Tools;
+use PVE::Ceph::Services;
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::RADOS;
+use PVE::RPCEnvironment;
+use PVE::Tools qw(run_command);
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method ({
+    name => 'createmgr',
+    path => '',
+    method => 'POST',
+    description => "Create Ceph Manager",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Modify' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    id => {
+		type => 'string',
+		optional => 1,
+		pattern => '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
+		description => "The ID for the manager, when omitted the same as the nodename",
+	    },
+	},
+    },
+    returns => { type => 'string' },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::Ceph::Tools::check_ceph_installed('ceph_mgr');
+
+	PVE::Ceph::Tools::check_ceph_inited();
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+
+	my $authuser = $rpcenv->get_user();
+
+	my $mgrid = $param->{id} // $param->{node};
+
+	my $worker = sub  {
+	    my $upid = shift;
+
+	    my $rados = PVE::RADOS->new(timeout => PVE::Ceph::Tools::get_config('long_rados_timeout'));
+
+	    PVE::Ceph::Services::create_mgr($mgrid, $rados);
+	};
+
+	return $rpcenv->fork_worker('cephcreatemgr', "mgr.$mgrid", $authuser, $worker);
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'destroymgr',
+    path => '{id}',
+    method => 'DELETE',
+    description => "Destroy Ceph Manager.",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Modify' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    id => {
+		description => 'The ID of the manager',
+		type => 'string',
+		pattern => '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
+	    },
+	},
+    },
+    returns => { type => 'string' },
+    code => sub {
+	my ($param) = @_;
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+
+	my $authuser = $rpcenv->get_user();
+
+	PVE::Ceph::Tools::check_ceph_inited();
+
+	my $mgrid = $param->{id};
+
+	my $worker = sub {
+	    my $upid = shift;
+
+	    PVE::Ceph::Services::destroy_mgr($mgrid);
+	};
+
+	return $rpcenv->fork_worker('cephdestroymgr', "mgr.$mgrid",  $authuser, $worker);
+    }});
diff --git a/PVE/API2/Ceph/Makefile b/PVE/API2/Ceph/Makefile
index 9a2c8791..99566cfd 100644
--- a/PVE/API2/Ceph/Makefile
+++ b/PVE/API2/Ceph/Makefile
@@ -1,6 +1,7 @@
 include ../../../defines.mk
 
 PERLSOURCE= 			\
+	MGR.pm			\
 	OSD.pm			\
 	FS.pm			\
 	MDS.pm
diff --git a/PVE/CLI/pveceph.pm b/PVE/CLI/pveceph.pm
index 84a6ef1e..294b1b82 100755
--- a/PVE/CLI/pveceph.pm
+++ b/PVE/CLI/pveceph.pm
@@ -21,6 +21,7 @@ use PVE::Ceph::Tools;
 use PVE::API2::Ceph;
 use PVE::API2::Ceph::FS;
 use PVE::API2::Ceph::MDS;
+use PVE::API2::Ceph::MGR;
 use PVE::API2::Ceph::OSD;
 
 use PVE::CLIHandler;
@@ -193,8 +194,8 @@ our $cmddef = {
     createmon => { alias => 'mon create' },
     destroymon => { alias => 'mon destroy' },
     mgr => {
-	create => [ 'PVE::API2::Ceph', 'createmgr', [], { node => $nodename }, $upid_exit],
-	destroy => [ 'PVE::API2::Ceph', 'destroymgr', ['id'], { node => $nodename }, $upid_exit],
+	create => [ 'PVE::API2::Ceph::MGR', 'createmgr', [], { node => $nodename }, $upid_exit],
+	destroy => [ 'PVE::API2::Ceph::MGR', 'destroymgr', ['id'], { node => $nodename }, $upid_exit],
     },
     createmgr => { alias => 'mgr create' },
     destroymgr => { alias => 'mgr destroy' },
-- 
2.11.0





More information about the pve-devel mailing list