예제 #1
0
 def test_limiter_limit_over_max(self):
     """Test limit of 3000."""
     req = webob.Request.blank('/?limit=3000')
     self.assertEqual(self.tiny, common.limited(self.tiny, req))
     self.assertEqual(self.small, common.limited(self.small, req))
     self.assertEqual(self.medium, common.limited(self.medium, req))
     self.assertEqual(self.large[:1000], common.limited(self.large, req))
예제 #2
0
 def test_limiter_offset_over_max(self):
     """Test offset key works with a number over 1000 (max_limit)."""
     req = webob.Request.blank("/?offset=1001")
     self.assertEqual(common.limited(self.tiny, req), [])
     self.assertEqual(common.limited(self.small, req), [])
     self.assertEqual(common.limited(self.medium, req), [])
     self.assertEqual(common.limited(self.large, req), self.large[1001:2001])
예제 #3
0
 def test_limiter_nothing(self):
     """Test request with no offset or limit."""
     req = webob.Request.blank("/")
     self.assertEqual(common.limited(self.tiny, req), self.tiny)
     self.assertEqual(common.limited(self.small, req), self.small)
     self.assertEqual(common.limited(self.medium, req), self.medium)
     self.assertEqual(common.limited(self.large, req), self.large[:1000])
예제 #4
0
 def test_limiter_limit_medium(self):
     """Test limit of 10."""
     req = webob.Request.blank('/?limit=10')
     self.assertEqual(self.tiny, common.limited(self.tiny, req))
     self.assertEqual(self.small, common.limited(self.small, req))
     self.assertEqual(self.medium[:10], common.limited(self.medium, req))
     self.assertEqual(self.large[:10], common.limited(self.large, req))
예제 #5
0
 def test_limiter_offset_medium(self):
     """Test offset key works with a medium sized number."""
     req = webob.Request.blank('/?offset=10')
     self.assertEqual([], common.limited(self.tiny, req))
     self.assertEqual(self.small[10:], common.limited(self.small, req))
     self.assertEqual(self.medium[10:], common.limited(self.medium, req))
     self.assertEqual(self.large[10:1010], common.limited(self.large, req))
예제 #6
0
 def test_limiter_nothing(self):
     """Test request with no offset or limit."""
     req = webob.Request.blank('/')
     self.assertEqual(self.tiny, common.limited(self.tiny, req))
     self.assertEqual(self.small, common.limited(self.small, req))
     self.assertEqual(self.medium, common.limited(self.medium, req))
     self.assertEqual(self.large[:1000], common.limited(self.large, req))
예제 #7
0
 def test_limiter_limit_medium(self):
     """Test limit of 10."""
     req = webob.Request.blank("/?limit=10")
     self.assertEqual(common.limited(self.tiny, req), self.tiny)
     self.assertEqual(common.limited(self.small, req), self.small)
     self.assertEqual(common.limited(self.medium, req), self.medium[:10])
     self.assertEqual(common.limited(self.large, req), self.large[:10])
예제 #8
0
 def test_limiter_limit_zero(self):
     """Test limit of zero."""
     req = webob.Request.blank('/?limit=0')
     self.assertEqual(self.tiny, common.limited(self.tiny, req))
     self.assertEqual(self.small, common.limited(self.small, req))
     self.assertEqual(self.medium, common.limited(self.medium, req))
     self.assertEqual(self.large[:1000], common.limited(self.large, req))
예제 #9
0
 def test_limiter_limit_over_max(self):
     """Test limit of 3000."""
     req = webob.Request.blank("/?limit=3000")
     self.assertEqual(common.limited(self.tiny, req), self.tiny)
     self.assertEqual(common.limited(self.small, req), self.small)
     self.assertEqual(common.limited(self.medium, req), self.medium)
     self.assertEqual(common.limited(self.large, req), self.large[:1000])
예제 #10
0
 def test_limiter_offset_zero(self):
     """Test offset key works with 0."""
     req = webob.Request.blank("/?offset=0")
     self.assertEqual(common.limited(self.tiny, req), self.tiny)
     self.assertEqual(common.limited(self.small, req), self.small)
     self.assertEqual(common.limited(self.medium, req), self.medium)
     self.assertEqual(common.limited(self.large, req), self.large[:1000])
예제 #11
0
 def test_limiter_offset_medium(self):
     """Test offset key works with a medium sized number."""
     req = webob.Request.blank("/?offset=10")
     self.assertEqual(common.limited(self.tiny, req), [])
     self.assertEqual(common.limited(self.small, req), self.small[10:])
     self.assertEqual(common.limited(self.medium, req), self.medium[10:])
     self.assertEqual(common.limited(self.large, req), self.large[10:1010])
