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

16 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-24 11:16 +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 

16""" 

17Scheduler host weights 

18""" 

19 

20from nova import weights 

21 

22 

23class WeighedHost(weights.WeighedObject): 

24 def to_dict(self): 

25 x = dict(weight=self.weight) 

26 x['host'] = self.obj.host 

27 return x 

28 

29 def __repr__(self): 

30 return "WeighedHost [host: %r, weight: %s]" % ( 

31 self.obj, self.weight) 

32 

33 

34class BaseHostWeigher(weights.BaseWeigher): 

35 """Base class for host weights.""" 

36 pass 

37 

38 

39class HostWeightHandler(weights.BaseWeightHandler): 

40 object_class = WeighedHost 

41 

42 def __init__(self): 

43 super(HostWeightHandler, self).__init__(BaseHostWeigher) 

44 

45 

46def all_weighers(): 

47 """Return a list of weight plugin classes found in this directory.""" 

48 return HostWeightHandler().get_all_classes()