Avoid extra glance v2 locations call!

In 7df1c911 we added code to attempt to direct download
images from glance locations. This feature is meant to be off
by default however when it is disabled it adds an unnecessary
glance V2 API call.

This patch removes the extra get_locations call when
CONF.allowed_direct_url_schemes is empty (disabled). This effectively
fixes Nova on Python some 2.6 distros which fail to work with the
recent Glance V2 schema code.

Fixes LP Bug #1208656

Change-Id: I0989ed4f248cd1126d4703ad6498cfd66685ae31
This commit is contained in:
Dan Prince 2013-08-06 10:15:27 -04:00
parent 7df1c911e4
commit ae1040232d

View File

@ -313,19 +313,21 @@ class GlanceImageService(object):
def download(self, context, image_id, data=None):
"""Calls out to Glance for data and writes data."""
locations = self._get_locations(context, image_id)
for entry in 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(o, data, loc_meta)
LOG.info("Successfully transferred using %s" % o.scheme)
return
except Exception as ex:
LOG.exception(ex)
if CONF.allowed_direct_url_schemes:
locations = self._get_locations(context, image_id)
for entry in 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(o, data, loc_meta)
LOG.info("Successfully transferred using %s"
% o.scheme)
return
except Exception as ex:
LOG.exception(ex)
try:
image_chunks = self._client.call(context, 1, 'data', image_id)