def _format_filter_properties(self, context, filter_properties,
                                  request_spec):

        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", {})
        if not share_type:
            msg = _("You must create a share type in advance,"
                    " and specify in request body or"
                    " set default_share_type in manila.conf.")
            LOG.error(msg)
            raise exception.InvalidParameterValue(err=msg)

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

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

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

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

        config_options = self._get_configuration_options()

        # NOTE(ameade): If a consistency group is specified, pass the
        # consistency group support level to the ConsistencyGroupFilter
        # (host, pool, or False)
        cg_support = None
        cg = request_spec.get('consistency_group')
        if cg:
            temp_hosts = self.host_manager.get_all_host_states_share(elevated)
            cg_host = next(
                (host for host in temp_hosts if host.host == cg.get('host')),
                None)
            if cg_host:
                cg_support = cg_host.consistency_group_support

        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,
            'cg_support': cg_support,
            'consistency_group': cg,
        })

        self.populate_filter_properties_share(request_spec, filter_properties)

        return filter_properties, share_properties
Example #2
0
    def test_get_boolean_extra_specs(self):

        result = share_types.get_boolean_extra_specs()

        self.assertEqual(constants.ExtraSpecs.BOOLEAN, result)
Example #3
0
    def _format_filter_properties(self, context, filter_properties,
                                  request_spec):

        elevated = context.elevated()

        share_properties = request_spec['share_properties']
        share_instance_properties = (request_spec.get(
            'share_instance_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()
        resource_properties.update(share_instance_properties.copy())
        share_type = request_spec.get("share_type", {})
        if not share_type:
            msg = _("You must create a share type in advance,"
                    " and specify in request body or"
                    " set default_share_type in manila.conf.")
            LOG.error(msg)
            raise exception.InvalidParameterValue(err=msg)

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

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

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

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

        config_options = self._get_configuration_options()

        share_group = request_spec.get('share_group')

        # NOTE(gouthamr): If 'active_replica_host' is present in the request
        # spec, pass that host's 'replication_domain' to the
        # ShareReplication filter.
        active_replica_host = request_spec.get('active_replica_host')
        replication_domain = None
        if active_replica_host:
            temp_hosts = self.host_manager.get_all_host_states_share(elevated)
            ar_host = next((host for host in temp_hosts
                            if host.host == active_replica_host), None)
            if ar_host:
                replication_domain = ar_host.replication_domain

        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,
                                  'share_group': share_group,
                                  'replication_domain': replication_domain,
                                  })

        self.populate_filter_properties_share(request_spec, filter_properties)

        return filter_properties, share_properties
Example #4
0
    def test_get_boolean_extra_specs(self):

        result = share_types.get_boolean_extra_specs()

        self.assertEqual(constants.ExtraSpecs.BOOLEAN, result)
Example #5
0
    def _format_filter_properties(self, context, filter_properties,
                                  request_spec):

        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", {})
        if not share_type:
            msg = _("You must create a share type in advance,"
                    " and specify in request body or"
                    " set default_share_type in manila.conf.")
            LOG.error(msg)
            raise exception.InvalidParameterValue(err=msg)

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

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

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

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

        config_options = self._get_configuration_options()

        # NOTE(ameade): If a consistency group is specified, pass the
        # consistency group support level to the ConsistencyGroupFilter
        # (host, pool, or False)
        cg_support = None
        cg = request_spec.get('consistency_group')
        if cg:
            temp_hosts = self.host_manager.get_all_host_states_share(elevated)
            cg_host = next((host for host in temp_hosts
                            if host.host == cg.get('host')), None)
            if cg_host:
                cg_support = cg_host.consistency_group_support

        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,
                                  'cg_support': cg_support,
                                  'consistency_group': cg,
                                  })

        self.populate_filter_properties_share(request_spec, filter_properties)

        return filter_properties, share_properties