예제 #12
0
 def test_limiter_limit_zero(self):
     """Test limit of zero."""
     req = webob.Request.blank('/?limit=0')
     self.assertEqual(common.limited(self.tiny, req), self.tiny)
     self.assertEqual(common.limited(self.small, req), self.small)
     self.assertEqual(common.limited(self.medium, req), self.medium)
     self.assertEqual(common.limited(self.large, req), self.large[:1000])
예제 #13
0
 def test_limiter_offset_zero(self):
     """Test offset key works with 0."""
     req = webob.Request.blank('/?offset=0')
     self.assertEqual(self.tiny, common.limited(self.tiny, req))
     self.assertEqual(self.small, common.limited(self.small, req))
     self.assertEqual(self.medium, common.limited(self.medium, req))
     self.assertEqual(self.large[:1000], common.limited(self.large, req))
예제 #14
0
 def test_limiter_offset_over_max(self):
     """Test offset key works with a number over 1000 (max_limit)."""
     req = webob.Request.blank('/?offset=1001')
     self.assertEqual([], common.limited(self.tiny, req))
     self.assertEqual([], common.limited(self.small, req))
     self.assertEqual([], common.limited(self.medium, req))
     self.assertEqual(self.large[1001:2001],
                      common.limited(self.large, req))
예제 #15
0
 def test_limiter_limit_and_offset(self):
     """Test request with both limit and offset."""
     items = list(range(2000))
     req = webob.Request.blank('/?offset=1&limit=3')
     self.assertEqual(items[1:4], common.limited(items, req))
     req = webob.Request.blank('/?offset=3&limit=0')
     self.assertEqual(items[3:1003], common.limited(items, req))
     req = webob.Request.blank('/?offset=3&limit=1500')
     self.assertEqual(items[3:1003], common.limited(items, req))
     req = webob.Request.blank('/?offset=3000&limit=10')
     self.assertEqual([], common.limited(items, req))
예제 #16
0
 def test_limiter_limit_and_offset(self):
     """Test request with both limit and offset."""
     items = range(2000)
     req = webob.Request.blank("/?offset=1&limit=3")
     self.assertEqual(common.limited(items, req), items[1:4])
     req = webob.Request.blank("/?offset=3&limit=0")
     self.assertEqual(common.limited(items, req), items[3:1003])
     req = webob.Request.blank("/?offset=3&limit=1500")
     self.assertEqual(common.limited(items, req), items[3:1003])
     req = webob.Request.blank("/?offset=3000&limit=10")
     self.assertEqual(common.limited(items, req), [])
예제 #17
0
 def test_limiter_custom_max_limit(self):
     """Test a max_limit other than 1000."""
     items = range(2000)
     req = webob.Request.blank("/?offset=1&limit=3")
     self.assertEqual(common.limited(items, req, max_limit=2000), items[1:4])
     req = webob.Request.blank("/?offset=3&limit=0")
     self.assertEqual(common.limited(items, req, max_limit=2000), items[3:])
     req = webob.Request.blank("/?offset=3&limit=2500")
     self.assertEqual(common.limited(items, req, max_limit=2000), items[3:])
     req = webob.Request.blank("/?offset=3000&limit=10")
     self.assertEqual(common.limited(items, req, max_limit=2000), [])
예제 #18
0
 def test_limiter_limit_and_offset(self):
     """Test request with both limit and offset."""
     items = list(range(2000))
     req = webob.Request.blank('/?offset=1&limit=3')
     self.assertEqual(items[1:4], common.limited(items, req))
     req = webob.Request.blank('/?offset=3&limit=0')
     self.assertEqual(items[3:1003], common.limited(items, req))
     req = webob.Request.blank('/?offset=3&limit=1500')
     self.assertEqual(items[3:1003], common.limited(items, req))
     req = webob.Request.blank('/?offset=3000&limit=10')
     self.assertEqual([], common.limited(items, req))
예제 #19
0
 def test_limiter_custom_max_limit(self):
     """Test a max_limit other than 1000."""
     items = list(range(2000))
     req = webob.Request.blank('/?offset=1&limit=3')
     self.assertEqual(items[1:4], common.limited(items, req,
                                                 max_limit=2000))
     req = webob.Request.blank('/?offset=3&limit=0')
     self.assertEqual(items[3:], common.limited(items, req, max_limit=2000))
     req = webob.Request.blank('/?offset=3&limit=2500')
     self.assertEqual(items[3:], common.limited(items, req, max_limit=2000))
     req = webob.Request.blank('/?offset=3000&limit=10')
     self.assertEqual([], common.limited(items, req, max_limit=2000))
예제 #20
0
 def test_limiter_custom_max_limit(self):
     """Test a max_limit other than 1000."""
     items = list(range(2000))
     req = webob.Request.blank('/?offset=1&limit=3')
     self.assertEqual(
         items[1:4], common.limited(items, req, max_limit=2000))
     req = webob.Request.blank('/?offset=3&limit=0')
     self.assertEqual(
         items[3:], common.limited(items, req, max_limit=2000))
     req = webob.Request.blank('/?offset=3&limit=2500')
     self.assertEqual(
         items[3:], common.limited(items, req, max_limit=2000))
     req = webob.Request.blank('/?offset=3000&limit=10')
     self.assertEqual([], common.limited(items, req, max_limit=2000))
예제 #21
0
    def _get_share_group_snaps(self, req, is_detail):
        """Returns a list of share group snapshots."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to group attrs
        search_opts.pop('limit', None)
        search_opts.pop('offset', None)
        sort_key = search_opts.pop('sort_key', 'created_at')
        sort_dir = search_opts.pop('sort_dir', 'desc')

        snaps = self.share_group_api.get_all_share_group_snapshots(
            context,
            detailed=is_detail,
            search_opts=search_opts,
            sort_dir=sort_dir,
            sort_key=sort_key)

        limited_list = common.limited(snaps, req)

        if is_detail:
            snaps = self._view_builder.detail_list(req, limited_list)
        else:
            snaps = self._view_builder.summary_list(req, limited_list)
        return snaps
예제 #22
0
    def _get_shares(self, req, is_detail):
        """Returns a list of shares, transformed through view
           builder.
        """
        context = req.environ['manila.context']

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

        # NOTE(rushiagr): v2 API allows name instead of display_name
        if 'name' in search_opts:
            search_opts['display_name'] = search_opts['name']
            del search_opts['name']

        common.remove_invalid_options(context, search_opts,
                                      self._get_share_search_options())

        shares = self.share_api.get_all(context, search_opts=search_opts)

        limited_list = common.limited(shares, req)

        if is_detail:
            shares = self._view_builder.detail_list(req, limited_list)
        else:
            shares = self._view_builder.summary_list(req, limited_list)
        return shares
예제 #23
0
    def _get_snapshots(self, req, is_detail):
        """Returns a list of snapshots."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to share attrs
        search_opts.pop('limit', None)
        search_opts.pop('offset', None)
        sort_key = search_opts.pop('sort_key', 'created_at')
        sort_dir = search_opts.pop('sort_dir', 'desc')

        # NOTE(vponomaryov): Manila stores in DB key 'display_name', but
        # allows to use both keys 'name' and 'display_name'. It is leftover
        # from Cinder v1 and v2 APIs.
        if 'name' in search_opts:
            search_opts['display_name'] = search_opts.pop('name')

        common.remove_invalid_options(context, search_opts,
                                      self._get_snapshots_search_options())

        snapshots = self.share_api.get_all_snapshots(
            context,
            search_opts=search_opts,
            sort_key=sort_key,
            sort_dir=sort_dir,
        )
        limited_list = common.limited(snapshots, req)
        if is_detail:
            snapshots = self._view_builder.detail_list(req, limited_list)
        else:
            snapshots = self._view_builder.summary_list(req, limited_list)
        return snapshots
예제 #24
0
파일: shares.py 프로젝트: rpafford/manila
    def _get_shares(self, req, is_detail):
        """Returns a list of shares, transformed through view
           builder.
        """
        context = req.environ["manila.context"]

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

        # NOTE(rushiagr): v2 API allows name instead of display_name
        if "name" in search_opts:
            search_opts["display_name"] = search_opts["name"]
            del search_opts["name"]

        common.remove_invalid_options(context, search_opts, self._get_share_search_options())

        shares = self.share_api.get_all(context, search_opts=search_opts)

        limited_list = common.limited(shares, req)

        if is_detail:
            shares = self._view_builder.detail_list(req, limited_list)
        else:
            shares = self._view_builder.summary_list(req, limited_list)
        return shares
