Esempio n. 1
0
    def _get_share_networks(self, req, is_detail=True):
        """Returns a list of share networks."""
        context = req.environ["manila.context"]
        search_opts = {}
        search_opts.update(req.GET)

        if "all_tenants" in search_opts or (
            "project_id" in search_opts and search_opts["project_id"] != context.project_id
        ):
            policy.check_policy(context, RESOURCE_NAME, "get_all_share_networks")

        if "security_service_id" in search_opts:
            networks = db_api.share_network_get_all_by_security_service(context, search_opts["security_service_id"])
        elif "project_id" in search_opts and search_opts["project_id"] != context.project_id:
            networks = db_api.share_network_get_all_by_project(context, search_opts["project_id"])
        elif "all_tenants" in search_opts:
            networks = db_api.share_network_get_all(context)
        else:
            networks = db_api.share_network_get_all_by_project(context, context.project_id)

        date_parsing_error_msg = """%s is not in yyyy-mm-dd format."""
        if "created_since" in search_opts:
            try:
                created_since = timeutils.parse_strtime(search_opts["created_since"], fmt="%Y-%m-%d")
            except ValueError:
                msg = date_parsing_error_msg % search_opts["created_since"]
                raise exc.HTTPBadRequest(explanation=msg)
            networks = [network for network in networks if network["created_at"] >= created_since]
        if "created_before" in search_opts:
            try:
                created_before = timeutils.parse_strtime(search_opts["created_before"], fmt="%Y-%m-%d")
            except ValueError:
                msg = date_parsing_error_msg % search_opts["created_before"]
                raise exc.HTTPBadRequest(explanation=msg)
            networks = [network for network in networks if network["created_at"] <= created_before]
        opts_to_remove = ["all_tenants", "created_since", "created_before", "limit", "offset", "security_service_id"]
        for opt in opts_to_remove:
            search_opts.pop(opt, None)
        if search_opts:
            for key, value in six.iteritems(search_opts):
                if key in ["ip_version", "segmentation_id"]:
                    value = int(value)
                networks = [network for network in networks if network[key] == value]

        limited_list = common.limited(networks, req)
        return self._view_builder.build_share_networks(limited_list, is_detail)
Esempio n. 2
0
    def test_get_all_by_project(self):
        share_nw_dict2 = dict(self.share_nw_dict)
        share_nw_dict2["id"] = "fake share nw id2"
        share_nw_dict2["project_id"] = "fake project 2"
        share_nw_dict2["neutron_subnet_id"] = "fake subnet id2"
        db_api.share_network_create(self.fake_context, self.share_nw_dict)
        db_api.share_network_create(self.fake_context, share_nw_dict2)

        result = db_api.share_network_get_all_by_project(self.fake_context, share_nw_dict2["project_id"])

        self.assertEqual(len(result), 1)
        self._check_fields(expected=share_nw_dict2, actual=result[0])
Esempio n. 3
0
    def test_get_all_by_project(self):
        share_nw_dict2 = dict(self.share_nw_dict)
        share_nw_dict2['id'] = 'fake share nw id2'
        share_nw_dict2['project_id'] = 'fake project 2'
        share_nw_dict2['neutron_subnet_id'] = 'fake subnet id2'
        db_api.share_network_create(self.fake_context, self.share_nw_dict)
        db_api.share_network_create(self.fake_context, share_nw_dict2)

        result = db_api.share_network_get_all_by_project(
            self.fake_context, share_nw_dict2['project_id'])

        self.assertEqual(len(result), 1)
        self._check_fields(expected=share_nw_dict2, actual=result[0])
Esempio n. 4
0
    def _get_share_networks(self, req, is_detail=True):
        """Returns a list of share networks."""
        context = req.environ["manila.context"]
        policy.check_policy(context, RESOURCE_NAME, "index")

        search_opts = {}
        search_opts.update(req.GET)

        if search_opts.pop("all_tenants", None):
            networks = db_api.share_network_get_all(context)
        else:
            networks = db_api.share_network_get_all_by_project(context, context.project_id)

        if search_opts:
            for key, value in search_opts.iteritems():
                networks = [network for network in networks if network[key] == value]
        return self._view_builder.build_share_networks(networks, is_detail)
