def _calc_required_size(context, image, locations): required_size = None if image.size: required_size = image.size * len(locations) else: for location in locations: size_from_backend = None try: if CONF.enabled_backends: size_from_backend = store.get_size_from_uri_and_backend( location['url'], location['metadata'].get('store'), context=context) else: size_from_backend = store.get_size_from_backend( location['url'], context=context) except (store.UnknownScheme, store.NotFound): pass except store.BadStoreUri: raise exception.BadStoreUri if size_from_backend: required_size = size_from_backend * len(locations) break return required_size
def _calc_required_size(context, image, locations): required_size = None if image.size: required_size = image.size * len(locations) else: for location in locations: size_from_backend = None try: if CONF.enabled_backends: size_from_backend = store.get_size_from_uri_and_backend( location['url'], location['metadata'].get('backend'), context=context) else: size_from_backend = store.get_size_from_backend( location['url'], context=context) except (store.UnknownScheme, store.NotFound): pass except store.BadStoreUri: raise exception.BadStoreUri if size_from_backend: required_size = size_from_backend * len(locations) break return required_size
def _get_size(self, context, image_meta, location): # retrieve the image size from remote store (if not provided) try: return image_meta.get("size", 0) or store.get_size_from_backend(location, context=context) except (exception.NotFound, store.BadStoreUri) as e: LOG.debug(e) raise HTTPBadRequest(explanation=e.msg, content_type="text/plain")
def _set_image_size(context, image, locations): if not image.size: for location in locations: size_from_backend = store.get_size_from_backend(location["url"], context=context) if size_from_backend: # NOTE(flwang): This assumes all locations have the same size image.size = size_from_backend break
def _set_image_size(context, image, locations): if not image.size: for location in locations: size_from_backend = store.get_size_from_backend(location['url'], context=context) if size_from_backend: # NOTE(flwang): This assumes all locations have the same size image.size = size_from_backend break
def _set_image_size(context, image, locations): if not image.size: for location in locations: if CONF.enabled_backends: size_from_backend = store.get_size_from_uri_and_backend( location['url'], location['metadata'].get('store'), context=context) else: size_from_backend = store.get_size_from_backend( location['url'], context=context) if size_from_backend: # NOTE(flwang): This assumes all locations have the same size image.size = size_from_backend break
def _set_image_size(context, image, locations): if not image.size: for location in locations: if CONF.enabled_backends: size_from_backend = store.get_size_from_uri_and_backend( location['url'], location['metadata'].get('backend'), context=context) else: size_from_backend = store.get_size_from_backend( location['url'], context=context) if size_from_backend: # NOTE(flwang): This assumes all locations have the same size image.size = size_from_backend break
def _calc_required_size(context, image, locations): required_size = None if image.size: required_size = image.size * len(locations) else: for location in locations: size_from_backend = None try: size_from_backend = store.get_size_from_backend( location['url'], context=context) except (store.UnknownScheme, store.NotFound): pass if size_from_backend: required_size = size_from_backend * len(locations) break return required_size
def _handle_source(self, req, image_id, image_meta, image_data): copy_from = self._copy_from(req) location = image_meta.get("location") sources = filter(lambda x: x, (copy_from, location, image_data)) if len(sources) >= 2: msg = "It's invalid to provide multiple image sources." LOG.debug(msg) raise HTTPBadRequest(explanation=msg, request=req, content_type="text/plain") if image_data: image_meta = self._validate_image_for_activation(req, image_id, image_meta) image_meta = self._upload_and_activate(req, image_meta) elif copy_from: msg = _LI("Triggering asynchronous copy from external source") LOG.info(msg) self.pool.spawn_n(self._upload_and_activate, req, image_meta) else: if location: try: store.validate_location(location, context=req.context) except store.BadStoreUri as bse: raise HTTPBadRequest(explanation=bse.msg, request=req) self._validate_image_for_activation(req, image_id, image_meta) image_size_meta = image_meta.get("size") if image_size_meta: image_size_store = store.get_size_from_backend(location, context=req.context) # NOTE(zhiyan): A returned size of zero usually means # the driver encountered an error. In this case the # size provided by the client will be used as-is. if image_size_store and image_size_store != image_size_meta: msg = ( "Provided image size must match the stored " "image size. (provided size: %(ps)d, " "stored size: %(ss)d)" % {"ps": image_size_meta, "ss": image_size_store} ) LOG.debug(msg) raise HTTPConflict(explanation=msg, request=req, content_type="text/plain") location_data = {"url": location, "metadata": {}, "status": "active"} image_meta = self._activate(req, image_id, location_data) return image_meta