import math
import random
import time
-from mgr_module import CLIReadCommand, CLICommand, CommandResult, MgrModule, OSDMap
+from mgr_module import CLIReadCommand, CLICommand, CommandResult, MgrModule, Option, OSDMap
from threading import Event
from typing import cast, Any, Dict, List, Optional, Sequence, Tuple, Union
from mgr_module import CRUSHMap
class Module(MgrModule):
MODULE_OPTIONS = [
- {
- 'name': 'active',
- 'type': 'bool',
- 'default': True,
- 'desc': 'automatically balance PGs across cluster',
- 'runtime': True,
- },
- {
- 'name': 'begin_time',
- 'type': 'str',
- 'default': '0000',
- 'desc': 'beginning time of day to automatically balance',
- 'long_desc': 'This is a time of day in the format HHMM.',
- 'runtime': True,
- },
- {
- 'name': 'end_time',
- 'type': 'str',
- 'default': '2400',
- 'desc': 'ending time of day to automatically balance',
- 'long_desc': 'This is a time of day in the format HHMM.',
- 'runtime': True,
- },
- {
- 'name': 'begin_weekday',
- 'type': 'uint',
- 'default': 0,
- 'min': 0,
- 'max': 7,
- 'desc': 'Restrict automatic balancing to this day of the week or later',
- 'long_desc': '0 or 7 = Sunday, 1 = Monday, etc.',
- 'runtime': True,
- },
- {
- 'name': 'end_weekday',
- 'type': 'uint',
- 'default': 7,
- 'min': 0,
- 'max': 7,
- 'desc': 'Restrict automatic balancing to days of the week earlier than this',
- 'long_desc': '0 or 7 = Sunday, 1 = Monday, etc.',
- 'runtime': True,
- },
- {
- 'name': 'crush_compat_max_iterations',
- 'type': 'uint',
- 'default': 25,
- 'min': 1,
- 'max': 250,
- 'desc': 'maximum number of iterations to attempt optimization',
- 'runtime': True,
- },
- {
- 'name': 'crush_compat_metrics',
- 'type': 'str',
- 'default': 'pgs,objects,bytes',
- 'desc': 'metrics with which to calculate OSD utilization',
- 'long_desc': 'Value is a list of one or more of "pgs", "objects", or "bytes", and indicates which metrics to use to balance utilization.',
- 'runtime': True,
- },
- {
- 'name': 'crush_compat_step',
- 'type': 'float',
- 'default': .5,
- 'min': .001,
- 'max': .999,
- 'desc': 'aggressiveness of optimization',
- 'long_desc': '.99 is very aggressive, .01 is less aggressive',
- 'runtime': True,
- },
- {
- 'name': 'min_score',
- 'type': 'float',
- 'default': 0,
- 'desc': 'minimum score, below which no optimization is attempted',
- 'runtime': True,
- },
- {
- 'name': 'mode',
- 'desc': 'Balancer mode',
- 'default': 'upmap',
- 'enum_allowed': ['none', 'crush-compat', 'upmap'],
- 'runtime': True,
- },
- {
- 'name': 'sleep_interval',
- 'type': 'secs',
- 'default': 60,
- 'desc': 'how frequently to wake up and attempt optimization',
- 'runtime': True,
- },
- {
- 'name': 'upmap_max_optimizations',
- 'type': 'uint',
- 'default': 10,
- 'desc': 'maximum upmap optimizations to make per attempt',
- 'runtime': True,
- },
- {
- 'name': 'upmap_max_deviation',
- 'type': 'int',
- 'default': 5,
- 'min': 1,
- 'desc': 'deviation below which no optimization is attempted',
- 'long_desc': 'If the number of PGs are within this count then no optimization is attempted',
- 'runtime': True,
- },
- {
- 'name': 'pool_ids',
- 'type': 'str',
- 'default': '',
- 'desc': 'pools which the automatic balancing will be limited to',
- 'runtime': True,
- },
+ Option(name='active',
+ type='bool',
+ default=True,
+ desc='automatically balance PGs across cluster',
+ runtime=True),
+ Option(name='begin_time',
+ type='str',
+ default='0000',
+ desc='beginning time of day to automatically balance',
+ long_desc='This is a time of day in the format HHMM.',
+ runtime=True),
+ Option(name='end_time',
+ type='str',
+ default='2400',
+ desc='ending time of day to automatically balance',
+ long_desc='This is a time of day in the format HHMM.',
+ runtime=True),
+ Option(name='begin_weekday',
+ type='uint',
+ default=0,
+ min=0,
+ max=7,
+ desc='Restrict automatic balancing to this day of the week or later',
+ long_desc='0 or 7 = Sunday, 1 = Monday, etc.',
+ runtime=True),
+ Option(name='end_weekday',
+ type='uint',
+ default=7,
+ min=0,
+ max=7,
+ desc='Restrict automatic balancing to days of the week earlier than this',
+ long_desc='0 or 7 = Sunday, 1 = Monday, etc.',
+ runtime=True),
+ Option(name='crush_compat_max_iterations',
+ type='uint',
+ default=25,
+ min=1,
+ max=250,
+ desc='maximum number of iterations to attempt optimization',
+ runtime=True),
+ Option(name='crush_compat_metrics',
+ type='str',
+ default='pgs,objects,bytes',
+ desc='metrics with which to calculate OSD utilization',
+ long_desc='Value is a list of one or more of "pgs", "objects", or "bytes", and indicates which metrics to use to balance utilization.',
+ runtime=True),
+ Option(name='crush_compat_step',
+ type='float',
+ default=.5,
+ min=.001,
+ max=.999,
+ desc='aggressiveness of optimization',
+ long_desc='.99 is very aggressive, .01 is less aggressive',
+ runtime=True),
+ Option(name='min_score',
+ type='float',
+ default=0,
+ desc='minimum score, below which no optimization is attempted',
+ runtime=True),
+ Option(name='mode',
+ desc='Balancer mode',
+ default='upmap',
+ enum_allowed=['none', 'crush-compat', 'upmap'],
+ runtime=True),
+ Option(name='sleep_interval',
+ type='secs',
+ default=60,
+ desc='how frequently to wake up and attempt optimization',
+ runtime=True),
+ Option(name='upmap_max_optimizations',
+ type='uint',
+ default=10,
+ desc='maximum upmap optimizations to make per attempt',
+ runtime=True),
+ Option(name='upmap_max_deviation',
+ type='int',
+ default=5,
+ min=1,
+ desc='deviation below which no optimization is attempted',
+ long_desc='If the number of PGs are within this count then no optimization is attempted',
+ runtime=True),
+ Option(name='pool_ids',
+ type='str',
+ default='',
+ desc='pools which the automatic balancing will be limited to',
+ runtime=True)
]
active = False