openstack_dashboard/api/glance.py
def image_list_detailed(request, marker=None, sort_dir='desc',
                        sort_key='created_at', filters=None, paginate=False,
                        reversed_order=False, **kwargs):
    """Thin layer above glanceclient, for handling pagination issues.

    It provides iterating both forward and backward on top of ascetic
    OpenStack pagination API - which natively supports only iterating forward
    through the entries. Thus in order to retrieve list of objects at previous
    page, a request with the reverse entries order had to be made to Glance,
    using the first object id on current page as the marker - restoring
    the original items ordering before sending them back to the UI.

    :param request:

        The request object coming from browser to be passed further into
        Glance service.

    :param marker:

        The id of an object which defines a starting point of a query sent to
        Glance service.

    :param sort_dir:

        The direction by which the resulting image list throughout all pages
        (if pagination is enabled) will be sorted. Could be either 'asc'
        (ascending) or 'desc' (descending), defaults to 'desc'.

    :param sort_key:

        The name of key by by which the resulting image list throughout all
        pages (if pagination is enabled) will be sorted. Defaults to
        'created_at'.

    :param filters:

        A dictionary of filters passed as is to Glance service.

    :param paginate:

        Whether the pagination is enabled. If it is, then the number of
        entries on a single page of images table is limited to the specific
        number stored in browser cookies.

    :param reversed_order:

        Set this flag to True when it's necessary to get a reversed list of
        images from Glance (used for navigating the images list back in UI).
    """
    limit = settings.API_RESULT_LIMIT
    page_size = utils.get_page_size(request)

    if paginate:
        request_size = page_size + 1
    else:
        request_size = limit

    _normalize_list_input(filters, **kwargs)
    kwargs = {'filters': filters or {}}

    if marker:
        kwargs['marker'] = marker
    kwargs['sort_key'] = sort_key

    if not reversed_order:
        kwargs['sort_dir'] = sort_dir
    else:
        kwargs['sort_dir'] = 'desc' if sort_dir == 'asc' else 'asc'

    images_iter = glanceclient(request).images.list(page_size=request_size,
                                                    limit=limit,
                                                    **kwargs)
    has_prev_data = False
    has_more_data = False
    if paginate:
        images = list(itertools.islice(images_iter, request_size))
        # first and middle page condition
        if len(images) > page_size:
            images.pop(-1)
            has_more_data = True
            # middle page condition
            if marker is not None:
                has_prev_data = True
        # first page condition when reached via prev back
        elif reversed_order and marker is not None:
            has_more_data = True
        # last page condition
        elif marker is not None:
            has_prev_data = True

        # restore the original ordering here
        if reversed_order:
            images = sorted(images, key=lambda image:
                            (getattr(image, sort_key) or '').lower(),
                            reverse=(sort_dir == 'desc'))
    else:
        images = list(images_iter)

    # TODO(jpichon): Do it better
    wrapped_images = []
    for image in images:
        wrapped_images.append(Image(image))

    return wrapped_images, has_more_data, has_prev_data
Thin layer above glanceclient, for handling pagination issues.

    It provides iterating both forward and backward on top of ascetic
    OpenStack pagination API - which natively supports only iterating forward
    through the entries. Thus in order to retrieve list of objects at previous
    page, a request with the reverse entries order had to be made to Glance,
    using the first object id on current page as the marker - restoring
    the original items ordering before sending them back to the UI.

    :param request:

        The request object coming from browser to be passed further into
        Glance service.

    :param marker:

        The id of an object which defines a starting point of a query sent to
        Glance service.

    :param sort_dir:

        The direction by which the resulting image list throughout all pages
        (if pagination is enabled) will be sorted. Could be either 'asc'
        (ascending) or 'desc' (descending), defaults to 'desc'.

    :param sort_key:

        The name of key by by which the resulting image list throughout all
        pages (if pagination is enabled) will be sorted. Defaults to
        'created_at'.

    :param filters:

        A dictionary of filters passed as is to Glance service.

    :param paginate:

        Whether the pagination is enabled. If it is, then the number of
        entries on a single page of images table is limited to the specific
        number stored in browser cookies.

    :param reversed_order:

        Set this flag to True when it's necessary to get a reversed list of
        images from Glance (used for navigating the images list back in UI).
    
Thin layer above glanceclient, for handling pagination issues.
It provides iterating both forward and backward on top of ascetic
OpenStack pagination API - which natively supports only iterating forward
through the entries. Thus in order to retrieve list of objects at previous
page, a request with the reverse entries order had to be made to Glance,
using the first object id on current page as the marker - restoring
the original items ordering before sending them back to the UI.
Thin layer above glanceclient for handling pagination issues . It provides iterating both forward and backward on top of ascetic OpenStack pagination API - which natively supports only iterating forward through the entries . Thus in order to retrieve list of objects at previous page a request with the reverse entries order had to be made to Glance using the first object id on current page as the marker - restoring the original items ordering before sending them back to the UI .
def image_list_detailed(request, marker=None, sort_dir='desc',
                        sort_key='created_at', filters=None, paginate=False,
                        reversed_order=False, **kwargs):
    limit = settings.API_RESULT_LIMIT
    page_size = utils.get_page_size(request)
    if paginate:
        request_size = page_size + 1
    else:
        request_size = limit
    _normalize_list_input(filters, **kwargs)
    kwargs = {'filters': filters or {}}
    if marker:
        kwargs['marker'] = marker
    kwargs['sort_key'] = sort_key
    if not reversed_order:
        kwargs['sort_dir'] = sort_dir
    else:
        kwargs['sort_dir'] = 'desc' if sort_dir == 'asc' else 'asc'
    images_iter = glanceclient(request).images.list(page_size=request_size,
                                                    limit=limit,
                                                    **kwargs)
    has_prev_data = False
    has_more_data = False
    if paginate:
        images = list(itertools.islice(images_iter, request_size))
        if len(images) > page_size:
            images.pop(-1)
            has_more_data = True
            if marker is not None:
                has_prev_data = True
        elif reversed_order and marker is not None:
            has_more_data = True
        elif marker is not None:
            has_prev_data = True
        if reversed_order:
            images = sorted(images, key=lambda image:
                            (getattr(image, sort_key) or '').lower(),
                            reverse=(sort_dir == 'desc'))
    else:
        images = list(images_iter)
    wrapped_images = []
    for image in images:
        wrapped_images.append(Image(image))
    return wrapped_images, has_more_data, has_prev_data
