本文整理汇总了Python中nova.api.openstack.common.get_pagination_params函数的典型用法代码示例。如果您正苦于以下问题:Python get_pagination_params函数的具体用法?Python get_pagination_params怎么用?Python get_pagination_params使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_pagination_params函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fake_get_limit_and_marker
def fake_get_limit_and_marker(request, max_limit=1):
params = common.get_pagination_params(request)
limit = params.get('limit', max_limit)
limit = min(max_limit, limit)
marker = params.get('marker')
return limit, marker
示例2: limited_by_marker
def limited_by_marker(self, items, request,
max_limit=CONF.osapi_max_limit):
"""
Return a tuple with slice of items according to the requested marker
and limit and a set of collection links
:params items: resource item list
:params request: webob request
:params max_limit: maximum number of items to be returned
:returns: (limited item list, collection links list) as a tuple
"""
collection_links = []
params = common.get_pagination_params(request)
limit = params.get('limit', max_limit)
marker = params.get('marker')
limit = min(max_limit, limit)
if limit == 0:
return ([], [])
start_index = 0
if marker:
start_index = -1
for i, item in enumerate(items):
# NOTE(siva): getter from generateDS
if item.get_id() == marker:
start_index = i + 1
break
if start_index < 0:
msg = _('marker [%s] not found') % marker
raise webob.exc.HTTPBadRequest(explanation=msg)
range_end = start_index + limit
prev_index = start_index - limit
try:
items[range_end]
items[range_end - 1]
except Exception:
pass
else:
collection_links.append({
'rel': 'next',
'href': self._get_next_link(
request,
str(items[range_end - 1].get_id()), self._collection_name)
})
if prev_index > 0:
collection_links.append({
'rel': 'previous',
'href': self._get_previous_link(
request,
str(items[prev_index - 1].get_id()), self._collection_name)
})
elif prev_index == 0:
collection_links.append({
'rel': 'previous',
'href': self._get_previous_link(request,
None, self._collection_name)
})
return (items[start_index:range_end], collection_links)
示例3: detail
def detail(self, req):
"""Return a detailed index listing of images available to the request.
:param req: `wsgi.Request` object.
"""
context = req.environ['nova.context']
filters = self._get_filters(req)
page_params = common.get_pagination_params(req)
images = self._image_service.detail(context, filters=filters,
**page_params)
builder = self.get_builder(req).build
return dict(images=[builder(image, detail=True) for image in images])
示例4: detail
def detail(self, req):
"""Return a detailed index listing of images available to the request.
:param req: `wsgi.Request` object.
"""
context = req.environ["nova.context"]
filters = self._get_filters(req)
params = req.GET.copy()
page_params = common.get_pagination_params(req)
for key, val in page_params.iteritems():
params[key] = val
images = self._image_service.detail(context, filters=filters, **page_params)
return self._view_builder.detail(req, images)
示例5: index
def index(self, req):
"""Return an index listing of images available to the request.
:param req: `wsgi.Request` object
"""
context = req.environ['nova.context']
filters = self._get_filters(req)
page_params = common.get_pagination_params(req)
try:
images = self._image_api.get_all(context, filters=filters,
**page_params)
except exception.Invalid as e:
raise webob.exc.HTTPBadRequest(explanation=e.format_message())
return self._view_builder.index(req, images)
示例6: index
def index(self, req):
"""Return an index listing of images available to the request.
:param req: `wsgi.Request` object
"""
context = req.environ['nova.context']
filters = self._get_filters(req)
params = req.GET.copy()
page_params = common.get_pagination_params(req)
for key, val in page_params.iteritems():
params[key] = val
images = self._image_service.index(context, filters=filters,
**page_params)
return self.get_builder(req).build_list(images, **params)
示例7: _build_list
def _build_list(self, req, instances, is_detail=False):
params = req.GET.copy()
pagination_params = common.get_pagination_params(req)
# Update params with int() values from pagination params
for key, val in pagination_params.iteritems():
params[key] = val
context = req.environ['nova.context']
project_id = getattr(context, 'project_id', '')
base_url = req.application_url
flavor_builder = views_flavors.ViewBuilder(base_url, project_id)
image_builder = views_images.ViewBuilder(base_url, project_id)
addresses_builder = views_addresses.ViewBuilder()
builder = views_servers.ViewBuilder(context, addresses_builder,
flavor_builder, image_builder, base_url, project_id)
return builder.build_list(instances, is_detail=is_detail, **params)
示例8: detail
def detail(self, req):
"""Return a detailed index listing of images available to the request.
:param req: `wsgi.Request` object.
"""
context = req.environ['nova.context']
filters = self._get_filters(req)
params = req.GET.copy()
page_params = common.get_pagination_params(req)
for key, val in page_params.iteritems():
params[key] = val
try:
images = self._image_service.detail(context, filters=filters,
**page_params)
except exception.Invalid as e:
raise webob.exc.HTTPBadRequest(explanation=str(e))
return self._view_builder.detail(req, images)
示例9: _build_list
def _build_list(self, req, instances, is_detail=False):
params = req.GET.copy()
pagination_params = common.get_pagination_params(req)
# Update params with int() values from pagination params
for key, val in pagination_params.iteritems():
params[key] = val
project_id = getattr(req.environ['nova.context'], 'project_id', '')
base_url = req.application_url
flavor_builder = nova.api.openstack.views.flavors.ViewBuilderV11(
base_url, project_id)
image_builder = nova.api.openstack.views.images.ViewBuilderV11(
base_url, project_id)
addresses_builder = nova.api.openstack.views.addresses.ViewBuilderV11()
builder = nova.api.openstack.views.servers.ViewBuilderV11(
addresses_builder, flavor_builder, image_builder,
base_url, project_id)
get_nw = self._get_networks_for_instance
inst_data = [(inst, get_nw(req, inst)) for inst in instances]
return builder.build_list(inst_data, is_detail=is_detail, **params)
示例10: detail
def detail(self, req):
"""Return a detailed index listing of images available to the request.
:param req: `wsgi.Request` object.
"""
context = req.environ['nova.context']
filters = self._get_filters(req)
params = req.GET.copy()
page_params = common.get_pagination_params(req)
for key, val in six.iteritems(page_params):
params[key] = val
try:
images = self._image_api.get_all(context, filters=filters,
**page_params)
except exception.Invalid as e:
raise webob.exc.HTTPBadRequest(explanation=e.format_message())
req.cache_db_items('images', images, 'id')
return self._view_builder.detail(req, images)
示例11: test_valid_limit_and_page_size
def test_valid_limit_and_page_size(self):
# Test valid limit and page_size parameters.
req = webob.Request.blank("/?limit=20&page_size=5")
self.assertEqual(common.get_pagination_params(req), {"page_size": 5, "limit": 20})
示例12: test_valid_limit_and_marker
def test_valid_limit_and_marker(self):
# Test valid limit and marker parameters.
marker = '263abb28-1de6-412f-b00b-f0ee0c4333c2'
req = webob.Request.blank('/?limit=20&marker=%s' % marker)
self.assertEqual(common.get_pagination_params(req),
{'marker': marker, 'limit': 20})
示例13: test_valid_limit
def test_valid_limit(self):
# Test valid limit param.
req = webob.Request.blank('/?limit=10')
self.assertEqual(common.get_pagination_params(req), {'limit': 10})
示例14: test_valid_marker
def test_valid_marker(self):
# Test valid marker param.
req = webob.Request.blank(
'/?marker=263abb28-1de6-412f-b00b-f0ee0c4333c2')
self.assertEqual(common.get_pagination_params(req),
{'marker': '263abb28-1de6-412f-b00b-f0ee0c4333c2'})
示例15: test_no_params
def test_no_params(self):
# Test no params.
req = webob.Request.blank('/')
self.assertEqual(common.get_pagination_params(req), {})