summaryrefslogtreecommitdiffstats
path: root/nova/image
diff options
context:
space:
mode:
authorJohn Bresnahan <jbresnah@redhat.com>2013-01-10 07:19:28 -1000
committerJohn Bresnahan <jbresnah@redhat.com>2013-01-18 08:25:19 -1000
commit20fca1a2d75c2cd813245200c138df6e854b681b (patch)
tree1c9c2a36e929c695b7eee029d17c30a9439cadf6 /nova/image
parent664ea40ebb0ee29a5fd11effeeed279ddc543f89 (diff)
downloadnova-20fca1a2d75c2cd813245200c138df6e854b681b.tar.gz
nova-20fca1a2d75c2cd813245200c138df6e854b681b.tar.xz
nova-20fca1a2d75c2cd813245200c138df6e854b681b.zip
Directly copy a file URL from glance.
That patch allows nova to use shutil to copy a file directly from the glance store. For this to work glance needs to enable direct_url descriptions in the image metadata. This is done by setting show_image_direct_url to True in glance-api.conf. The path used to back glance also must match the path used to back nova instance storage. This should be a large performance increase for the cases where both glance and nova instance storage are backed by a shared file system like gluster or ceph. A new option has been added to nova: allowed_direct_url_schemes This option is set to a list of schemes that can be directly accessed. For this first simple patch only file:// is valid, and the implementation is simple and inline. In the future it would be better to make this into propagation modules which are dynamically loaded according to the scheme. DocImpact Implements: blueprint direct-file-copy Change-Id: I041b5524f8a0ea59e89ece0202f0503abf2f9d8e
Diffstat (limited to 'nova/image')
-rw-r--r--nova/image/glance.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/nova/image/glance.py b/nova/image/glance.py
index 6a5406d9e..8bda7285f 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: