Source code for glance.db.utils
# 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
# 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.
from glance.common import exception
from glance.i18n import _
Replaces a v2-style image dictionary's 'visibility' member with the
equivalent v1-style 'is_public' member.
visibility = image.pop('visibility')
is_image_public = 'public' == visibility
image['is_public'] = is_image_public
Accepts an image dictionary that contains a v1-style 'is_public' member
and returns the equivalent v2-style image dictionary.
if ('is_public' in image):
if ('visibility' in image):
msg = _("Specifying both 'visibility' and 'is_public' is not "
image['visibility'] = ('public' if image.pop('is_public') else
def is_image_visible(context, image, image_member_find, status=None):
"""Return True if the image is visible in this context."""
# Is admin == image visible
# No owner == image visible
if image['owner'] is None:
# Public or Community visibility == image visible
if image['visibility'] in ['public', 'community']:
# Perform tests based on whether we have an owner
if context.owner is not None:
if context.owner == image['owner']:
# Figure out if this image is shared with that tenant
if 'shared' == image['visibility']:
members = image_member_find(context,
# Private image