From ae1040232dc681d718d940af11108322044a23be Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Tue, 6 Aug 2013 10:15:27 -0400 Subject: [PATCH] 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 --- nova/image/glance.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/nova/image/glance.py b/nova/image/glance.py index 9a691bf53d1d..dae52aa560e5 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -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)