Coverage for manila/scheduler/filters/capabilities.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +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 

16from oslo_log import log 

17 

18from manila.scheduler.filters import base_host 

19from manila.scheduler import utils 

20 

21LOG = log.getLogger(__name__) 

22 

23 

24class CapabilitiesFilter(base_host.BaseHostFilter): 

25 """HostFilter to work with resource (instance & volume) type records.""" 

26 

27 def _satisfies_extra_specs(self, capabilities, resource_type): 

28 """Compare capabilities against extra specs. 

29 

30 Check that the capabilities provided by the services satisfy 

31 the extra specs associated with the resource type. 

32 """ 

33 extra_specs = resource_type.get('extra_specs', []) 

34 if not extra_specs: 

35 return True 

36 

37 return utils.capabilities_satisfied(capabilities, extra_specs) 

38 

39 def host_passes(self, host_state, filter_properties): 

40 """Return a list of hosts that can create resource_type.""" 

41 resource_type = filter_properties.get('resource_type') 

42 

43 if not self._satisfies_extra_specs(host_state.capabilities, 

44 resource_type): 

45 LOG.debug("%(host_state)s fails resource_type extra_specs " 

46 "requirements", {'host_state': host_state}) 

47 return False 

48 return True