def download(self, context, image_id, data=None): """Calls out to Glance for data and writes data.""" if CONF.allowed_direct_url_schemes: direct_url, locations = self.get_location(context, image_id) if locations is None: locations = [] if direct_url: locations.append({'url': direct_url, 'metadata': {}}) for entry in locations: loc_url = entry['url'] loc_meta = entry['metadata'] o = urlparse.urlparse(loc_url) if o.scheme in CONF.allowed_direct_url_schemes: if o.scheme == "file": with open(o.path, "r") as f: # a system call to cp could have significant performance # advantages, however we do not have the path to files at # this point in the abstraction. shutil.copyfileobj(f, data) return elif o.scheme in ["uds", "uds+https"]: try: xfer_mod = uds_download.get_download_handler() if data: path = data.name image_chunks = xfer_mod.download( context, o, path, loc_meta) msg = _("Successfully transferred " "using %s") % o.scheme LOG.info(msg) return except Exception as ex: LOG.exception(ex) elif o.scheme in ["swift", "swift+https"]: try: xfer_mod = swift_download.get_download_handler() if data: path = data.name xfer_mod.download(context, o, 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, 'data', image_id) except Exception: _reraise_translated_image_exception(image_id) if not data: return image_chunks else: path = data.name direct_io.write(path, image_chunks)
def download(self, context, url_parts, dst_path, *args, **kwargs): if not self.glance_is_local(): raise cinder_exception.CinderException("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 cinder_exception.CinderException( "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): """Calls out to Glance for data and writes data.""" if CONF.allowed_direct_url_schemes: direct_url, locations = self.get_location(context, image_id) if locations is None: locations = [] if direct_url: locations.append({'url': direct_url, 'metadata': {}}) for entry in locations: loc_url = entry['url'] loc_meta = entry['metadata'] o = urlparse.urlparse(loc_url) if o.scheme in CONF.allowed_direct_url_schemes: if o.scheme == "file": with open(o.path, "r") as f: # a system call to cp could have significant performance # advantages, however we do not have the path to files at # this point in the abstraction. shutil.copyfileobj(f, data) return elif o.scheme in ["uds", "uds+https"]: try: xfer_mod = uds_download.get_download_handler() if data: path = data.name image_chunks = xfer_mod.download(context, o, path, loc_meta) msg = _("Successfully transferred " "using %s") % o.scheme LOG.info(msg) return except Exception as ex: LOG.exception(ex) elif o.scheme in ["swift", "swift+https"]: try: xfer_mod = swift_download.get_download_handler() if data: path = data.name xfer_mod.download(context, o, 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, 'data', image_id) except Exception: _reraise_translated_image_exception(image_id) if not data: return image_chunks else: path = data.name direct_io.write(path, image_chunks)