Coverage for nova/scheduler/weights/ram.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-17 15:08 +0000

1# Copyright (c) 2011 OpenStack Foundation 

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. 

15""" 

16RAM Weigher. Weigh hosts by their RAM usage. 

17 

18The default is to spread instances across all hosts evenly. If you prefer 

19stacking, you can set the 'ram_weight_multiplier' option (by configuration 

20or aggregate metadata) to a negative number and the weighing has the opposite 

21effect of the default. 

22""" 

23 

24import nova.conf 

25from nova.scheduler import utils 

26from nova.scheduler import weights 

27 

28CONF = nova.conf.CONF 

29 

30 

31class RAMWeigher(weights.BaseHostWeigher): 

32 minval = 0 

33 

34 def weight_multiplier(self, host_state): 

35 """Override the weight multiplier.""" 

36 return utils.get_weight_multiplier( 

37 host_state, 'ram_weight_multiplier', 

38 CONF.filter_scheduler.ram_weight_multiplier) 

39 

40 def _weigh_object(self, host_state, weight_properties): 

41 """Higher weights win. We want spreading to be the default.""" 

42 return host_state.free_ram_mb