diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-01-21 23:05:19 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-01-21 23:05:19 +0000 |
| commit | a4d608fa33b328d7ed77c7f9c40ffbb43c0ade6b (patch) | |
| tree | cf59f08d89515cb1f20da8e01de685bd2f8a9e99 /nova/image | |
| parent | 07531ad264a4fd21faa89f19ad032bf34a223d38 (diff) | |
| parent | 20fca1a2d75c2cd813245200c138df6e854b681b (diff) | |
Merge "Directly copy a file URL from glance."
Diffstat (limited to 'nova/image')
| -rw-r--r-- | nova/image/glance.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/nova/image/glance.py b/nova/image/glance.py index 75551d35c..1a6bba62f 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -22,6 +22,7 @@ from __future__ import absolute_import import copy import itertools import random +import shutil import sys import time import urlparse @@ -58,7 +59,12 @@ glance_opts = [ cfg.IntOpt('glance_num_retries', default=0, help='Number retries when downloading an image from glance'), -] + cfg.ListOpt('allowed_direct_url_schemes', + default=[], + help='A list of url scheme that can be downloaded directly ' + 'via the direct_url. Currently supported schemes: ' + '[file].'), + ] LOG = logging.getLogger(__name__) CONF = cfg.CONF @@ -254,6 +260,18 @@ class GlanceImageService(object): def download(self, context, image_id, data): """Calls out to Glance for metadata and data and writes data.""" + if 'file' in CONF.allowed_direct_url_schemes: + location = self.get_location(context, image_id) + o = urlparse.urlparse(location) + if o.scheme == "file": + with open(o.path, "r") as f: + # FIXME(jbresnah) 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 + try: image_chunks = self._client.call(context, 1, 'data', image_id) except Exception: |
