2014-02-18 10:14:00 +08:00
|
|
|
# Copyright 2012 United States Government as represented by the
|
|
|
|
# Administrator of the National Aeronautics and Space Administration.
|
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Copyright 2012 Nebula, Inc.
|
|
|
|
# Copyright 2012 OpenStack Foundation
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Views for managing Images and Snapshots.
|
|
|
|
"""
|
|
|
|
|
2022-04-18 23:30:04 +05:30
|
|
|
import logging
|
|
|
|
|
2022-01-26 22:42:15 +09:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2014-02-18 10:14:00 +08:00
|
|
|
|
|
|
|
from horizon import exceptions
|
2016-04-12 14:16:11 +08:00
|
|
|
from horizon import messages
|
2014-02-18 10:14:00 +08:00
|
|
|
from horizon import tables
|
|
|
|
|
|
|
|
from openstack_dashboard import api
|
2016-04-12 14:16:11 +08:00
|
|
|
from openstack_dashboard import policy
|
2014-02-18 10:14:00 +08:00
|
|
|
|
|
|
|
from openstack_dashboard.dashboards.project.images.images \
|
|
|
|
import tables as images_tables
|
|
|
|
|
|
|
|
|
2022-04-18 23:30:04 +05:30
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2014-02-18 10:14:00 +08:00
|
|
|
class IndexView(tables.DataTableView):
|
|
|
|
table_class = images_tables.ImagesTable
|
2015-02-10 14:13:14 +00:00
|
|
|
page_title = _("Images")
|
2014-02-18 10:14:00 +08:00
|
|
|
|
2022-04-18 23:30:04 +05:30
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
LOG.warning('The Django version of the Images panel is deprecated '
|
|
|
|
'since Zed release. Switch to the AngularJS version by '
|
|
|
|
'setting "ANGULAR_FEATURES[\'images_panel\'] = True".')
|
|
|
|
|
2014-04-28 16:42:43 -07:00
|
|
|
def has_prev_data(self, table):
|
2014-06-12 13:42:53 +08:00
|
|
|
return getattr(self, "_prev", False)
|
2014-04-28 16:42:43 -07:00
|
|
|
|
2014-02-18 10:14:00 +08:00
|
|
|
def has_more_data(self, table):
|
2014-06-12 13:42:53 +08:00
|
|
|
return getattr(self, "_more", False)
|
2014-02-18 10:14:00 +08:00
|
|
|
|
|
|
|
def get_data(self):
|
2016-04-12 14:16:11 +08:00
|
|
|
if not policy.check((("image", "get_images"),), self.request):
|
|
|
|
msg = _("Insufficient privilege level to retrieve image list.")
|
|
|
|
messages.info(self.request, msg)
|
|
|
|
return []
|
2014-10-24 20:14:46 +04:00
|
|
|
prev_marker = self.request.GET.get(
|
|
|
|
images_tables.ImagesTable._meta.prev_pagination_param, None)
|
|
|
|
|
|
|
|
if prev_marker is not None:
|
|
|
|
marker = prev_marker
|
|
|
|
else:
|
|
|
|
marker = self.request.GET.get(
|
|
|
|
images_tables.ImagesTable._meta.pagination_param, None)
|
|
|
|
reversed_order = prev_marker is not None
|
2014-02-18 10:14:00 +08:00
|
|
|
try:
|
2014-10-24 20:14:46 +04:00
|
|
|
images, self._more, self._prev = api.glance.image_list_detailed(
|
2014-06-12 13:42:53 +08:00
|
|
|
self.request,
|
|
|
|
marker=marker,
|
2014-10-24 20:14:46 +04:00
|
|
|
paginate=True,
|
|
|
|
sort_dir='asc',
|
|
|
|
sort_key='name',
|
|
|
|
reversed_order=reversed_order)
|
2014-02-18 10:14:00 +08:00
|
|
|
except Exception:
|
|
|
|
images = []
|
2014-10-24 20:14:46 +04:00
|
|
|
self._prev = self._more = False
|
2014-02-18 10:14:00 +08:00
|
|
|
exceptions.handle(self.request, _("Unable to retrieve images."))
|
|
|
|
return images
|