From 34a2222dd8cf6b21c590cce444283e0b2fa8cadf Mon Sep 17 00:00:00 2001 From: Aaron Lauterer Date: Thu, 28 Apr 2022 13:58:06 +0200 Subject: [PATCH] ceph tools: add erasure code management functions Functions to manage erasure code (EC) profiles: * add * remove * check if exists * get default prefixed name * get pool properties * destroy crush rule Signed-off-by: Aaron Lauterer --- PVE/Ceph/Tools.pm | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/PVE/Ceph/Tools.pm b/PVE/Ceph/Tools.pm index 7291aa23..2459e882 100644 --- a/PVE/Ceph/Tools.pm +++ b/PVE/Ceph/Tools.pm @@ -255,6 +255,19 @@ sub set_pool { } +sub get_pool_properties { + my ($pool) = @_; + my $command = { + prefix => "osd pool get", + pool => "$pool", + var => "all", + format => 'json', + }; + + my $rados = PVE::RADOS->new(); + return $rados->mon_command($command); +} + sub create_pool { my ($pool, $param, $rados) = @_; $rados = PVE::RADOS->new() if !defined($rados); @@ -516,4 +529,63 @@ sub ceph_cluster_status { return $status; } +sub ecprofile_exists { + my ($name) = @_; + + my $rados = PVE::RADOS->new(); + my $res = $rados->mon_command({ prefix => 'osd erasure-code-profile ls' }); + + my $profiles = { map { $_ => 1 } @$res }; + return $profiles->{$name}; +} + +sub create_ecprofile { + my ($name, $k, $m, $failure_domain, $device_class) = @_; + + $failure_domain = 'host' if !$failure_domain; + + my $profile = [ + "crush-failure-domain=${failure_domain}", + "k=${k}", + "m=${m}", + ]; + + push(@$profile, "crush-device-class=${device_class}") if $device_class; + + my $rados = PVE::RADOS->new(); + $rados->mon_command({ + prefix => 'osd erasure-code-profile set', + name => $name, + profile => $profile, + }); +} + +sub destroy_ecprofile { + my ($profile) = @_; + + my $rados = PVE::RADOS->new(); + my $command = { + prefix => 'osd erasure-code-profile rm', + name => $profile, + format => 'plain', + }; + return $rados->mon_command($command); +} + +sub get_ecprofile_name { + my ($name) = @_; + return "pve_ec_${name}"; +} + +sub destroy_crush_rule { + my ($rule) = @_; + my $rados = PVE::RADOS->new(); + my $command = { + prefix => 'osd crush rule rm', + name => $rule, + format => 'plain', + }; + return $rados->mon_command($command); +} + 1;