"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "glance/api/v2/images.py" between
glance-20.0.0.tar.gz and glance-20.0.1.tar.gz

About: OpenStack Glance (Core Service: Image Service) stores and retrieves virtual machine disk images. OpenStack Compute makes use of this during instance provisioning.
The "Ussuri" series (latest release).

images.py  (glance-20.0.0):images.py  (glance-20.0.1)
skipping to change at line 33 skipping to change at line 33
from glance_store import location from glance_store import location
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
from oslo_utils import encodeutils from oslo_utils import encodeutils
import six import six
from six.moves import http_client as http from six.moves import http_client as http
import six.moves.urllib.parse as urlparse import six.moves.urllib.parse as urlparse
import webob.exc import webob.exc
from glance.api import authorization
from glance.api import common from glance.api import common
from glance.api import policy from glance.api import policy
from glance.common import exception from glance.common import exception
from glance.common import location_strategy from glance.common import location_strategy
from glance.common import store_utils from glance.common import store_utils
from glance.common import timeutils from glance.common import timeutils
from glance.common import utils from glance.common import utils
from glance.common import wsgi from glance.common import wsgi
import glance.db import glance.db
import glance.gateway import glance.gateway
skipping to change at line 133 skipping to change at line 134
import_method == 'glance-direct'): import_method == 'glance-direct'):
msg = _("Image needs to be staged before 'glance-direct' " msg = _("Image needs to be staged before 'glance-direct' "
"method can be used") "method can be used")
raise exception.Conflict(msg) raise exception.Conflict(msg)
if not getattr(image, 'container_format', None): if not getattr(image, 'container_format', None):
msg = _("'container_format' needs to be set before import") msg = _("'container_format' needs to be set before import")
raise exception.Conflict(msg) raise exception.Conflict(msg)
if not getattr(image, 'disk_format', None): if not getattr(image, 'disk_format', None):
msg = _("'disk_format' needs to be set before import") msg = _("'disk_format' needs to be set before import")
raise exception.Conflict(msg) raise exception.Conflict(msg)
if not authorization.is_image_mutable(req.context, image):
raise webob.exc.HTTPForbidden(
explanation=_("Operation not permitted"))
stores = [None] stores = [None]
if CONF.enabled_backends: if CONF.enabled_backends:
try: try:
stores = utils.get_stores_from_request(req, body) stores = utils.get_stores_from_request(req, body)
except glance_store.UnknownScheme as exc: except glance_store.UnknownScheme as exc:
LOG.warn(exc.msg) LOG.warn(exc.msg)
raise exception.Conflict(exc.msg) raise exception.Conflict(exc.msg)
# NOTE(abhishekk): If all_stores is specified and import_method is # NOTE(abhishekk): If all_stores is specified and import_method is
skipping to change at line 620 skipping to change at line 624
"invisible.") "invisible.")
raise webob.exc.HTTPForbidden(explanation=msg) raise webob.exc.HTTPForbidden(explanation=msg)
if image.status not in ('active', 'queued'): if image.status not in ('active', 'queued'):
msg = _("It's not allowed to replace locations if image status is " msg = _("It's not allowed to replace locations if image status is "
"%s.") % image.status "%s.") % image.status
raise webob.exc.HTTPConflict(explanation=msg) raise webob.exc.HTTPConflict(explanation=msg)
val_data = self._validate_validation_data(image, value) val_data = self._validate_validation_data(image, value)
# NOTE(abhishekk): get glance store based on location uri # NOTE(abhishekk): get glance store based on location uri
updated_location = value
if CONF.enabled_backends: if CONF.enabled_backends:
store_utils.update_store_in_locations(value, image.image_id) updated_location = store_utils.get_updated_store_location(
value)
try: try:
# NOTE(flwang): _locations_proxy's setattr method will check if # NOTE(flwang): _locations_proxy's setattr method will check if
# the update is acceptable. # the update is acceptable.
image.locations = value image.locations = updated_location
if image.status == 'queued': if image.status == 'queued':
for k, v in val_data.items(): for k, v in val_data.items():
setattr(image, k, v) setattr(image, k, v)
image.status = 'active' image.status = 'active'
except (exception.BadStoreUri, exception.DuplicateLocation) as e: except (exception.BadStoreUri, exception.DuplicateLocation) as e:
raise webob.exc.HTTPBadRequest(explanation=e.msg) raise webob.exc.HTTPBadRequest(explanation=e.msg)
except ValueError as ve: # update image status failed. except ValueError as ve: # update image status failed.
raise webob.exc.HTTPBadRequest( raise webob.exc.HTTPBadRequest(
explanation=encodeutils.exception_to_unicode(ve)) explanation=encodeutils.exception_to_unicode(ve))
skipping to change at line 650 skipping to change at line 656
"invisible.") "invisible.")
raise webob.exc.HTTPForbidden(explanation=msg) raise webob.exc.HTTPForbidden(explanation=msg)
if image.status not in ('active', 'queued'): if image.status not in ('active', 'queued'):
msg = _("It's not allowed to add locations if image status is " msg = _("It's not allowed to add locations if image status is "
"%s.") % image.status "%s.") % image.status
raise webob.exc.HTTPConflict(explanation=msg) raise webob.exc.HTTPConflict(explanation=msg)
val_data = self._validate_validation_data(image, [value]) val_data = self._validate_validation_data(image, [value])
# NOTE(abhishekk): get glance store based on location uri # NOTE(abhishekk): get glance store based on location uri
updated_location = value
if CONF.enabled_backends: if CONF.enabled_backends:
store_utils.update_store_in_locations([value], image.image_id) updated_location = store_utils.get_updated_store_location(
[value])[0]
pos = self._get_locations_op_pos(path_pos, pos = self._get_locations_op_pos(path_pos,
len(image.locations), True) len(image.locations), True)
if pos is None: if pos is None:
msg = _("Invalid position for adding a location.") msg = _("Invalid position for adding a location.")
raise webob.exc.HTTPBadRequest(explanation=msg) raise webob.exc.HTTPBadRequest(explanation=msg)
try: try:
image.locations.insert(pos, value) image.locations.insert(pos, updated_location)
if image.status == 'queued': if image.status == 'queued':
for k, v in val_data.items(): for k, v in val_data.items():
setattr(image, k, v) setattr(image, k, v)
image.status = 'active' image.status = 'active'
except (exception.BadStoreUri, exception.DuplicateLocation) as e: except (exception.BadStoreUri, exception.DuplicateLocation) as e:
raise webob.exc.HTTPBadRequest(explanation=e.msg) raise webob.exc.HTTPBadRequest(explanation=e.msg)
except ValueError as e: # update image status failed. except ValueError as e: # update image status failed.
raise webob.exc.HTTPBadRequest( raise webob.exc.HTTPBadRequest(
explanation=encodeutils.exception_to_unicode(e)) explanation=encodeutils.exception_to_unicode(e))
skipping to change at line 703 skipping to change at line 711
# from the backend store. # from the backend store.
image.locations.pop(pos) image.locations.pop(pos)
# TODO(jokke): Fix this, we should catch what store throws and # TODO(jokke): Fix this, we should catch what store throws and
# provide definitely something else than IternalServerError to user. # provide definitely something else than IternalServerError to user.
except Exception as e: except Exception as e:
raise webob.exc.HTTPInternalServerError( raise webob.exc.HTTPInternalServerError(
explanation=encodeutils.exception_to_unicode(e)) explanation=encodeutils.exception_to_unicode(e))
class RequestDeserializer(wsgi.JSONRequestDeserializer): class RequestDeserializer(wsgi.JSONRequestDeserializer):
_disallowed_properties = ('direct_url', 'self', 'file', 'schema') _disallowed_properties = ('direct_url', 'self', 'file', 'schema', 'stores')
_readonly_properties = ('created_at', 'updated_at', 'status', 'checksum', _readonly_properties = ('created_at', 'updated_at', 'status', 'checksum',
'size', 'virtual_size', 'direct_url', 'self', 'size', 'virtual_size', 'direct_url', 'self',
'file', 'schema', 'id', 'os_hash_algo', 'file', 'schema', 'id', 'os_hash_algo',
'os_hash_value') 'os_hash_value')
_reserved_properties = ('location', 'deleted', 'deleted_at') _reserved_properties = ('location', 'deleted', 'deleted_at')
_base_properties = ('checksum', 'created_at', 'container_format', _base_properties = ('checksum', 'created_at', 'container_format',
'disk_format', 'id', 'min_disk', 'min_ram', 'name', 'disk_format', 'id', 'min_disk', 'min_ram', 'name',
'size', 'virtual_size', 'status', 'tags', 'owner', 'size', 'virtual_size', 'status', 'tags', 'owner',
'updated_at', 'visibility', 'protected', 'os_hidden') 'updated_at', 'visibility', 'protected', 'os_hidden')
_available_sort_keys = ('name', 'status', 'container_format', _available_sort_keys = ('name', 'status', 'container_format',
 End of changes. 9 change blocks. 
5 lines changed or deleted 13 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)