def _satisfies_extra_specs(self, capabilities, resource_type):
        """Check if capabilities satisfy resource type requirements.

        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:
                    LOG.debug("Host doesn't provide capability '%(cap)s' " %
                              {'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 if capabilities satisfy resource type requirements.

        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[scope[index]]
                except (TypeError, KeyError):
                    LOG.debug("Host doesn't provide capability '%(cap)s' " %
                              {'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
示例#3
0
    def _satisfies_extra_specs(self, capabilities, resource_type):
        """Check if capabilities satisfy resource type requirements.

        Check that the capabilities provided by the services satisfy
        the extra specs associated with the resource type.
        """

        if not resource_type:
            return True

        extra_specs = resource_type.get('extra_specs', [])
        if not extra_specs:
            return True

        for key, req in extra_specs.items():

            # Either not scoped format, or in capabilities scope
            scope = key.split(':')

            # Ignore scoped (such as vendor-specific) capabilities
            if len(scope) > 1 and scope[0] != "capabilities":
                continue
            # Strip off prefix if spec started with 'capabilities:'
            elif scope[0] == "capabilities":
                del scope[0]

            cap = capabilities
            for index in range(len(scope)):
                try:
                    cap = cap[scope[index]]
                except (TypeError, KeyError):
                    LOG.debug("Backend doesn't provide capability '%(cap)s' ",
                              {'cap': scope[index]})
                    return False

            # Make all capability values a list so we can handle lists
            cap_list = [cap] if not isinstance(cap, list) else cap

            # Loop through capability values looking for any match
            for cap_value in cap_list:
                if extra_specs_ops.match(cap_value, req):
                    break
            else:
                # Nothing matched, so bail out
                LOG.debug(
                    'Volume type extra spec requirement '
                    '"%(key)s=%(req)s" does not match reported '
                    'capability "%(cap)s"', {
                        'key': key,
                        'req': req,
                        'cap': cap
                    })
                return False
        return True
    def _satisfies_extra_specs(self, capabilities, resource_type):
        """Check if capabilities satisfy resource type requirements.

        Check that the capabilities provided by the services satisfy
        the extra specs associated with the resource type.
        """

        if not resource_type:
            return True

        extra_specs = resource_type.get('extra_specs', [])
        if not extra_specs:
            return True

        for key, req in extra_specs.items():

            # Either not scoped format, or in capabilities scope
            scope = key.split(':')

            # Ignore scoped (such as vendor-specific) capabilities
            if len(scope) > 1 and scope[0] != "capabilities":
                continue
            # Strip off prefix if spec started with 'capabilities:'
            elif scope[0] == "capabilities":
                del scope[0]

            cap = capabilities
            for index in range(len(scope)):
                try:
                    cap = cap[scope[index]]
                except (TypeError, KeyError):
                    LOG.debug("Backend doesn't provide capability '%(cap)s' ",
                              {'cap': scope[index]})
                    return False

            # Make all capability values a list so we can handle lists
            cap_list = [cap] if not isinstance(cap, list) else cap

            # Loop through capability values looking for any match
            for cap_value in cap_list:
                if extra_specs_ops.match(cap_value, req):
                    break
            else:
                # Nothing matched, so bail out
                LOG.debug('Volume type extra spec requirement '
                          '"%(key)s=%(req)s" does not match reported '
                          'capability "%(cap)s"',
                          {'key': key, 'req': req, 'cap': cap})
                return False
        return True
示例#5
0
    def _satisfies_extra_specs(self, capabilities, filter_properties):
        """Check if capabilities satisfy resource type requirements.

        Check that the capabilities provided by the services satisfy
        the extra specs associated with the resource type.
        """

        req_spec = filter_properties.get('request_spec')
        if req_spec and req_spec.get('operation') == 'extend_volume':
            # NOTE(erlon): By default, cinder considers that every backend
            # supports volume online extending. Those backends that don't
            # support it should report online_extend_support=False.
            online_extends = capabilities.get('online_extend_support', True)
            if online_extends is False:
                vol_prop = req_spec.get('volume_properties')
                attach_status = vol_prop.get('attach_status')
                if attach_status != VolumeAttachStatus.DETACHED:
                    LOG.debug("Backend doesn't support attached volume extend")
                    return False

        resource_type = filter_properties.get('resource_type')
        if not resource_type:
            return True

        extra_specs = resource_type.get('extra_specs', [])
        if not extra_specs:
            return True

        for key, req in extra_specs.items():

            # Either not scoped format, or in capabilities scope
            scope = key.split(':')

            # Ignore scoped (such as vendor-specific) capabilities
            if len(scope) > 1 and scope[0] != "capabilities":
                continue
            # Strip off prefix if spec started with 'capabilities:'
            elif scope[0] == "capabilities":
                del scope[0]

            cap = capabilities
            for index in range(len(scope)):
                try:
                    cap = cap[scope[index]]
                except (TypeError, KeyError):
                    LOG.debug("Backend doesn't provide capability '%(cap)s' ",
                              {'cap': scope[index]})
                    return False

            # Make all capability values a list so we can handle lists
            cap_list = [cap] if not isinstance(cap, list) else cap

            # Loop through capability values looking for any match
            for cap_value in cap_list:
                if extra_specs_ops.match(cap_value, req):
                    break
            else:
                # Nothing matched, so bail out
                LOG.debug('Volume type extra spec requirement '
                          '"%(key)s=%(req)s" does not match reported '
                          'capability "%(cap)s"',
                          {'key': key, 'req': req, 'cap': cap})
                return False
        return True