24
24
class ComputeFilter(filters.BaseHostFilter):
25
"""HostFilter hard-coded to work with InstanceType records."""
27
def _satisfies_extra_specs(self, capabilities, instance_type):
28
"""Check that the capabilities provided by the compute service
29
satisfy the extra specs associated with the instance type"""
30
if 'extra_specs' not in instance_type:
33
# NOTE(lorinh): For now, we are just checking exact matching on the
34
# values. Later on, we want to handle numerical
35
# values so we can represent things like number of GPU cards
36
for key, value in instance_type['extra_specs'].iteritems():
37
if capabilities.get(key, None) != value:
25
"""Filter on active Compute nodes that satisfy the instance properties"""
27
def _instance_supported(self, capabilities, instance_meta):
28
"""Check if the instance is supported by the hypervisor.
30
The instance may specify an architecture, hypervisor, and
31
vm_mode, e.g. (x86_64, kvm, hvm).
33
inst_arch = instance_meta.get('image_architecture', None)
34
inst_h_type = instance_meta.get('image_hypervisor_type', None)
35
inst_vm_mode = instance_meta.get('image_vm_mode', None)
36
inst_props_req = (inst_arch, inst_h_type, inst_vm_mode)
38
# Supported if no compute-related instance properties are specified
39
if not any(inst_props_req):
42
supp_instances = capabilities.get('supported_instances', None)
43
# Not supported if an instance property is requested but nothing
44
# advertised by the host.
45
if not supp_instances:
46
LOG.debug(_("Instance contains properties %(instance_meta)s, "
47
"but no corresponding capabilities are advertised "
48
"by the compute node"), locals())
51
def _compare_props(props, other_props):
53
if i and i not in other_props:
57
for supp_inst in supp_instances:
58
if _compare_props(inst_props_req, supp_inst):
59
LOG.debug(_("Instance properties %(instance_meta)s "
60
"are satisfied by compute host capabilities "
61
"%(capabilities)s"), locals())
64
LOG.debug(_("Instance contains properties %(instance_meta)s "
65
"that are not provided by the compute node "
66
"capabilities %(capabilities)s"), locals())
41
69
def host_passes(self, host_state, filter_properties):
42
"""Return a list of hosts that can create instance_type."""
70
"""Check if host passes instance compute properties.
72
Returns True for active compute nodes that satisfy
73
the compute properties specified in the instance.
75
spec = filter_properties.get('request_spec', {})
76
instance_props = spec.get('instance_properties', {})
77
instance_meta = instance_props.get('system_metadata', {})
43
78
instance_type = filter_properties.get('instance_type')
44
79
if host_state.topic != 'compute' or not instance_type:
51
86
"heard from in a while"), locals())
53
88
if not capabilities.get("enabled", True):
54
LOG.debug(_("%(host_state)s is disabled via capabs"), locals())
89
LOG.debug(_("%(host_state)s is disabled via capabilities"),
56
if not self._satisfies_extra_specs(capabilities, instance_type):
57
LOG.debug(_("%(host_state)s fails instance_type extra_specs "
58
"requirements"), locals())
92
if not self._instance_supported(capabilities, instance_meta):
93
LOG.debug(_("%(host_state)s does not support requested "
94
"instance_properties"), locals())