From: Alwin Antreich <a.antreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager v2 1/5] ceph: split out pool set into own method
Date: Mon, 19 Oct 2020 12:39:30 +0200 [thread overview]
Message-ID: <20201019103934.1484472-1-a.antreich@proxmox.com> (raw)
to reduce code duplication and make it easier to add more options for
pool commands.
Use a new rados object for each 'osd pool set', as each command can set
an option independent of the previous commands success/failure. On
failure a new rados object would need to be created and that will
confuse task tracking of the REST environment.
Signed-off-by: Alwin Antreich <a.antreich@proxmox.com>
---
Note:
v1 -> v2:
* reorder patches, since pool create & set share common pool
options.
* include new setpool API
PVE/API2/Ceph.pm | 17 +++++++----
PVE/Ceph/Tools.pm | 74 +++++++++++++++++++++++++----------------------
2 files changed, 52 insertions(+), 39 deletions(-)
diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index d7e5892c..48d0484f 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -751,14 +751,21 @@ __PACKAGE__->register_method ({
if !PVE::JSONSchema::parse_storage_id($pool);
}
- my $pg_num = $param->{pg_num} || 128;
- my $size = $param->{size} || 3;
- my $min_size = $param->{min_size} || 2;
- my $application = $param->{application} // 'rbd';
+ my $ceph_param = \%$param;
+ for my $item ('add_storages', 'name', 'node') {
+ # not ceph parameters
+ delete $ceph_param->{$item};
+ }
+
+ # pool defaults
+ $ceph_param->{pg_num} //= 128;
+ $ceph_param->{size} //= 3;
+ $ceph_param->{min_size} //= 2;
+ $ceph_param->{application} //= 'rbd';
my $worker = sub {
- PVE::Ceph::Tools::create_pool($pool, $param);
+ PVE::Ceph::Tools::create_pool($pool, $ceph_param);
if ($param->{add_storages}) {
my $err;
diff --git a/PVE/Ceph/Tools.pm b/PVE/Ceph/Tools.pm
index 2d8a4c1d..cc4238c9 100644
--- a/PVE/Ceph/Tools.pm
+++ b/PVE/Ceph/Tools.pm
@@ -202,6 +202,45 @@ sub check_ceph_enabled {
return 1;
}
+sub set_pool {
+ my ($pool, $param) = @_;
+
+ foreach my $setting (keys %$param) {
+ my $value = $param->{$setting};
+
+ my $command;
+ if ($setting eq 'application') {
+ $command = {
+ prefix => "osd pool application enable",
+ pool => "$pool",
+ app => "$value",
+ };
+ } else {
+ $command = {
+ prefix => "osd pool set",
+ pool => "$pool",
+ var => "$setting",
+ val => "$value",
+ format => 'plain',
+ };
+ }
+
+ my $rados = PVE::RADOS->new();
+ eval { $rados->mon_command($command); };
+ if ($@) {
+ print "$@";
+ } else {
+ delete $param->{$setting};
+ }
+ }
+
+ if ((keys %$param) > 0) {
+ my @missing = join(', ', keys %$param );
+ die "Could not set: @missing\n";
+ }
+
+}
+
sub create_pool {
my ($pool, $param, $rados) = @_;
@@ -210,9 +249,6 @@ sub create_pool {
}
my $pg_num = $param->{pg_num} || 128;
- my $size = $param->{size} || 3;
- my $min_size = $param->{min_size} || 2;
- my $application = $param->{application} // 'rbd';
$rados->mon_command({
prefix => "osd pool create",
@@ -221,37 +257,7 @@ sub create_pool {
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,
- });
+ set_pool($pool, $param);
}
--
2.27.0
next reply other threads:[~2020-10-19 10:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-19 10:39 Alwin Antreich [this message]
2020-10-19 10:39 ` [pve-devel] [PATCH manager v2 2/5] ceph: allow to alter pool settings Alwin Antreich
2020-10-19 10:39 ` [pve-devel] [PATCH manager v2 3/5] ceph: use pool common options pool create Alwin Antreich
2020-10-19 10:39 ` [pve-devel] [PATCH manager v2 4/5] ceph: add pg_autoscale_mode to " Alwin Antreich
2020-10-19 10:39 ` [pve-devel] [PATCH manager v2 5/5] ceph: gui: add autoscale mode " Alwin Antreich
2020-10-22 16:52 ` [pve-devel] applied-series: [PATCH manager v2 1/5] ceph: split out pool set into own method Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201019103934.1484472-1-a.antreich@proxmox.com \
--to=a.antreich@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.