Esempio n. 5
0
    def _get_share_networks(self, req, is_detail=True):
        """Returns a list of share networks."""
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME, 'index')

        search_opts = {}
        search_opts.update(req.GET)

        if search_opts.pop('all_tenants', None):
            networks = db_api.share_network_get_all(context)
        else:
            networks = db_api.share_network_get_all_by_project(
                context,
                context.project_id)

        if search_opts:
            for key, value in six.iteritems(search_opts):
                networks = [network for network in networks
                            if network[key] == value]
        return self._view_builder.build_share_networks(networks, is_detail)
Esempio n. 6
0
    def _get_share_networks(self, req, is_detail=True):
        """Returns a list of share networks."""
        context = req.environ['manila.context']
        search_opts = {}
        search_opts.update(req.GET)

        if ('all_tenants' in search_opts or
            ('project_id' in search_opts and
             search_opts['project_id'] != context.project_id)):
                policy.check_policy(context, RESOURCE_NAME,
                                    'get_all_share_networks')

        if 'security_service_id' in search_opts:
            networks = db_api.share_network_get_all_by_security_service(
                context, search_opts['security_service_id'])
        elif ('project_id' in search_opts and
              search_opts['project_id'] != context.project_id):
            networks = db_api.share_network_get_all_by_project(
                context, search_opts['project_id'])
        elif 'all_tenants' in search_opts:
            networks = db_api.share_network_get_all(context)
        else:
            networks = db_api.share_network_get_all_by_project(
                context,
                context.project_id)

        date_parsing_error_msg = '''%s is not in yyyy-mm-dd format.'''
        if 'created_since' in search_opts:
            try:
                created_since = timeutils.parse_strtime(
                    search_opts['created_since'],
                    fmt="%Y-%m-%d")
            except ValueError:
                msg = date_parsing_error_msg % search_opts['created_since']
                raise exc.HTTPBadRequest(explanation=msg)
            networks = [network for network in networks
                        if network['created_at'] >= created_since]
        if 'created_before' in search_opts:
            try:
                created_before = timeutils.parse_strtime(
                    search_opts['created_before'],
                    fmt="%Y-%m-%d")
            except ValueError:
                msg = date_parsing_error_msg % search_opts['created_before']
                raise exc.HTTPBadRequest(explanation=msg)
            networks = [network for network in networks
                        if network['created_at'] <= created_before]
        opts_to_remove = [
            'all_tenants',
            'created_since',
            'created_before',
            'limit',
            'offset',
            'security_service_id',
        ]
        for opt in opts_to_remove:
            search_opts.pop(opt, None)
        if search_opts:
            for key, value in search_opts.items():
                if key in ['ip_version', 'segmentation_id']:
                    value = int(value)
                networks = [network for network in networks
                            if network[key] == value]

        limited_list = common.limited(networks, req)
        return self._view_builder.build_share_networks(limited_list, is_detail)