Example #6
0
    def _format_filter_properties(self, context, filter_properties,
                                  request_spec):

        elevated = context.elevated()

        share_properties = request_spec['share_properties']
        share_instance_properties = (request_spec.get(
            'share_instance_properties', {}))
        share_proto = request_spec.get('share_proto',
                                       share_properties.get('share_proto'))

        resource_properties = share_properties.copy()
        resource_properties.update(share_instance_properties.copy())
        share_type = request_spec.get("share_type", {})
        if not share_type:
            msg = _("You must create a share type in advance,"
                    " and specify in request body or"
                    " set default_share_type in manila.conf.")
            LOG.error(msg)
            self.message_api.create(
                context,
                message_field.Action.CREATE,
                context.project_id,
                resource_type=message_field.Resource.SHARE,
                resource_id=request_spec.get('share_id', None),
                detail=message_field.Detail.NO_DEFAULT_SHARE_TYPE)
            raise exception.InvalidParameterValue(err=msg)

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

        if share_type['extra_specs']:
            for extra_spec_name in share_types.get_boolean_extra_specs():
                extra_spec = share_type['extra_specs'].get(extra_spec_name)
                if extra_spec is not None:
                    if not extra_spec.startswith("<is>"):
                        extra_spec = "<is> %s" % extra_spec
                        share_type['extra_specs'][extra_spec_name] = extra_spec

        storage_protocol_spec = (
            share_type['extra_specs'].get('storage_protocol'))
        if storage_protocol_spec is None and share_proto is not None:
            # a host can report multiple protocols as "storage_protocol"
            spec_value = "<in> %s" % share_proto
            share_type['extra_specs']['storage_protocol'] = spec_value

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

        config_options = self._get_configuration_options()

        share_group = request_spec.get('share_group')

        # NOTE(gouthamr): If 'active_replica_host' or 'snapshot_host' is
        # present in the request spec, pass that host's 'replication_domain' to
        # the ShareReplication and CreateFromSnapshot filters.
        active_replica_host = request_spec.get('active_replica_host')
        snapshot_host = request_spec.get('snapshot_host')
        allowed_hosts = []
        if active_replica_host:
            allowed_hosts.append(active_replica_host)
        if snapshot_host:
            allowed_hosts.append(snapshot_host)
        replication_domain = None
        if active_replica_host or snapshot_host:
            temp_hosts = self.host_manager.get_all_host_states_share(elevated)
            matching_host = next(
                (host for host in temp_hosts if host.host in allowed_hosts),
                None)
            if matching_host:
                replication_domain = matching_host.replication_domain

            # NOTE(zengyingzhe): remove the 'share_backend_name' extra spec,
            # let scheduler choose the available host for this replica or
            # snapshot clone creation request.
            share_type.get('extra_specs', {}).pop('share_backend_name', None)

        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,
            'share_group': share_group,
            'replication_domain': replication_domain,
        })

        self.populate_filter_properties_share(context, request_spec,
                                              filter_properties)

        return filter_properties, share_properties
Example #7
0
    def _format_filter_properties(self, context, filter_properties,
                                  request_spec):

        elevated = context.elevated()

        share_properties = request_spec['share_properties']
        share_instance_properties = (request_spec.get(
            'share_instance_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()
        resource_properties.update(share_instance_properties.copy())
        share_type = request_spec.get("share_type", {})
        if not share_type:
            msg = _("You must create a share type in advance,"
                    " and specify in request body or"
                    " set default_share_type in manila.conf.")
            LOG.error(msg)
            raise exception.InvalidParameterValue(err=msg)

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

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

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

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

        config_options = self._get_configuration_options()

        share_group = request_spec.get('share_group')

        # NOTE(gouthamr): If 'active_replica_host' or 'snapshot_host' is
        # present in the request spec, pass that host's 'replication_domain' to
        # the ShareReplication and CreateFromSnapshot filters.
        active_replica_host = request_spec.get('active_replica_host')
        snapshot_host = request_spec.get('snapshot_host')
        allowed_hosts = []
        if active_replica_host:
            allowed_hosts.append(active_replica_host)
        if snapshot_host:
            allowed_hosts.append(snapshot_host)
        replication_domain = None
        if active_replica_host or snapshot_host:
            temp_hosts = self.host_manager.get_all_host_states_share(elevated)
            matching_host = next((host for host in temp_hosts
                                  if host.host in allowed_hosts), None)
            if matching_host:
                replication_domain = matching_host.replication_domain

            # NOTE(zengyingzhe): remove the 'share_backend_name' extra spec,
            # let scheduler choose the available host for this replica or
            # snapshot clone creation request.
            share_type.get('extra_specs', {}).pop('share_backend_name', None)

        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,
                                  'share_group': share_group,
                                  'replication_domain': replication_domain,
                                  })

        self.populate_filter_properties_share(request_spec, filter_properties)

        return filter_properties, share_properties