def _satisfies_extra_specs(self, capabilities, resource_type):
        """Check that the capabilities provided by the services satisfy
        the extra specs associated with the resource type.
        """
        extra_specs = resource_type.get('extra_specs', [])
        if not extra_specs:
            return True

        for key, req in six.iteritems(extra_specs):
            # Either not scope format, or in capabilities scope
            scope = key.split(':')
            if len(scope) > 1 and scope[0] != "capabilities":
                continue
            elif scope[0] == "capabilities":
                del scope[0]

            cap = capabilities
            for index in range(len(scope)):
                try:
                    cap = cap.get(scope[index])
                except AttributeError:
                    cap = None
                if cap is None:
                    LOG.debug("Host doesn't provide capability '%(cap)s' "
                              "listed in the extra specs",
                              {'cap': scope[index]})
                    return False
            if not extra_specs_ops.match(cap, req):
                LOG.debug("extra_spec requirement '%(req)s' "
                          "does not match '%(cap)s'",
                          {'req': req, 'cap': cap})
                return False
        return True
    def _satisfies_extra_specs(self, capabilities, resource_type):
        """Check that the capabilities provided by the services
        satisfy the extra specs associated with the instance type"""
        extra_specs = resource_type.get('extra_specs', [])
        if not extra_specs:
            return True

        for key, req in extra_specs.iteritems():
            # Either not scope format, or in capabilities scope
            scope = key.split(':')
            if len(scope) > 1 and scope[0] != "capabilities":
                continue
            elif scope[0] == "capabilities":
                del scope[0]

            cap = capabilities
            for index in range(0, len(scope)):
                try:
                    cap = cap.get(scope[index], None)
                except AttributeError:
                    return False
                if cap is None:
                    return False
            if not extra_specs_ops.match(cap, req):
                return False
        return True
    def _satisfies_extra_specs(self, capabilities, resource_type):
        """Check that the capabilities provided by the services satisfy
        the extra specs associated with the resource type.
        """
        extra_specs = resource_type.get('extra_specs', [])
        if not extra_specs:
            return True

        for key, req in six.iteritems(extra_specs):
            # Either not scope format, or in capabilities scope
            scope = key.split(':')
            if len(scope) > 1 and scope[0] != "capabilities":
                continue
            elif scope[0] == "capabilities":
                del scope[0]

            cap = capabilities
            for index in range(len(scope)):
                try:
                    cap = cap.get(scope[index])
                except AttributeError:
                    return False
                if cap is None:
                    return False
            if not extra_specs_ops.match(cap, req):
                LOG.debug(
                    "extra_spec requirement '%(req)s' "
                    "does not match '%(cap)s'", {
                        'req': req,
                        'cap': cap
                    })
                return False
        return True
 def _do_extra_specs_ops_test(self, value, req, matches):
     assertion = self.assertTrue if matches else self.assertFalse
     assertion(extra_specs_ops.match(value, req))
Example #5
0
 def _do_extra_specs_ops_test(self, value, req, matches):
     assertion = self.assertTrue if matches else self.assertFalse
     assertion(extra_specs_ops.match(value, req))