From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 5A546603D5 for ; Wed, 14 Oct 2020 16:04:27 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 509AFAC15 for ; Wed, 14 Oct 2020 16:03:57 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 11DEBAC07 for ; Wed, 14 Oct 2020 16:03:56 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D144F45D5F for ; Wed, 14 Oct 2020 16:03:55 +0200 (CEST) From: Alwin Antreich To: pve-devel@lists.proxmox.com Date: Wed, 14 Oct 2020 16:03:51 +0200 Message-Id: <20201014140352.2136911-1-a.antreich@proxmox.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.000 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [ceph.pm, tools.pm] Subject: [pve-devel] [PATCH manager 1/2] ceph: split out pool set into own method X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Oct 2020 14:04:27 -0000 to reduce code duplication and make it easier to add more options for pool commands. Signed-off-by: Alwin Antreich --- 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