&max_iterations, &pool_list)) {
return nullptr;
}
+ if (!PyList_CheckExact(pool_list)) {
+ derr << __func__ << " pool_list not a list" << dendl;
+ return nullptr;
+ }
+ set<int64_t> pools;
+ for (auto i = 0; i < PyList_Size(pool_list); ++i) {
+ PyObject *pool_name = PyList_GET_ITEM(pool_list, i);
+ if (!PyString_Check(pool_name)) {
+ derr << __func__ << " " << pool_name << " not a string" << dendl;
+ return nullptr;
+ }
+ auto pool_id = self->osdmap->lookup_pg_pool_name(
+ PyString_AsString(pool_name));
+ if (pool_id < 0) {
+ derr << __func__ << " pool '" << PyString_AsString(pool_name)
+ << "' does not exist" << dendl;
+ return nullptr;
+ }
+ pools.insert(pool_id);
+ }
dout(10) << __func__ << " osdmap " << self->osdmap << " inc " << incobj->inc
<< " max_deviation " << max_deviation
<< " max_iterations " << max_iterations
+ << " pools " << pools
<< dendl;
- set<int64_t> pools;
- // FIXME: unpack pool_list and translate to pools set
int r = self->osdmap->calc_pg_upmaps(g_ceph_context,
max_deviation,
max_iterations,
return 0.0
class Plan:
- def __init__(self, name, ms):
+ def __init__(self, name, ms, pools):
self.mode = 'unknown'
self.name = name
self.initial = ms
+ self.pools = pools
self.osd_weights = {}
self.compat_ws = {}
"perm": "r",
},
{
- "cmd": "balancer optimize name=plan,type=CephString",
+ "cmd": "balancer optimize name=plan,type=CephString name=pools,type=CephString,n=N,req=false",
"desc": "Run optimizer to create a new plan",
"perm": "rw",
},
'current cluster')
return (0, self.evaluate(ms, verbose=verbose), '')
elif command['prefix'] == 'balancer optimize':
- plan = self.plan_create(command['plan'])
+ pools = []
+ if 'pools' in command:
+ pools = command['pools']
+ osdmap = self.get_osdmap()
+ valid_pool_names = [p['pool_name'] for p in osdmap.dump().get('pools', [])]
+ invalid_pool_names = []
+ for p in pools:
+ if p not in valid_pool_names:
+ invalid_pool_names.append(p)
+ if len(invalid_pool_names):
+ return (-errno.EINVAL, '', 'pools %s not found' % invalid_pool_names)
+ plan = self.plan_create(command['plan'], osdmap, pools)
self.optimize(plan)
return (0, '', '')
elif command['prefix'] == 'balancer rm':
if self.active and self.time_in_interval(timeofday, begin_time, end_time):
self.log.debug('Running')
name = 'auto_%s' % time.strftime(TIME_FORMAT, time.gmtime())
- plan = self.plan_create(name)
+ plan = self.plan_create(name, self.get_osdmap(), [])
if self.optimize(plan):
self.execute(plan)
self.plan_rm(name)
self.event.wait(sleep_interval)
self.event.clear()
- def plan_create(self, name):
- plan = Plan(name, MappingState(self.get_osdmap(),
- self.get("pg_dump"),
- 'plan %s initial' % name))
+ def plan_create(self, name, osdmap, pools):
+ plan = Plan(name,
+ MappingState(osdmap,
+ self.get("pg_dump"),
+ 'plan %s initial' % name),
+ pools)
self.plans[name] = plan
return plan
max_deviation = float(self.get_config('upmap_max_deviation', .01))
ms = plan.initial
- pools = [str(i['pool_name']) for i in ms.osdmap_dump.get('pools',[])]
+ if len(plan.pools):
+ pools = plan.pools
+ else: # all
+ pools = [str(i['pool_name']) for i in ms.osdmap_dump.get('pools',[])]
if len(pools) == 0:
self.log.info('no pools, nothing to do')
return False