Exemplo n.º 1
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])
Exemplo n.º 2
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])
Exemplo n.º 3
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])
Exemplo n.º 4
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])
Exemplo n.º 5
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])
Exemplo n.º 6
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])
Exemplo n.º 7
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])
Exemplo n.º 8
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])
Exemplo n.º 9
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])
Exemplo n.º 10
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])
Exemplo n.º 11
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])
Exemplo n.º 12
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])
Exemplo n.º 13
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), [])
Exemplo n.º 14
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), [])
Exemplo n.º 15
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), [])
Exemplo n.º 16
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), [])
Exemplo n.º 17
0
 def _get_cells(self, ctxt, req, detail=False):
     """Return all cells."""
     # Ask the CellsManager for the most recent data
     items = self.cells_rpcapi.get_cell_info_for_neighbors(ctxt)
     items = common.limited(items, req)
     items = [_scrub_cell(item, detail=detail) for item in items]
     return dict(cells=items)
Exemplo n.º 18
0
 def _get_cells(self, ctxt, req, detail=False):
     """Return all cells."""
     # Ask the CellsManager for the most recent data
     items = self.cells_rpcapi.get_cell_info_for_neighbors(ctxt)
     items = common.limited(items, req)
     items = [_scrub_cell(item, detail=detail) for item in items]
     return dict(cells=items)
Exemplo n.º 19
0
    def _items(self, req, server_id, entity_maker):
        """Returns a list of VIFs, transformed through entity_maker."""
        context = req.environ['patron.context']
        instance = common.get_instance(self.compute_api, context, server_id)

        vifs = self.network_api.get_vifs_by_instance(context, instance)
        limited_list = common.limited(vifs, req)
        res = [entity_maker(context, vif) for vif in limited_list]
        return {'virtual_interfaces': res}
Exemplo n.º 20
0
    def _items(self, req, entity_maker):
        """Returns a list of volumes, transformed through entity_maker."""
        context = req.environ['patron.context']
        authorize(context)

        volumes = self.volume_api.get_all(context)
        limited_list = common.limited(volumes, req)
        res = [entity_maker(context, vol) for vol in limited_list]
        return {'volumes': res}
Exemplo n.º 21
0
    def _items(self, req, entity_maker):
        """Returns a list of snapshots, transformed through entity_maker."""
        context = req.environ['patron.context']
        authorize(context)

        snapshots = self.volume_api.get_all_snapshots(context)
        limited_list = common.limited(snapshots, req)
        res = [entity_maker(context, snapshot) for snapshot in limited_list]
        return {'snapshots': res}
Exemplo n.º 22
0
    def _items(self, req, server_id, entity_maker):
        """Returns a list of VIFs, transformed through entity_maker."""
        context = req.environ['patron.context']
        instance = common.get_instance(self.compute_api, context, server_id)

        vifs = self.network_api.get_vifs_by_instance(context, instance)
        limited_list = common.limited(vifs, req)
        res = [entity_maker(context, vif) for vif in limited_list]
        return {'virtual_interfaces': res}
Exemplo n.º 23
0
 def index(self, req):
     """Returns a list of server groups."""
     context = _authorize_context(req)
     project_id = context.project_id
     if 'all_projects' in req.GET and context.is_admin:
         sgs = objects.InstanceGroupList.get_all(context)
     else:
         sgs = objects.InstanceGroupList.get_by_project_id(
                 context, project_id)
     limited_list = common.limited(sgs.objects, req)
     result = [self._format_server_group(context, group)
               for group in limited_list]
     return {'server_groups': result}
Exemplo n.º 24
0
 def index(self, req):
     """Returns a list of server groups."""
     context = _authorize_context(req)
     project_id = context.project_id
     if 'all_projects' in req.GET and context.is_admin:
         sgs = objects.InstanceGroupList.get_all(context)
     else:
         sgs = objects.InstanceGroupList.get_by_project_id(
             context, project_id)
     limited_list = common.limited(sgs.objects, req)
     result = [
         self._format_server_group(context, group) for group in limited_list
     ]
     return {'server_groups': result}
Exemplo n.º 25
0
    def _items(self, req, server_id, entity_maker):
        """Returns a list of attachments, transformed through entity_maker."""
        context = req.environ['patron.context']
        authorize(context)

        instance = common.get_instance(self.compute_api, context, server_id)

        bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
                context, instance.uuid)
        limited_list = common.limited(bdms, req)
        results = []

        for bdm in limited_list:
            if bdm.volume_id:
                results.append(entity_maker(bdm.volume_id,
                                            bdm.instance_uuid,
                                            bdm.device_name))

        return {'volumeAttachments': results}
Exemplo n.º 26
0
    def index(self, req):
        """Returns a list of security groups."""
        context = _authorize_context(req)

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

        project_id = context.project_id
        raw_groups = self.security_group_api.list(context,
                                                  project=project_id,
                                                  search_opts=search_opts)

        limited_list = common.limited(raw_groups, req)
        result = [self._format_security_group(context, group)
                    for group in limited_list]

        return {'security_groups':
                list(sorted(result,
                            key=lambda k: (k['tenant_id'], k['name'])))}
Exemplo n.º 27
0
    def index(self, req):
        """Returns a list of security groups."""
        context = _authorize_context(req)

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

        project_id = context.project_id
        raw_groups = self.security_group_api.list(context,
                                                  project=project_id,
                                                  search_opts=search_opts)

        limited_list = common.limited(raw_groups, req)
        result = [
            self._format_security_group(context, group)
            for group in limited_list
        ]

        return {
            'security_groups':
            list(sorted(result, key=lambda k: (k['tenant_id'], k['name'])))
        }