'Calls out to Glance for data and writes data.'

def download(self, context, image_id, data=None):

    if (data and ('file' in CONF.allowed_direct_url_schemes)):
        (direct_url, locations) = self.get_location(context, image_id)
        urls = ([direct_url] + [loc.get('url') for loc in (locations or [])])
        for url in urls:
            if (url is None):
                continue
            parsed_url = urllib.parse.urlparse(url)
            if (parsed_url.scheme == 'file'):
                with open(parsed_url.path, 'r') as f:
                    shutil.copyfileobj(f, data)
                return
    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:
        for chunk in image_chunks:
            data.write(chunk)