예제 #25
0
    def _get_snapshots(self, req, is_detail):
        """Returns a list of snapshots."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to share attrs
        search_opts.pop('limit', None)
        search_opts.pop('offset', None)
        sort_key = search_opts.pop('sort_key', 'created_at')
        sort_dir = search_opts.pop('sort_dir', 'desc')

        # NOTE(vponomaryov): Manila stores in DB key 'display_name', but
        # allows to use both keys 'name' and 'display_name'. It is leftover
        # from Cinder v1 and v2 APIs.
        if 'name' in search_opts:
            search_opts['display_name'] = search_opts.pop('name')

        common.remove_invalid_options(context, search_opts,
                                      self._get_snapshots_search_options())

        snapshots = self.share_api.get_all_snapshots(
            context,
            search_opts=search_opts,
            sort_key=sort_key,
            sort_dir=sort_dir,
        )
        limited_list = common.limited(snapshots, req)
        if is_detail:
            snapshots = self._view_builder.detail_list(req, limited_list)
        else:
            snapshots = self._view_builder.summary_list(req, limited_list)
        return snapshots
    def _get_access_group_entries(self, req, is_detail):
        """Returns a list of access_group_entries."""
        context = req.environ['manila.context']

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

        sort_key = search_opts.pop('sort_key', 'created_at')
        sort_dir = search_opts.pop('sort_dir', 'desc')
        access_group_id = search_opts.pop('access_group_id', None)

        common.remove_invalid_options(context, search_opts,
                                      self._get_access_entries_search_options())
        
        access_group_entries = self.access_group_api.get_all_access_group_entries(
            context,
            access_group_id = access_group_id,
            sort_key=sort_key,
            sort_dir=sort_dir,
        )

        print("NMH 222222 api/v2/access_group_entries.py access_group_entries is",access_group_entries)

        limited_list = common.limited(access_group_entries, req)
       
        if is_detail:
            access_group_entries = self._view_builder.detail_list(req, limited_list)
        else:
            access_group_entries = self._view_builder.summary_list(req, limited_list)
        return access_group_entries
예제 #27
0
    def _get_share_groups(self, req, is_detail):
        """Returns a list of share groups, transformed through view builder."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to share group attrs
        search_opts.pop('limit', None)
        search_opts.pop('offset', None)
        sort_key = search_opts.pop('sort_key', 'created_at')
        sort_dir = search_opts.pop('sort_dir', 'desc')
        if req.api_version_request < api_version.APIVersionRequest("2.36"):
            search_opts.pop('name~', None)
            search_opts.pop('description~', None)
        if 'group_type_id' in search_opts:
            search_opts['share_group_type_id'] = search_opts.pop(
                'group_type_id')

        share_groups = self.share_group_api.get_all(
            context, detailed=is_detail, search_opts=search_opts,
            sort_dir=sort_dir, sort_key=sort_key,
        )

        limited_list = common.limited(share_groups, req)

        if is_detail:
            share_groups = self._view_builder.detail_list(req, limited_list)
        else:
            share_groups = self._view_builder.summary_list(req, limited_list)
        return share_groups
예제 #28
0
    def _members(self, req, id):
        """Returns a list of share group snapshot members."""
        context = req.environ['manila.context']

        snaps = self.share_group_api.get_all_share_group_snapshot_members(
            context, id)

        limited_list = common.limited(snaps, req)

        snaps = self._view_builder.member_list(req, limited_list)
        return snaps
예제 #29
0
    def _get_security_services(self, req, is_detail):
        """Returns a transformed list of security services.

        The list gets transformed through view builder.
        """
        context = req.environ['manila.context']

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

        # NOTE(vponomaryov): remove 'status' from search opts
        # since it was removed from security service model.
        search_opts.pop('status', None)
        if 'share_network_id' in search_opts:
            share_nw = db.share_network_get(context,
                                            search_opts['share_network_id'])
            security_services = share_nw['security_services']
            del search_opts['share_network_id']
        else:
            if 'all_tenants' in search_opts and context.is_admin:
                policy.check_policy(context, RESOURCE_NAME,
                                    'get_all_security_services')
                security_services = db.security_service_get_all(context)
            else:
                security_services = db.security_service_get_all_by_project(
                    context, context.project_id)
        search_opts.pop('all_tenants', None)
        common.remove_invalid_options(
            context,
            search_opts,
            self._get_security_services_search_options())
        if search_opts:
            results = []
            not_found = object()
            for ss in security_services:
                if all(ss.get(opt, not_found) == value for opt, value in
                       search_opts.items()):
                    results.append(ss)
            security_services = results

        limited_list = common.limited(security_services, req)

        if is_detail:
            security_services = self._view_builder.detail_list(
                req, limited_list)
            for ss in security_services['security_services']:
                share_networks = db.share_network_get_all_by_security_service(
                    context,
                    ss['id'])
                ss['share_networks'] = [sn['id'] for sn in share_networks]
        else:
            security_services = self._view_builder.summary_list(
                req, limited_list)
        return security_services
