Coverage for manila/scheduler/weighers/pool.py: 100%
23 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright 2015 Mirantis Inc.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
16from oslo_config import cfg
18from manila import context
19from manila.db import api as db_api
20from manila.scheduler.weighers import base_host
21from manila.share import utils
23pool_weight_opts = [
24 cfg.FloatOpt('pool_weight_multiplier',
25 default=1.0,
26 help='Multiplier used for weighing pools which have '
27 'existing share servers. Negative numbers mean to spread'
28 ' vs stack.'),
29]
31CONF = cfg.CONF
32CONF.register_opts(pool_weight_opts)
35class PoolWeigher(base_host.BaseHostWeigher):
36 def weight_multiplier(self):
37 """Override the weight multiplier."""
38 return CONF.pool_weight_multiplier
40 def _weigh_object(self, host_state, weight_properties):
41 """Pools with existing share server win."""
42 pool_mapping = weight_properties.get('server_pools_mapping', {})
43 if not pool_mapping:
44 return 0
46 ctx = context.get_admin_context()
47 host = utils.extract_host(host_state.host, 'backend')
48 servers = db_api.share_server_get_all_by_host(ctx, host)
49 pool = utils.extract_host(host_state.host, 'pool')
50 for server in servers:
51 if any(pool == p['pool_name'] for p in pool_mapping.get(
52 server['id'], [])):
53 return 1
54 return 0