Exemplo n.º 1
0
    def test_get_share_type_required_extra_specs(self):
        valid_required_extra_specs = (
            constants.ExtraSpecs.DRIVER_HANDLES_SHARE_SERVERS,)

        actual_result = share_types.get_required_extra_specs()

        self.assertEqual(valid_required_extra_specs, actual_result)
Exemplo n.º 2
0
    def _get_weighted_hosts_for_share_type(self, context, request_spec,
                                           share_type):
        config_options = self._get_configuration_options()
        # NOTE(ameade): Find our local list of acceptable hosts by
        # filtering and weighing our options. We virtually consume
        # resources on it so subsequent selections can adjust accordingly.

        # NOTE(ameade): Remember, we are using an iterator here. So only
        # traverse this list once.
        all_hosts = self.host_manager.get_all_host_states_share(context)

        if not all_hosts:
            return []

        share_type['extra_specs'] = share_type.get('extra_specs', {})

        if share_type['extra_specs']:
            for spec_name in share_types.get_required_extra_specs():
                extra_spec = share_type['extra_specs'].get(spec_name)

                if extra_spec is not None:
                    share_type['extra_specs'][spec_name] = (
                        "<is> %s" % extra_spec)

        filter_properties = {
            'context': context,
            'request_spec': request_spec,
            'config_options': config_options,
            'share_type': share_type,
            'resource_type': share_type,
            'size': 0,
        }
        # Filter local hosts based on requirements ...
        hosts, last_filter = self.host_manager.get_filtered_hosts(
            all_hosts, filter_properties)

        if not hosts:
            return []

        LOG.debug("Filtered %s", hosts)

        # weighted_host = WeightedHost() ... the best host for the job.
        weighed_hosts = self.host_manager.get_weighed_hosts(
            hosts,
            filter_properties)
        if not weighed_hosts:
            return []

        return weighed_hosts
Exemplo n.º 3
0
    def _delete(self, req, type_id, id):
        """Deletes an existing extra spec."""
        context = req.environ['manila.context']

        if id in share_types.get_required_extra_specs():
            msg = _("Extra spec '%s' can't be deleted.") % id
            raise webob.exc.HTTPForbidden(explanation=msg)

        try:
            db.share_type_extra_specs_delete(context, type_id, id)
        except exception.ShareTypeExtraSpecsNotFound as error:
            raise webob.exc.HTTPNotFound(explanation=error.msg)

        notifier_info = dict(type_id=type_id, id=id)
        notifier = rpc.get_notifier('shareTypeExtraSpecs')
        notifier.info(context, 'share_type_extra_specs.delete', notifier_info)
        return webob.Response(status_int=http_client.ACCEPTED)
    def _delete(self, req, type_id, id):
        """Deletes an existing extra spec."""
        context = req.environ['manila.context']

        if id in share_types.get_required_extra_specs():
            msg = _("Extra spec '%s' can't be deleted.") % id
            raise webob.exc.HTTPForbidden(explanation=msg)

        try:
            db.share_type_extra_specs_delete(context, type_id, id)
        except exception.ShareTypeExtraSpecsNotFound as error:
            raise webob.exc.HTTPNotFound(explanation=error.msg)

        notifier_info = dict(type_id=type_id, id=id)
        notifier = rpc.get_notifier('shareTypeExtraSpecs')
        notifier.info(context, 'share_type_extra_specs.delete', notifier_info)
        return webob.Response(status_int=202)
Exemplo n.º 5
0
    def test_get_required_extra_specs(self):

        result = share_types.get_required_extra_specs()

        self.assertEqual(constants.ExtraSpecs.REQUIRED, result)