def image_list_detailed ( request , marker = None , sort_dir = 'desc' , sort_key = 'created_at' , filters = None , paginate = False , reversed_order = False , ** kwargs ) : limit = settings . API_RESULT_LIMIT page_size = utils . get_page_size ( request ) if paginate : request_size = page_size + 1 else : request_size = limit _normalize_list_input ( filters , ** kwargs ) kwargs = { 'filters' : filters or { } } if marker : kwargs [ 'marker' ] = marker kwargs [ 'sort_key' ] = sort_key if not reversed_order : kwargs [ 'sort_dir' ] = sort_dir else : kwargs [ 'sort_dir' ] = 'desc' if sort_dir == 'asc' else 'asc' images_iter = glanceclient ( request ) . images . list ( page_size = request_size , limit = limit , ** kwargs ) has_prev_data = False has_more_data = False if paginate : images = list ( itertools . islice ( images_iter , request_size ) ) if len ( images ) > page_size : images . pop ( - 1 ) has_more_data = True if marker is not None : has_prev_data = True elif reversed_order and marker is not None : has_more_data = True elif marker is not None : has_prev_data = True if reversed_order : images = sorted ( images , key = lambda image : ( getattr ( image , sort_key ) or '' ) . lower ( ) , reverse = ( sort_dir == 'desc' ) ) else : images = list ( images_iter ) wrapped_images = [ ] for image in images : wrapped_images . append ( Image ( image ) ) return wrapped_images , has_more_data , has_prev_data
Thin layer above glanceclient, for handling pagination issues.
Thin layer above glanceclient for handling pagination issues .
"""Thin layer above glanceclient, for handling pagination issues.

    It provides iterating both forward and backward on top of ascetic
    OpenStack pagination API - which natively supports only iterating forward
    through the entries. Thus in order to retrieve list of objects at previous
    page, a request with the reverse entries order had to be made to Glance,
    using the first object id on current page as the marker - restoring
    the original items ordering before sending them back to the UI.

    :param request:

        The request object coming from browser to be passed further into
        Glance service.

    :param marker:

        The id of an object which defines a starting point of a query sent to
        Glance service.

    :param sort_dir:

        The direction by which the resulting image list throughout all pages
        (if pagination is enabled) will be sorted. Could be either 'asc'
        (ascending) or 'desc' (descending), defaults to 'desc'.

    :param sort_key:

        The name of key by by which the resulting image list throughout all
        pages (if pagination is enabled) will be sorted. Defaults to
        'created_at'.

    :param filters:

        A dictionary of filters passed as is to Glance service.

    :param paginate:

        Whether the pagination is enabled. If it is, then the number of
        entries on a single page of images table is limited to the specific
        number stored in browser cookies.

    :param reversed_order:

        Set this flag to True when it's necessary to get a reversed list of
        images from Glance (used for navigating the images list back in UI).
    """ # first and middle page condition # middle page condition # first page condition when reached via prev back # last page condition # restore the original ordering here # TODO(jpichon): Do it better
request
The request object coming from browser to be passed further into
Glance service.
The request object coming from browser to be passed further into Glance service .
marker
The id of an object which defines a starting point of a query sent to
Glance service.
The id of an object which defines a starting point of a query sent to Glance service .
sort_dir
The direction by which the resulting image list throughout all pages
(if pagination is enabled) will be sorted. Could be either 'asc'
(ascending) or 'desc' (descending), defaults to 'desc'.
The direction by which the resulting image list throughout all pages ( if pagination is enabled ) will be sorted . Could be either ' asc ' ( ascending ) or ' desc ' ( descending ) defaults to ' desc ' .
'desc'
sort_key
The name of key by by which the resulting image list throughout all
pages (if pagination is enabled) will be sorted. Defaults to
'created_at'.
The name of key by by which the resulting image list throughout all pages ( if pagination is enabled ) will be sorted . Defaults to ' created_at ' .
filters
A dictionary of filters passed as is to Glance service.
A dictionary of filters passed as is to Glance service .
paginate
Whether the pagination is enabled. If it is, then the number of
entries on a single page of images table is limited to the specific
number stored in browser cookies.
Whether the pagination is enabled . If it is then the number of entries on a single page of images table is limited to the specific number stored in browser cookies .
reversed_order
Set this flag to True when it's necessary to get a reversed list of
images from Glance (used for navigating the images list back in UI).
Set this flag to True when it ' s necessary to get a reversed list of images from Glance ( used for navigating the images list back in UI ) .