~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/scheduler/filters/compute_filter.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2011 OpenStack, LLC.
 
1
# Copyright (c) 2012 OpenStack, LLC.
2
2
# All Rights Reserved.
3
3
#
4
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
22
22
 
23
23
 
24
24
class ComputeFilter(filters.BaseHostFilter):
25
 
    """HostFilter hard-coded to work with InstanceType records."""
26
 
 
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:
31
 
            return True
32
 
 
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:
38
 
                return False
39
 
        return True
 
25
    """Filter on active Compute nodes that satisfy the instance properties"""
 
26
 
 
27
    def _instance_supported(self, capabilities, instance_meta):
 
28
        """Check if the instance is supported by the hypervisor.
 
29
 
 
30
        The instance may specify an architecture, hypervisor, and
 
31
        vm_mode, e.g. (x86_64, kvm, hvm).
 
32
        """
 
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)
 
37
 
 
38
        # Supported if no compute-related instance properties are specified
 
39
        if not any(inst_props_req):
 
40
            return True
 
41
 
 
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())
 
49
            return False
 
50
 
 
51
        def _compare_props(props, other_props):
 
52
            for i in props:
 
53
                if i and i not in other_props:
 
54
                    return False
 
55
            return True
 
56
 
 
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())
 
62
                return True
 
63
 
 
64
        LOG.debug(_("Instance contains properties %(instance_meta)s "
 
65
                    "that are not provided by the compute node "
 
66
                    "capabilities %(capabilities)s"), locals())
 
67
        return False
40
68
 
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.
 
71
 
 
72
        Returns True for active compute nodes that satisfy
 
73
        the compute properties specified in the instance.
 
74
        """
 
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:
45
80
            return True
51
86
                    "heard from in a while"), locals())
52
87
            return False
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"),
 
90
                    locals())
55
91
            return False
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())
59
95
            return False
60
96
        return True