[pve-devel] [PATCH manager 5/8] ceph: move create/destroy pool to CephTools
Thomas Lamprecht
t.lamprecht at proxmox.com
Wed Nov 21 11:42:40 CET 2018
We will reuse this in the future, e.g., when creating a data and
metadata pool for CephFS.
Allow to pass a $rados object (to reuse it, as initializing is not
that cheap) but also create it if it's undefined, fro convenience.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
PVE/API2/Ceph.pm | 50 ++--------------------------------
PVE/CephTools.pm | 71 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 48 deletions(-)
diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index dd7f2016..854527a3 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -1620,45 +1620,7 @@ __PACKAGE__->register_method ({
my $worker = sub {
- my $rados = PVE::RADOS->new();
- $rados->mon_command({
- prefix => "osd pool create",
- pool => $pool,
- pg_num => int($pg_num),
- format => 'plain',
- });
-
- $rados->mon_command({
- prefix => "osd pool set",
- pool => $pool,
- var => 'min_size',
- val => $min_size,
- format => 'plain',
- });
-
- $rados->mon_command({
- prefix => "osd pool set",
- pool => $pool,
- var => 'size',
- val => $size,
- format => 'plain',
- });
-
- if (defined($param->{crush_rule})) {
- $rados->mon_command({
- prefix => "osd pool set",
- pool => $pool,
- var => 'crush_rule',
- val => $param->{crush_rule},
- format => 'plain',
- });
- }
-
- $rados->mon_command({
- prefix => "osd pool application enable",
- pool => $pool,
- app => $application,
- });
+ PVE::CephTools::create_pool($pool, $param);
if ($param->{add_storages}) {
my $err;
@@ -1858,15 +1820,7 @@ __PACKAGE__->register_method ({
}
}
- my $rados = PVE::RADOS->new();
- # fixme: '--yes-i-really-really-mean-it'
- $rados->mon_command({
- prefix => "osd pool delete",
- pool => $pool,
- pool2 => $pool,
- sure => '--yes-i-really-really-mean-it',
- format => 'plain',
- });
+ PVE::CephTools::destroy_pool($pool);
if ($param->{remove_storages}) {
my $err;
diff --git a/PVE/CephTools.pm b/PVE/CephTools.pm
index 1e6271f0..93d531b6 100644
--- a/PVE/CephTools.pm
+++ b/PVE/CephTools.pm
@@ -6,6 +6,7 @@ use warnings;
use File::Path;
use PVE::Tools qw(run_command dir_glob_foreach);
+use PVE::RADOS;
my $ccname = 'ceph'; # ceph cluster name
my $ceph_cfgdir = "/etc/ceph";
@@ -182,6 +183,76 @@ sub write_ceph_config {
PVE::Tools::file_set_contents($pve_ceph_cfgpath, $out);
}
+sub create_pool {
+ my ($pool, $param, $rados) = @_;
+
+ if (!defined($rados)) {
+ $rados = PVE::RADOS->new();
+ }
+
+ my $pg_num = $param->{pg_num} || 64;
+ my $size = $param->{size} || 3;
+ my $min_size = $param->{min_size} || 2;
+ my $application = $param->{application} // 'rbd';
+
+ $rados->mon_command({
+ prefix => "osd pool create",
+ pool => $pool,
+ pg_num => int($pg_num),
+ format => 'plain',
+ });
+
+ $rados->mon_command({
+ prefix => "osd pool set",
+ pool => $pool,
+ var => 'min_size',
+ val => $min_size,
+ format => 'plain',
+ });
+
+ $rados->mon_command({
+ prefix => "osd pool set",
+ pool => $pool,
+ var => 'size',
+ val => $size,
+ format => 'plain',
+ });
+
+ if (defined($param->{crush_rule})) {
+ $rados->mon_command({
+ prefix => "osd pool set",
+ pool => $pool,
+ var => 'crush_rule',
+ val => $param->{crush_rule},
+ format => 'plain',
+ });
+ }
+
+ $rados->mon_command({
+ prefix => "osd pool application enable",
+ pool => $pool,
+ app => $application,
+ });
+
+}
+
+sub destroy_pool {
+ my ($pool, $rados) = @_;
+
+ if (!defined($rados)) {
+ $rados = PVE::RADOS->new();
+ }
+
+ # fixme: '--yes-i-really-really-mean-it'
+ $rados->mon_command({
+ prefix => "osd pool delete",
+ pool => $pool,
+ pool2 => $pool,
+ sure => '--yes-i-really-really-mean-it',
+ format => 'plain',
+ });
+}
+
sub setup_pve_symlinks {
# fail if we find a real file instead of a link
if (-f $ceph_cfgpath) {
--
2.19.1
More information about the pve-devel
mailing list