Esempio n. 7
0
    def _get_share_networks(self, req, is_detail=True):
        """Returns a list of share networks."""
        context = req.environ['manila.context']
        search_opts = {}
        search_opts.update(req.GET)

        if 'security_service_id' in search_opts:
            networks = db_api.share_network_get_all_by_security_service(
                context, search_opts['security_service_id'])
        elif context.is_admin and 'project_id' in search_opts:
            networks = db_api.share_network_get_all_by_project(
                context, search_opts['project_id'])
        elif context.is_admin and utils.is_all_tenants(search_opts):
            networks = db_api.share_network_get_all(context)
        else:
            networks = db_api.share_network_get_all_by_project(
                context, context.project_id)

        date_parsing_error_msg = '''%s is not in yyyy-mm-dd format.'''
        if 'created_since' in search_opts:
            try:
                created_since = timeutils.parse_strtime(
                    search_opts['created_since'], fmt="%Y-%m-%d")
            except ValueError:
                msg = date_parsing_error_msg % search_opts['created_since']
                raise exc.HTTPBadRequest(explanation=msg)
            networks = [
                network for network in networks
                if network['created_at'] >= created_since
            ]
        if 'created_before' in search_opts:
            try:
                created_before = timeutils.parse_strtime(
                    search_opts['created_before'], fmt="%Y-%m-%d")
            except ValueError:
                msg = date_parsing_error_msg % search_opts['created_before']
                raise exc.HTTPBadRequest(explanation=msg)
            networks = [
                network for network in networks
                if network['created_at'] <= created_before
            ]
        opts_to_remove = [
            'all_tenants', 'created_since', 'created_before', 'limit',
            'offset', 'security_service_id', 'project_id'
        ]
        for opt in opts_to_remove:
            search_opts.pop(opt, None)
        if search_opts:
            for key, value in search_opts.items():
                if key in ['ip_version', 'segmentation_id']:
                    value = int(value)
                if (req.api_version_request >=
                        api_version.APIVersionRequest("2.36")):
                    networks = [
                        network for network in networks
                        if network.get(key) == value
                        or self._subnet_has_search_opt(key, value, network) or
                        (value in network.get(key.rstrip('~')) if key.endswith(
                            '~') and network.get(key.rstrip('~')) else ())
                    ]
                else:
                    networks = [
                        network for network in networks
                        if network.get(key) == value
                        or self._subnet_has_search_opt(
                            key, value, network, exact_value=True)
                    ]

        limited_list = common.limited(networks, req)
        return self._view_builder.build_share_networks(req, limited_list,
                                                       is_detail)
Esempio n. 8
0
    def _get_share_networks(self, req, is_detail=True):
        """Returns a list of share networks."""
        context = req.environ['manila.context']
        search_opts = {}
        search_opts.update(req.GET)

        if 'security_service_id' in search_opts:
            networks = db_api.share_network_get_all_by_security_service(
                context, search_opts['security_service_id'])
        elif context.is_admin and 'project_id' in search_opts:
            networks = db_api.share_network_get_all_by_project(
                context, search_opts['project_id'])
        elif context.is_admin and utils.is_all_tenants(search_opts):
            networks = db_api.share_network_get_all(context)
        else:
            networks = db_api.share_network_get_all_by_project(
                context,
                context.project_id)

        date_parsing_error_msg = '''%s is not in yyyy-mm-dd format.'''
        if 'created_since' in search_opts:
            try:
                created_since = timeutils.parse_strtime(
                    search_opts['created_since'],
                    fmt="%Y-%m-%d")
            except ValueError:
                msg = date_parsing_error_msg % search_opts['created_since']
                raise exc.HTTPBadRequest(explanation=msg)
            networks = [network for network in networks
                        if network['created_at'] >= created_since]
        if 'created_before' in search_opts:
            try:
                created_before = timeutils.parse_strtime(
                    search_opts['created_before'],
                    fmt="%Y-%m-%d")
            except ValueError:
                msg = date_parsing_error_msg % search_opts['created_before']
                raise exc.HTTPBadRequest(explanation=msg)
            networks = [network for network in networks
                        if network['created_at'] <= created_before]
        opts_to_remove = [
            'all_tenants',
            'created_since',
            'created_before',
            'limit',
            'offset',
            'security_service_id',
            'project_id'
        ]
        for opt in opts_to_remove:
            search_opts.pop(opt, None)
        if search_opts:
            for key, value in search_opts.items():
                if key in ['ip_version', 'segmentation_id']:
                    value = int(value)
                if (req.api_version_request >=
                        api_version.APIVersionRequest("2.36")):
                    networks = [network for network in networks
                                if network.get(key) == value or
                                (value in network.get(key.rstrip('~'))
                                 if key.endswith('~') and
                                 network.get(key.rstrip('~')) else ())]
                else:
                    networks = [network for network in networks
                                if network.get(key) == value]

        limited_list = common.limited(networks, req)
        return self._view_builder.build_share_networks(
            req, limited_list, is_detail)