]> git.proxmox.com Git - pve-manager.git/commitdiff
ceph: move possible_flags to Ceph::Tools for intra-module reuse
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 23 Jul 2019 13:47:37 +0000 (15:47 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 23 Jul 2019 13:52:23 +0000 (15:52 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Ceph.pm
PVE/Ceph/Tools.pm

index 7a5afcaf8ed796dedf5111166f4b9edf4804ce38..367074d6e6e048c99ee1c5daa7aa723b99c797a8 100644 (file)
@@ -762,69 +762,8 @@ __PACKAGE__->register_method ({
        return $rpcenv->fork_worker('cephcreatepool', $pool,  $user, $worker);
     }});
 
-my $possible_flags = {
-    pause => {
-       description => 'Pauses read and writes.',
-       type => 'boolean',
-       optional=> 1,
-    },
-    noup => {
-       description => 'OSDs are not allowed to start.',
-       type => 'boolean',
-       optional=> 1,
-    },
-    nodown => {
-       description => 'OSD failure reports are being ignored, such that the monitors will not mark OSDs down.',
-       type => 'boolean',
-       optional=> 1,
-    },
-    noout => {
-       description => 'OSDs will not automatically be marked out after the configured interval.',
-       type => 'boolean',
-       optional=> 1,
-    },
-    noin => {
-       description => 'OSDs that were previously marked out will not be marked back in when they start.',
-       type => 'boolean',
-       optional=> 1,
-    },
-    nobackfill => {
-       description => 'Backfilling of PGs is suspended.',
-       type => 'boolean',
-       optional=> 1,
-    },
-    norebalance => {
-       description => 'Rebalancing of PGs is suspended.',
-       type => 'boolean',
-       optional=> 1,
-    },
-    norecover => {
-       description => 'Recovery of PGs is suspended.',
-       type => 'boolean',
-       optional=> 1,
-    },
-    noscrub => {
-       description => 'Scrubbing is disabled.',
-       type => 'boolean',
-       optional=> 1,
-    },
-    'nodeep-scrub' => {
-       description => 'Deep Scrubbing is disabled.',
-       type => 'boolean',
-       optional=> 1,
-    },
-    notieragent => {
-       description => 'Cache tiering activity is suspended.',
-       type => 'boolean',
-       optional=> 1,
-    },
-};
-
-# the 'pause' flag gets always set to both 'pauserd' and 'pausewr'
-# so decide that the 'pause' flag is set if we detect 'pauserd'
-my $flagmap = {
-    'pause' => 'pauserd',
-};
+my $possible_flags = PVE::Ceph::Tools::get_possible_osd_flags();
+my $possible_flags_list = [ sort keys %$possible_flags ];
 
 my $get_current_set_flags = sub {
     my $rados = shift;
@@ -861,14 +800,14 @@ __PACKAGE__->register_method ({
        my $setflags = $get_current_set_flags->();
 
        my $res = [];
-       foreach my $flag (sort keys %$possible_flags) {
+       foreach my $flag (@$possible_flags_list) {
            my $el = {
                name => $flag,
                description => $possible_flags->{$flag}->{description},
                value => 0,
            };
 
-           my $realflag = $flagmap->{$flag} // $flag;
+           my $realflag = PVE::Ceph::Tools::get_real_flag_name($flag);
            if ($setflags->{$realflag}) {
                $el->{value} = 1;
            }
@@ -940,10 +879,10 @@ __PACKAGE__->register_method ({
            my $setflags = $get_current_set_flags->($rados);
 
            my $errors = 0;
-           foreach my $flag (sort keys %$possible_flags) {
+           foreach my $flag (@$possible_flags_list) {
                next if !defined($param->{$flag});
                my $val = $param->{$flag};
-               my $realflag = $flagmap->{$flag} // $flag;
+               my $realflag = PVE::Ceph::Tools::get_real_flag_name($flag);
 
                next if !$val == !$setflags->{$realflag}; # we do not set/unset flags to the same state
 
@@ -984,7 +923,7 @@ __PACKAGE__->register_method ({
            flag => {
                description => 'The ceph flag to set',
                type => 'string',
-               enum => [sort keys %$possible_flags],
+               enum => $possible_flags_list,
            },
        },
     },
@@ -1021,7 +960,7 @@ __PACKAGE__->register_method ({
            flag => {
                description => 'The ceph flag to unset',
                type => 'string',
-               enum => [sort keys %$possible_flags],
+               enum => $possible_flags_list,
            },
        },
     },
index d268dc38203df4280944066de88960e0ed25d0ae..b95eb42480da22251416c473a549420725541d03 100644 (file)
@@ -339,5 +339,77 @@ sub get_db_wal_sizes {
 
     return $res;
 }
+sub get_possible_osd_flags {
+    my $possible_flags = {
+       pause => {
+           description => 'Pauses read and writes.',
+           type => 'boolean',
+           optional=> 1,
+       },
+       noup => {
+           description => 'OSDs are not allowed to start.',
+           type => 'boolean',
+           optional=> 1,
+       },
+       nodown => {
+           description => 'OSD failure reports are being ignored, such that the monitors will not mark OSDs down.',
+           type => 'boolean',
+           optional=> 1,
+       },
+       noout => {
+           description => 'OSDs will not automatically be marked out after the configured interval.',
+           type => 'boolean',
+           optional=> 1,
+       },
+       noin => {
+           description => 'OSDs that were previously marked out will not be marked back in when they start.',
+           type => 'boolean',
+           optional=> 1,
+       },
+       nobackfill => {
+           description => 'Backfilling of PGs is suspended.',
+           type => 'boolean',
+           optional=> 1,
+       },
+       norebalance => {
+           description => 'Rebalancing of PGs is suspended.',
+           type => 'boolean',
+           optional=> 1,
+       },
+       norecover => {
+           description => 'Recovery of PGs is suspended.',
+           type => 'boolean',
+           optional=> 1,
+       },
+       noscrub => {
+           description => 'Scrubbing is disabled.',
+           type => 'boolean',
+           optional=> 1,
+       },
+       'nodeep-scrub' => {
+           description => 'Deep Scrubbing is disabled.',
+           type => 'boolean',
+           optional=> 1,
+       },
+       notieragent => {
+           description => 'Cache tiering activity is suspended.',
+           type => 'boolean',
+           optional=> 1,
+       },
+    };
+    return $possible_flags;
+}
+
+sub get_real_flag_name {
+    my ($flag) = @_;
+
+    # the 'pause' flag gets always set to both 'pauserd' and 'pausewr'
+    # so decide that the 'pause' flag is set if we detect 'pauserd'
+    my $flagmap = {
+       'pause' => 'pauserd',
+    };
+
+    return $flagmap->{$flag} // $flag;
+}
 
 1;