예제 #30
0
    def members(self, req, id):
        """Returns a list of share group snapshot members."""
        context = req.environ['manila.context']

        snaps = self.share_group_api.get_all_share_group_snapshot_members(
            context, id)

        limited_list = common.limited(snaps, req)

        snaps = self._view_builder.member_list(req, limited_list)
        return snaps
예제 #31
0
    def _get_security_services(self, req, is_detail):
        """Returns a transformed list of security services.

        The list gets transformed through view builder.
        """
        context = req.environ['manila.context']

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

        # NOTE(vponomaryov): remove 'status' from search opts
        # since it was removed from security service model.
        search_opts.pop('status', None)
        if 'share_network_id' in search_opts:
            share_nw = db.share_network_get(context,
                                            search_opts['share_network_id'])
            security_services = share_nw['security_services']
            del search_opts['share_network_id']
        else:
            if context.is_admin and utils.is_all_tenants(search_opts):
                policy.check_policy(context, RESOURCE_NAME,
                                    'get_all_security_services')
                security_services = db.security_service_get_all(context)
            else:
                security_services = db.security_service_get_all_by_project(
                    context, context.project_id)
        search_opts.pop('all_tenants', None)
        common.remove_invalid_options(
            context, search_opts, self._get_security_services_search_options())
        if search_opts:
            results = []
            not_found = object()
            for ss in security_services:
                if all(
                        ss.get(opt, not_found) == value
                        for opt, value in search_opts.items()):
                    results.append(ss)
            security_services = results

        limited_list = common.limited(security_services, req)

        if is_detail:
            security_services = self._view_builder.detail_list(
                req, limited_list)
            for ss in security_services['security_services']:
                share_networks = db.share_network_get_all_by_security_service(
                    context, ss['id'])
                ss['share_networks'] = [sn['id'] for sn in share_networks]
        else:
            security_services = self._view_builder.summary_list(
                req, limited_list)
        return security_services
예제 #32
0
파일: shares.py 프로젝트: stackhpc/manila
    def _get_shares(self, req, is_detail):
        """Returns a list of shares, transformed through view builder."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to share attrs
        search_opts.pop('limit', None)
        search_opts.pop('offset', None)
        sort_key = search_opts.pop('sort_key', 'created_at')
        sort_dir = search_opts.pop('sort_dir', 'desc')

        # Deserialize dicts
        if 'metadata' in search_opts:
            search_opts['metadata'] = ast.literal_eval(search_opts['metadata'])
        if 'extra_specs' in search_opts:
            search_opts['extra_specs'] = ast.literal_eval(
                search_opts['extra_specs'])

        # NOTE(vponomaryov): Manila stores in DB key 'display_name', but
        # allows to use both keys 'name' and 'display_name'. It is leftover
        # from Cinder v1 and v2 APIs.
        if 'name' in search_opts:
            search_opts['display_name'] = search_opts.pop('name')
        if 'description' in search_opts:
            search_opts['display_description'] = search_opts.pop('description')

        # like filter
        for key, db_key in (('name~', 'display_name~'),
                            ('description~', 'display_description~')):
            if key in search_opts:
                search_opts[db_key] = search_opts.pop(key)

        if sort_key == 'name':
            sort_key = 'display_name'

        common.remove_invalid_options(context, search_opts,
                                      self._get_share_search_options())

        shares = self.share_api.get_all(context,
                                        search_opts=search_opts,
                                        sort_key=sort_key,
                                        sort_dir=sort_dir)

        limited_list = common.limited(shares, req)

        if is_detail:
            shares = self._view_builder.detail_list(req, limited_list)
        else:
            shares = self._view_builder.summary_list(req, limited_list)
        return shares
예제 #33
0
    def _get_snapshots(self, req, is_detail):
        """Returns a list of snapshots."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to share attrs
        search_opts.pop('limit', None)
        search_opts.pop('offset', None)
        sort_key = search_opts.pop('sort_key', 'created_at')
        sort_dir = search_opts.pop('sort_dir', 'desc')

        # NOTE(vponomaryov): Manila stores in DB key 'display_name', but
        # allows to use both keys 'name' and 'display_name'. It is leftover
        # from Cinder v1 and v2 APIs.
        if 'name' in search_opts:
            search_opts['display_name'] = search_opts.pop('name')
        if 'description' in search_opts:
            search_opts['display_description'] = search_opts.pop(
                'description')

        # like filter
        for key, db_key in (('name~', 'display_name~'),
                            ('description~', 'display_description~')):
            if key in search_opts:
                search_opts[db_key] = search_opts.pop(key)

        common.remove_invalid_options(context, search_opts,
                                      self._get_snapshots_search_options())

        snapshots = self.share_api.get_all_snapshots(
            context,
            search_opts=search_opts,
            sort_key=sort_key,
            sort_dir=sort_dir,
        )

        # Snapshots with no instances are filtered out.
        snapshots = list(filter(lambda x: x.get('status') is not None,
                                snapshots))

        limited_list = common.limited(snapshots, req)
        if is_detail:
            snapshots = self._view_builder.detail_list(req, limited_list)
        else:
            snapshots = self._view_builder.summary_list(req, limited_list)
        return snapshots
