Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b7febb9a1 |
@@ -16,6 +16,7 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
|
from oslo_log import log as logging
|
||||||
from requests import codes
|
from requests import codes
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import warlock
|
import warlock
|
||||||
@@ -24,6 +25,8 @@ from glanceclient.common import utils
|
|||||||
from glanceclient import exc
|
from glanceclient import exc
|
||||||
from glanceclient.v2 import schemas
|
from glanceclient.v2 import schemas
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEFAULT_PAGE_SIZE = 200
|
DEFAULT_PAGE_SIZE = 200
|
||||||
|
|
||||||
SORT_DIR_VALUES = ('asc', 'desc')
|
SORT_DIR_VALUES = ('asc', 'desc')
|
||||||
@@ -216,7 +219,12 @@ class Controller(object):
|
|||||||
'This operation is not supported by Glance.')
|
'This operation is not supported by Glance.')
|
||||||
|
|
||||||
@utils.add_req_id_to_object()
|
@utils.add_req_id_to_object()
|
||||||
def data(self, image_id, do_checksum=True, allow_md5_fallback=False):
|
def data(self,
|
||||||
|
image_id,
|
||||||
|
do_checksum=True,
|
||||||
|
allow_md5_fallback=False,
|
||||||
|
direct_download=False,
|
||||||
|
):
|
||||||
"""Retrieve data of an image.
|
"""Retrieve data of an image.
|
||||||
|
|
||||||
When do_checksum is enabled, validation proceeds as follows:
|
When do_checksum is enabled, validation proceeds as follows:
|
||||||
@@ -251,13 +259,31 @@ class Controller(object):
|
|||||||
meta_hash_value = image_meta.get('os_hash_value', None)
|
meta_hash_value = image_meta.get('os_hash_value', None)
|
||||||
meta_hash_algo = image_meta.get('os_hash_algo', None)
|
meta_hash_algo = image_meta.get('os_hash_algo', None)
|
||||||
|
|
||||||
url = '/v2/images/%s/file' % image_id
|
file_fallback = False
|
||||||
resp, body = self.http_client.get(url)
|
if direct_download:
|
||||||
if resp.status_code == codes.no_content:
|
url = '/v2/images/%s/direct-download' % image_id
|
||||||
return None, resp
|
try:
|
||||||
|
resp, body = self.http_client.get(url)
|
||||||
|
except exc.HTTPNotImplemented:
|
||||||
|
LOG.warn("Direct download for %s failed, falling back to "
|
||||||
|
"download from Glance", image_id)
|
||||||
|
file_fallback = True
|
||||||
|
else:
|
||||||
|
if resp.status_code == codes.no_content:
|
||||||
|
return None, resp
|
||||||
|
|
||||||
|
if not direct_download or file_fallback:
|
||||||
|
url = '/v2/images/%s/file' % image_id
|
||||||
|
resp, body = self.http_client.get(url)
|
||||||
|
if resp.status_code == codes.no_content:
|
||||||
|
return None, resp
|
||||||
|
|
||||||
checksum = resp.headers.get('content-md5', None)
|
checksum = resp.headers.get('content-md5', None)
|
||||||
content_length = int(resp.headers.get('content-length', 0))
|
content_length = 0
|
||||||
|
if 'content-length' in resp.headers:
|
||||||
|
content_length = int(resp.headers['content-length'])
|
||||||
|
elif 'Content-Length' in resp.headers:
|
||||||
|
content_length = int(resp.headers['Content-Length'])
|
||||||
|
|
||||||
check_md5sum = do_checksum
|
check_md5sum = do_checksum
|
||||||
if do_checksum and meta_hash_value is not None:
|
if do_checksum and meta_hash_value is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user