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 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
Beispiel #3
0
    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 _satisfies_metadata(self, host_stats, metadata):
     req = metadata.get("storage_protocol", None)
     if req is None:
         return True
     try:
         cap = host_stats.get("storage_protocol", None)
     except AttributeError:
         try:
             cap = host_stats.capabilities.get("storage_protocol", None)
         except AttributeError:
             return False
     if cap is None:
         return False
     if not extra_specs_ops.match(cap, req):
         LOG.debug(_("storage protocol requirement '%(req)s' does not match " "'%(cap)s'"), {"req": req, "cap": cap})
         return False
     return True