예제 #34
0
    def _get_security_services(self, req, is_detail):
        """Returns a transformed list of security services.

        The list gets transformed through view builder.
        """
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME,
                            'get_all_security_services')

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

        if 'share_network_id' in search_opts:
            share_nw = db.share_network_get(context,
                                            search_opts['share_network_id'])
            security_services = share_nw['security_services']
        else:
            common.remove_invalid_options(
                context,
                search_opts,
                self._get_security_services_search_options())
            if 'all_tenants' in search_opts:
                security_services = db.security_service_get_all(context)
                del search_opts['all_tenants']
            else:
                security_services = db.security_service_get_all_by_project(
                    context, context.project_id)
            if search_opts:
                results = []
                not_found = object()
                for service in security_services:
                    for opt, value in six.iteritems(search_opts):
                        if service.get(opt, not_found) != value:
                            break
                    else:
                        results.append(service)
                security_services = results

        limited_list = common.limited(security_services, req)

        if is_detail:
            security_services = self._view_builder.detail_list(
                req, limited_list)
        else:
            security_services = self._view_builder.summary_list(
                req, limited_list)
        return security_services
예제 #35
0
    def _get_snapshots(self, req, is_detail):
        """Returns a list of snapshots."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to share attrs
        search_opts.pop('limit', None)
        search_opts.pop('offset', None)
        sort_key = search_opts.pop('sort_key', 'created_at')
        sort_dir = search_opts.pop('sort_dir', 'desc')

        # NOTE(vponomaryov): Manila stores in DB key 'display_name', but
        # allows to use both keys 'name' and 'display_name'. It is leftover
        # from Cinder v1 and v2 APIs.
        if 'name' in search_opts:
            search_opts['display_name'] = search_opts.pop('name')
        if 'description' in search_opts:
            search_opts['display_description'] = search_opts.pop('description')

        # like filter
        for key, db_key in (('name~', 'display_name~'),
                            ('description~', 'display_description~')):
            if key in search_opts:
                search_opts[db_key] = search_opts.pop(key)

        common.remove_invalid_options(context, search_opts,
                                      self._get_snapshots_search_options())

        snapshots = self.share_api.get_all_snapshots(
            context,
            search_opts=search_opts,
            sort_key=sort_key,
            sort_dir=sort_dir,
        )

        # Snapshots with no instances are filtered out.
        snapshots = list(
            filter(lambda x: x.get('status') is not None, snapshots))

        limited_list = common.limited(snapshots, req)
        if is_detail:
            snapshots = self._view_builder.detail_list(req, limited_list)
        else:
            snapshots = self._view_builder.summary_list(req, limited_list)
        return snapshots
예제 #36
0
    def _get_security_services(self, req, is_detail):
        """Returns a transformed list of security services.

        The list gets transformed through view builder.
        """
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME,
                            'get_all_security_services')

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

        if 'share_network_id' in search_opts:
            share_nw = db.share_network_get(context,
                                            search_opts['share_network_id'])
            security_services = share_nw['security_services']
        else:
            common.remove_invalid_options(
                context, search_opts,
                self._get_security_services_search_options())
            if 'all_tenants' in search_opts:
                security_services = db.security_service_get_all(context)
                del search_opts['all_tenants']
            else:
                security_services = db.security_service_get_all_by_project(
                    context, context.project_id)
            if search_opts:
                results = []
                not_found = object()
                for service in security_services:
                    for opt, value in six.iteritems(search_opts):
                        if service.get(opt, not_found) != value:
                            break
                    else:
                        results.append(service)
                security_services = results

        limited_list = common.limited(security_services, req)

        if is_detail:
            security_services = self._view_builder.detail_list(
                req, limited_list)
        else:
            security_services = self._view_builder.summary_list(
                req, limited_list)
        return security_services
예제 #37
0
파일: cgsnapshots.py 프로젝트: jcsp/manila
    def members(self, req, id):
        """Returns a list of cgsnapshot members."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to cg attrs
        search_opts.pop('limit', None)
        search_opts.pop('offset', None)

        snaps = self.cg_api.get_all_cgsnapshot_members(context, id)

        limited_list = common.limited(snaps, req)

        snaps = self._view_builder.member_list(req, limited_list)
        return snaps
