diff options
| author | Ewan Mellor <ewan.mellor@citrix.com> | 2010-07-29 00:11:02 +0100 |
|---|---|---|
| committer | Ewan Mellor <ewan.mellor@citrix.com> | 2010-07-29 00:11:02 +0100 |
| commit | 9f4996e8738991a95a23cba2caa660f7002f94cd (patch) | |
| tree | e40bc2e56ea96131200d5e12918bf5a429bb5cc1 /nova/virt | |
| parent | c5edaa2186add12947185cb1fd47e0a48eccafa9 (diff) | |
| parent | f61b62983f62aa10d7bed3bc1c406717663be923 (diff) | |
Merge with trunk, including fixing up conflicts with the removal of fake_users
and the reworking of node.py -> service.py.
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/images.py | 28 | ||||
| -rw-r--r-- | nova/virt/libvirt_conn.py | 8 |
2 files changed, 28 insertions, 8 deletions
diff --git a/nova/virt/images.py b/nova/virt/images.py index 12338fd80..92210e242 100644 --- a/nova/virt/images.py +++ b/nova/virt/images.py @@ -22,9 +22,11 @@ Handling of VM disk images. """ import os.path +import time from nova import flags from nova import process +from nova.auth import signer FLAGS = flags.FLAGS @@ -32,18 +34,34 @@ flags.DEFINE_bool('use_s3', True, 'whether to get images from s3 or use local copy') -def fetch(image, path): +def fetch(image, path, user): if FLAGS.use_s3: f = _fetch_s3_image else: f = _fetch_local_image - return f(image, path) + return f(image, path, user) -def _fetch_s3_image(image, path): +def _fetch_s3_image(image, path, user): url = _image_url('%s/image' % image) - return process.simple_execute('curl --silent %s -o %s' % (url, path)) -def _fetch_local_image(image, path): + # This should probably move somewhere else, like e.g. a download_as + # method on User objects and at the same time get rewritten to use + # twisted web client. + headers = {} + headers['Date'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()) + + uri = '/' + url.partition('/')[2] + auth = signer.Signer(user.secret.encode()).s3_authorization(headers, 'GET', uri) + headers['Authorization'] = 'AWS %s:%s' % (user.access, auth) + + cmd = ['/usr/bin/curl', '--silent', url] + for (k,v) in headers.iteritems(): + cmd += ['-H', '%s: %s' % (k,v)] + + cmd += ['-o', path] + return process.SharedPool().execute(executable=cmd[0], args=cmd[1:]) + +def _fetch_local_image(image, path, _): source = _image_path('%s/image' % image) return process.simple_execute('cp %s %s' % (source, path)) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 2c34711bc..c545e4190 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -34,6 +34,7 @@ from nova import exception from nova import flags from nova import process from nova import utils +from nova.auth import manager from nova.compute import disk from nova.compute import instance_types from nova.compute import power_state @@ -185,12 +186,13 @@ class LibvirtConnection(object): f.write(libvirt_xml) f.close() + user = manager.AuthManager().get_user(data['user_id']) if not os.path.exists(basepath('disk')): - yield images.fetch(data['image_id'], basepath('disk-raw')) + yield images.fetch(data['image_id'], basepath('disk-raw'), user) if not os.path.exists(basepath('kernel')): - yield images.fetch(data['kernel_id'], basepath('kernel')) + yield images.fetch(data['kernel_id'], basepath('kernel'), user) if not os.path.exists(basepath('ramdisk')): - yield images.fetch(data['ramdisk_id'], basepath('ramdisk')) + yield images.fetch(data['ramdisk_id'], basepath('ramdisk'), user) execute = lambda cmd, input=None: \ process.simple_execute(cmd=cmd, |