Exemplo n.º 6
0
    def _schedule_share(self, context, request_spec, filter_properties=None):
        """Returns a list of hosts that meet the required specs.

        The list is ordered by their fitness.
        """
        elevated = context.elevated()

        share_properties = request_spec["share_properties"]
        # Since Manila is using mixed filters from Oslo and it's own, which
        # takes 'resource_XX' and 'volume_XX' as input respectively, copying
        # 'volume_XX' to 'resource_XX' will make both filters happy.
        resource_properties = share_properties.copy()
        share_type = request_spec.get("share_type", {})

        extra_specs = share_type.get("extra_specs", {})

        if extra_specs:
            for extra_spec_name in share_types.get_required_extra_specs():
                extra_spec = extra_specs.get(extra_spec_name)

                if extra_spec is not None:
                    share_type["extra_specs"][extra_spec_name] = "<is> %s" % extra_spec

        resource_type = request_spec.get("share_type") or {}
        request_spec.update({"resource_properties": resource_properties})

        config_options = self._get_configuration_options()

        if filter_properties is None:
            filter_properties = {}
        self._populate_retry_share(filter_properties, resource_properties)

        filter_properties.update(
            {
                "context": context,
                "request_spec": request_spec,
                "config_options": config_options,
                "share_type": share_type,
                "resource_type": resource_type,
            }
        )

        self.populate_filter_properties_share(request_spec, filter_properties)

        # Find our local list of acceptable hosts by filtering and
        # weighing our options. we virtually consume resources on
        # it so subsequent selections can adjust accordingly.

        # Note: remember, we are using an iterator here. So only
        # traverse this list once.
        hosts = self.host_manager.get_all_host_states_share(elevated)

        # Filter local hosts based on requirements ...
        hosts = self.host_manager.get_filtered_hosts(hosts, filter_properties)
        if not hosts:
            return None

        LOG.debug("Filtered share %(hosts)s", {"hosts": hosts})
        # weighted_host = WeightedHost() ... the best
        # host for the job.
        weighed_hosts = self.host_manager.get_weighed_hosts(hosts, filter_properties)
        best_host = weighed_hosts[0]
        LOG.debug("Choosing for share: %(best_host)s", {"best_host": best_host})
        # NOTE(rushiagr): updating the available space parameters at same place
        best_host.obj.consume_from_share(share_properties)
        return best_host
Exemplo n.º 7
0
    def _schedule_share(self, context, request_spec, filter_properties=None):
        """Returns a list of hosts that meet the required specs.

        The list is ordered by their fitness.
        """
        elevated = context.elevated()

        share_properties = request_spec['share_properties']
        # Since Manila is using mixed filters from Oslo and it's own, which
        # takes 'resource_XX' and 'volume_XX' as input respectively, copying
        # 'volume_XX' to 'resource_XX' will make both filters happy.
        resource_properties = share_properties.copy()
        share_type = request_spec.get("share_type", {})

        extra_specs = share_type.get('extra_specs', {})

        if extra_specs:
            for extra_spec_name in share_types.get_required_extra_specs():
                extra_spec = extra_specs.get(extra_spec_name)

                if extra_spec is not None:
                    share_type['extra_specs'][extra_spec_name] = ("<is> %s" %
                                                                  extra_spec)

        resource_type = request_spec.get("share_type") or {}
        request_spec.update({'resource_properties': resource_properties})

        config_options = self._get_configuration_options()

        if filter_properties is None:
            filter_properties = {}
        self._populate_retry_share(filter_properties, resource_properties)

        filter_properties.update({
            'context': context,
            'request_spec': request_spec,
            'config_options': config_options,
            'share_type': share_type,
            'resource_type': resource_type
        })

        self.populate_filter_properties_share(request_spec, filter_properties)

        # Find our local list of acceptable hosts by filtering and
        # weighing our options. we virtually consume resources on
        # it so subsequent selections can adjust accordingly.

        # Note: remember, we are using an iterator here. So only
        # traverse this list once.
        hosts = self.host_manager.get_all_host_states_share(elevated)

        # Filter local hosts based on requirements ...
        hosts = self.host_manager.get_filtered_hosts(hosts, filter_properties)
        if not hosts:
            return None

        LOG.debug("Filtered share %(hosts)s", {"hosts": hosts})
        # weighted_host = WeightedHost() ... the best
        # host for the job.
        weighed_hosts = self.host_manager.get_weighed_hosts(
            hosts, filter_properties)
        best_host = weighed_hosts[0]
        LOG.debug("Choosing for share: %(best_host)s",
                  {"best_host": best_host})
        # NOTE(rushiagr): updating the available space parameters at same place
        best_host.obj.consume_from_share(share_properties)
        return best_host
Exemplo n.º 8
0
    def test_get_required_extra_specs(self):

        result = share_types.get_required_extra_specs()

        self.assertEqual(constants.ExtraSpecs.REQUIRED, result)