예제 #38
0
파일: cgsnapshots.py 프로젝트: vkmc/manila
    def members(self, req, id):
        """Returns a list of cgsnapshot members."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to cg attrs
        search_opts.pop('limit', None)
        search_opts.pop('offset', None)

        snaps = self.cg_api.get_all_cgsnapshot_members(context, id)

        limited_list = common.limited(snaps, req)

        snaps = self._view_builder.member_list(req, limited_list)
        return snaps
예제 #39
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)
예제 #40
0
파일: messages.py 프로젝트: bswartz/manila
    def index(self, req):
        """Returns a list of messages, transformed through view builder."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to message attrs
        search_opts.pop('limit', None)
        search_opts.pop('marker', None)
        sort_key = search_opts.pop('sort_key', 'created_at')
        sort_dir = search_opts.pop('sort_dir', 'desc')

        messages = self.message_api.get_all(
            context, search_opts=search_opts, sort_dir=sort_dir,
            sort_key=sort_key)
        limited_list = common.limited(messages, req)

        return self._view_builder.index(req, limited_list)
예제 #41
0
파일: shares.py 프로젝트: sharkconi/manila
    def _get_shares(self, req, is_detail):
        """Returns a list of shares, transformed through view builder."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to share attrs
        search_opts.pop('limit', None)
        search_opts.pop('offset', None)
        sort_key = search_opts.pop('sort_key', 'created_at')
        sort_dir = search_opts.pop('sort_dir', 'desc')

        # Deserialize dicts
        if 'metadata' in search_opts:
            search_opts['metadata'] = ast.literal_eval(search_opts['metadata'])
        if 'extra_specs' in search_opts:
            search_opts['extra_specs'] = ast.literal_eval(
                search_opts['extra_specs'])

        # NOTE(vponomaryov): Manila stores in DB key 'display_name', but
        # allows to use both keys 'name' and 'display_name'. It is leftover
        # from Cinder v1 and v2 APIs.
        if 'name' in search_opts:
            search_opts['display_name'] = search_opts.pop('name')
        if sort_key == 'name':
            sort_key = 'display_name'

        common.remove_invalid_options(
            context, search_opts, self._get_share_search_options())

        shares = self.share_api.get_all(
            context, search_opts=search_opts, sort_key=sort_key,
            sort_dir=sort_dir)

        limited_list = common.limited(shares, req)

        if is_detail:
            shares = self._view_builder.detail_list(req, limited_list)
        else:
            shares = self._view_builder.summary_list(req, limited_list)
        return shares
예제 #42
0
파일: messages.py 프로젝트: stackhpc/manila
    def index(self, req):
        """Returns a list of messages, transformed through view builder."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to message attrs
        search_opts.pop('limit', None)
        search_opts.pop('marker', None)
        sort_key = search_opts.pop('sort_key', 'created_at')
        sort_dir = search_opts.pop('sort_dir', 'desc')

        messages = self.message_api.get_all(context,
                                            search_opts=search_opts,
                                            sort_dir=sort_dir,
                                            sort_key=sort_key)
        limited_list = common.limited(messages, req)

        return self._view_builder.index(req, limited_list)
