]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/balancer: introduce CRUSHMap.DEFAULT_CHOOSE_ARGS and use it
authorKefu Chai <kchai@redhat.com>
Fri, 2 Feb 2018 08:23:31 +0000 (16:23 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 3 Feb 2018 17:15:56 +0000 (01:15 +0800)
avoid using '-1' as a magic variable.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/mgr/balancer/module.py
src/pybind/mgr/mgr_module.py

index 3b5d7f9379035dd35bac7b4997b6a4655b9030a9..2c5718d8341ed34a1350c97504232dcfa2b6cf98 100644 (file)
@@ -77,7 +77,7 @@ class Plan:
                   self.initial.osdmap.get_crush_version())
         ls.append('# mode %s' % self.mode)
         if len(self.compat_ws) and \
-           '-1' not in self.initial.crush_dump.get('choose_args', {}):
+           not CRUSHMap.have_default_choose_args(self.initial.crush_dump):
             ls.append('ceph osd crush weight-set create-compat')
         for osd, weight in self.compat_ws.iteritems():
             ls.append('ceph osd crush weight-set reweight-compat %s %f' %
@@ -823,7 +823,7 @@ class Module(MgrModule):
             return False
 
     def get_compat_weight_set_weights(self, ms):
-        if '-1' not in ms.crush_dump.get('choose_args', {}):
+        if not CRUSHMap.have_default_choose_args(ms.crush_dump):
             # enable compat weight-set first
             self.log.debug('ceph osd crush weight-set create-compat')
             result = CommandResult('')
@@ -852,7 +852,7 @@ class Module(MgrModule):
         else:
             crushmap = ms.crush_dump
 
-        raw = crushmap.get('choose_args',{}).get('-1', [])
+        raw = CRUSHMap.get_default_choose_args(crushmap)
         weight_set = {}
         for b in raw:
             bucket = None
@@ -885,7 +885,7 @@ class Module(MgrModule):
 
         # compat weight-set
         if len(plan.compat_ws) and \
-           '-1' not in plan.initial.crush_dump.get('choose_args', {}):
+           not CRUSHMap.have_default_choose_args(plan.initial.crush_dump):
             self.log.debug('ceph osd crush weight-set create-compat')
             result = CommandResult('')
             self.send_command(result, 'mon', '', json.dumps({
index 314c8fcd4f118ec30e55a9224c8759dd56dfe202..1e36c27ffa327887f9d3ad4d40e36d6cae86b313 100644 (file)
@@ -125,6 +125,7 @@ class OSDMapIncremental(ceph_module.BasePyOSDMapIncremental):
 
 class CRUSHMap(ceph_module.BasePyCRUSH):
     ITEM_NONE = 0x7fffffff
+    DEFAULT_CHOOSE_ARGS = '-1'
 
     def dump(self):
         return self._dump()
@@ -142,6 +143,15 @@ class CRUSHMap(ceph_module.BasePyCRUSH):
         uglymap = self._get_take_weight_osd_map(root)
         return { int(k): v for k, v in uglymap.get('weights', {}).iteritems() }
 
+    @staticmethod
+    def have_default_choose_args(dump):
+        return CRUSHMap.DEFAULT_CHOOSE_ARGS in dump.get('choose_args', {})
+
+    @staticmethod
+    def get_default_choose_args(dump):
+        return dump.get('choose_args', {}).get(CRUSHMap.DEFAULT_CHOOSE_ARGS, [])
+
+
 class MgrStandbyModule(ceph_module.BaseMgrStandbyModule):
     """
     Standby modules only implement a serve and shutdown method, they