def download(self, context, url_parts, dst_path, *args, **kwargs): if not self.glance_is_local(): raise nova_exception.NovaException("Cannot use direct_url to" " download, cause glance is not as this az.") try: connection = self.get_connection(url_parts) resp_headers, resp_body = connection.get_object( container=self.container, obj=self.obj, resp_chunk_size=self.CHUNKSIZE) except: LOG.exception("Fail to download image by direct_url.") raise direct_io.write(dst_path, resp_body)
def download(self, context, url_parts, dst_path, *args, **kwargs): if not self.glance_is_local(): raise nova_exception.NovaException( "Cannot use direct_url to" " download, cause glance is not as this az.") try: connection = self.get_connection(url_parts) resp_headers, resp_body = connection.get_object( container=self.container, obj=self.obj, resp_chunk_size=self.CHUNKSIZE) except: LOG.exception("Fail to download image by direct_url.") raise direct_io.write(dst_path, resp_body)
def download(self, context, image_id, data=None, dst_path=None): """Calls out to Glance for data and writes data.""" if CONF.glance.allowed_direct_url_schemes and dst_path is not None: image = self.show(context, image_id, include_locations=True) for entry in image.get('locations', []): loc_url = entry['url'] loc_meta = entry['metadata'] o = urlparse.urlparse(loc_url) xfer_mod = self._get_transfer_module(o.scheme) if xfer_mod: try: xfer_mod.download(context, o, dst_path, loc_meta) msg = _("Successfully transferred " "using %s") % o.scheme LOG.info(msg) return except Exception as ex: LOG.exception(ex) try: image_chunks = self._client.call(context, 1, 'data', image_id) except Exception: glance._reraise_translated_image_exception(image_id) close_file = False if data is None and dst_path: direct_io.write(dst_path, image_chunks) return if data is None: return image_chunks else: try: for chunk in image_chunks: data.write(chunk) finally: if close_file: data.close()
def download(self, context, image_id, data=None, dst_path=None): """Calls out to Glance for data and writes data.""" if CONF.glance.allowed_direct_url_schemes and dst_path is not None: image = self.show(context, image_id, include_locations=True) for entry in image.get('locations', []): loc_url = entry['url'] loc_meta = entry['metadata'] o = urlparse.urlparse(loc_url) xfer_mod = self._get_transfer_module(o.scheme) if xfer_mod: try: xfer_mod.download(context, o, dst_path, loc_meta) msg = _("Successfully transferred " "using %s") % o.scheme LOG.info(msg) return except Exception as ex: LOG.exception(ex) try: image_chunks = self._client.call(context, 1, 'data', image_id) except Exception: glance._reraise_translated_image_exception(image_id) close_file = False if data is None and dst_path: direct_io.write(dst_path, image_chunks) return if data is None: return image_chunks else: try: for chunk in image_chunks: data.write(chunk) finally: if close_file: data.close()