예제 #43
0
파일: cgsnapshots.py 프로젝트: jcsp/manila
    def _get_cgs(self, req, is_detail):
        """Returns a list of cgsnapshots."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to cg attrs
        search_opts.pop('limit', None)
        search_opts.pop('offset', None)

        snaps = self.cg_api.get_all_cgsnapshots(
            context, detailed=is_detail, search_opts=search_opts)

        limited_list = common.limited(snaps, req)

        if is_detail:
            snaps = self._view_builder.detail_list(req, limited_list)
        else:
            snaps = self._view_builder.summary_list(req, limited_list)
        return snaps
예제 #44
0
파일: cgsnapshots.py 프로젝트: vkmc/manila
    def _get_cgs(self, req, is_detail):
        """Returns a list of cgsnapshots."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to cg attrs
        search_opts.pop('limit', None)
        search_opts.pop('offset', None)

        snaps = self.cg_api.get_all_cgsnapshots(
            context, detailed=is_detail, search_opts=search_opts)

        limited_list = common.limited(snaps, req)

        if is_detail:
            snaps = self._view_builder.detail_list(req, limited_list)
        else:
            snaps = self._view_builder.summary_list(req, limited_list)
        return snaps
    def _get_replicas(self, req, is_detail=False):
        """Returns list of replicas."""
        context = req.environ['manila.context']

        share_id = req.params.get('share_id')
        if share_id:
            try:
                replicas = db.share_replicas_get_all_by_share(
                    context, share_id)
            except exception.NotFound:
                msg = _("Share with share ID %s not found.") % share_id
                raise exc.HTTPNotFound(explanation=msg)
        else:
            replicas = db.share_replicas_get_all(context)

        limited_list = common.limited(replicas, req)
        if is_detail:
            replicas = self._view_builder.detail_list(req, limited_list)
        else:
            replicas = self._view_builder.summary_list(req, limited_list)

        return replicas
예제 #46
0
    def _get_replicas(self, req, is_detail=False):
        """Returns list of replicas."""
        context = req.environ['manila.context']

        share_id = req.params.get('share_id')
        if share_id:
            try:
                replicas = db.share_replicas_get_all_by_share(
                    context, share_id)
            except exception.NotFound:
                msg = _("Share with share ID %s not found.") % share_id
                raise exc.HTTPNotFound(explanation=msg)
        else:
            replicas = db.share_replicas_get_all(context)

        limited_list = common.limited(replicas, req)
        if is_detail:
            replicas = self._view_builder.detail_list(req, limited_list)
        else:
            replicas = self._view_builder.summary_list(req, limited_list)

        return replicas
예제 #47
0
    def _get_snapshots(self, req, is_detail):
        """Returns a list of snapshots."""
        context = req.environ['manila.context']

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

        # NOTE(rushiagr): v2 API allows name instead of display_name
        if 'name' in search_opts:
            search_opts['display_name'] = search_opts['name']
            del search_opts['name']

        common.remove_invalid_options(context, search_opts,
                                      self._get_snapshots_search_options())

        snapshots = self.share_api.get_all_snapshots(context,
                                                     search_opts=search_opts)
        limited_list = common.limited(snapshots, req)
        if is_detail:
            snapshots = self._view_builder.detail_list(req, limited_list)
        else:
            snapshots = self._view_builder.summary_list(req, limited_list)
        return snapshots
예제 #48
0
    def _get_share_group_snaps(self, req, is_detail):
        """Returns a list of share group snapshots."""
        context = req.environ['manila.context']

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

        # Remove keys that are not related to group attrs
        search_opts.pop('limit', None)
        search_opts.pop('offset', None)
        sort_key = search_opts.pop('sort_key', 'created_at')
        sort_dir = search_opts.pop('sort_dir', 'desc')

        snaps = self.share_group_api.get_all_share_group_snapshots(
            context, detailed=is_detail, search_opts=search_opts,
            sort_dir=sort_dir, sort_key=sort_key)

        limited_list = common.limited(snaps, req)

        if is_detail:
            snaps = self._view_builder.detail_list(req, limited_list)
        else:
            snaps = self._view_builder.summary_list(req, limited_list)
        return snaps
예제 #49
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)
예제 #50
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)
예제 #51
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)
        filters = {}

        # if not context.is_admin, will ignore project_id and all_tenants here,
        # in database will auto add context.project_id to search_opts.
        if context.is_admin:
            if 'project_id' in search_opts:
                # if specified project_id, will not use all_tenants
                filters['project_id'] = search_opts['project_id']
            elif not utils.is_all_tenants(search_opts):
                # if not specified project_id and all_tenants, will get
                # share networks in admin project.
                filters['project_id'] = context.project_id

        date_parsing_error_msg = '''%s is not in yyyy-mm-dd format.'''
        for time_comparison_filter in ['created_since', 'created_before']:
            if time_comparison_filter in search_opts:
                time_str = search_opts.get(time_comparison_filter)
                try:
                    parsed_time = timeutils.parse_strtime(time_str,
                                                          fmt="%Y-%m-%d")
                except ValueError:
                    msg = date_parsing_error_msg % time_str
                    raise exc.HTTPBadRequest(explanation=msg)

                filters[time_comparison_filter] = parsed_time

        if 'security_service_id' in search_opts:
            filters['security_service_id'] = search_opts.get(
                'security_service_id')

        networks = db_api.share_network_get_all_by_filter(context,
                                                          filters=filters)

        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)
예제 #52
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)