summaryrefslogtreecommitdiffstats
path: root/nova/virt
diff options
context:
space:
mode:
authorEwan Mellor <ewan.mellor@citrix.com>2010-08-11 14:23:59 +0100
committerEwan Mellor <ewan.mellor@citrix.com>2010-08-11 14:23:59 +0100
commit57beed337d3c267b69eaf73f166fd00ea29f2498 (patch)
tree24065950eb39fd4f7517d050f454faff3dd85544 /nova/virt
parent035f93aa7dc19656bf22de9b7ccfe12b28cde61b (diff)
parent57f834ba7881c116adedfa3b3f1065bf0f0c072e (diff)
Merged with trunk.
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/images.py16
-rw-r--r--nova/virt/libvirt_conn.py41
2 files changed, 35 insertions, 22 deletions
diff --git a/nova/virt/images.py b/nova/virt/images.py
index 698536324..1e23c48b9 100644
--- a/nova/virt/images.py
+++ b/nova/virt/images.py
@@ -28,6 +28,7 @@ import urlparse
from nova import flags
from nova import process
from nova.auth import signer
+from nova.auth import manager
FLAGS = flags.FLAGS
@@ -35,14 +36,14 @@ flags.DEFINE_bool('use_s3', True,
'whether to get images from s3 or use local copy')
-def fetch(image, path, user):
+def fetch(image, path, user, project):
if FLAGS.use_s3:
f = _fetch_s3_image
else:
f = _fetch_local_image
- return f(image, path, user)
+ return f(image, path, user, project)
-def _fetch_s3_image(image, path, user):
+def _fetch_s3_image(image, path, user, project):
url = image_url(image)
# This should probably move somewhere else, like e.g. a download_as
@@ -52,8 +53,11 @@ def _fetch_s3_image(image, path, user):
headers['Date'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
(_, _, url_path, _, _, _) = urlparse.urlparse(url)
- auth = signer.Signer(user.secret.encode()).s3_authorization(headers, 'GET', url_path)
- headers['Authorization'] = 'AWS %s:%s' % (user.access, auth)
+ access = manager.AuthManager().get_access_key(user, project)
+ signature = signer.Signer(user.secret.encode()).s3_authorization(headers,
+ 'GET',
+ url_path)
+ headers['Authorization'] = 'AWS %s:%s' % (access, signature)
cmd = ['/usr/bin/curl', '--silent', url]
for (k,v) in headers.iteritems():
@@ -62,7 +66,7 @@ def _fetch_s3_image(image, path, user):
cmd += ['-o', path]
return process.SharedPool().execute(executable=cmd[0], args=cmd[1:])
-def _fetch_local_image(image, path, _):
+def _fetch_local_image(image, path, user, project):
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 c545e4190..13305be0f 100644
--- a/nova/virt/libvirt_conn.py
+++ b/nova/virt/libvirt_conn.py
@@ -25,7 +25,6 @@ import json
import logging
import os.path
import shutil
-import sys
from twisted.internet import defer
from twisted.internet import task
@@ -47,6 +46,13 @@ FLAGS = flags.FLAGS
flags.DEFINE_string('libvirt_xml_template',
utils.abspath('compute/libvirt.xml.template'),
'Libvirt XML Template')
+flags.DEFINE_string('injected_network_template',
+ utils.abspath('compute/interfaces.template'),
+ 'Template file for injected network')
+
+flags.DEFINE_string('libvirt_type',
+ 'kvm',
+ 'Libvirt domain type (kvm, qemu, etc)')
def get_connection(read_only):
# These are loaded late so that there's no need to install these
@@ -108,7 +114,8 @@ class LibvirtConnection(object):
def _cleanup(self, instance):
target = os.path.abspath(instance.datamodel['basepath'])
logging.info("Deleting instance files at %s", target)
- shutil.rmtree(target)
+ if os.path.exists(target):
+ shutil.rmtree(target)
@defer.inlineCallbacks
@@ -187,12 +194,13 @@ class LibvirtConnection(object):
f.close()
user = manager.AuthManager().get_user(data['user_id'])
+ project = manager.AuthManager().get_project(data['project_id'])
if not os.path.exists(basepath('disk')):
- yield images.fetch(data['image_id'], basepath('disk-raw'), user)
+ yield images.fetch(data['image_id'], basepath('disk-raw'), user, project)
if not os.path.exists(basepath('kernel')):
- yield images.fetch(data['kernel_id'], basepath('kernel'), user)
+ yield images.fetch(data['kernel_id'], basepath('kernel'), user, project)
if not os.path.exists(basepath('ramdisk')):
- yield images.fetch(data['ramdisk_id'], basepath('ramdisk'), user)
+ yield images.fetch(data['ramdisk_id'], basepath('ramdisk'), user, project)
execute = lambda cmd, input=None: \
process.simple_execute(cmd=cmd,
@@ -201,14 +209,14 @@ class LibvirtConnection(object):
key = data['key_data']
net = None
- if FLAGS.simple_network:
- with open(FLAGS.simple_network_template) as f:
+ if data.get('inject_network', False):
+ with open(FLAGS.injected_network_template) as f:
net = f.read() % {'address': data['private_dns_name'],
- 'network': FLAGS.simple_network_network,
- 'netmask': FLAGS.simple_network_netmask,
- 'gateway': FLAGS.simple_network_gateway,
- 'broadcast': FLAGS.simple_network_broadcast,
- 'dns': FLAGS.simple_network_dns}
+ 'network': data['network_network'],
+ 'netmask': data['network_netmask'],
+ 'gateway': data['network_gateway'],
+ 'broadcast': data['network_broadcast'],
+ 'dns': data['network_dns']}
if key or net:
logging.info('Injecting data into image %s', data['image_id'])
yield disk.inject_data(basepath('disk-raw'), key, net, execute=execute)
@@ -235,6 +243,7 @@ class LibvirtConnection(object):
# TODO(termie): lazy lazy hack because xml is annoying
xml_info['nova'] = json.dumps(instance.datamodel.copy())
+ xml_info['type'] = FLAGS.libvirt_type
libvirt_xml = libvirt_xml % xml_info
logging.debug("Finished the toXML method")
@@ -255,7 +264,7 @@ class LibvirtConnection(object):
"""
Note that this function takes an instance ID, not an Instance, so
that it can be called by monitor.
-
+
Returns a list of all block devices for this domain.
"""
domain = self._conn.lookupByName(instance_id)
@@ -298,7 +307,7 @@ class LibvirtConnection(object):
"""
Note that this function takes an instance ID, not an Instance, so
that it can be called by monitor.
-
+
Returns a list of all network interfaces for this instance.
"""
domain = self._conn.lookupByName(instance_id)
@@ -341,7 +350,7 @@ class LibvirtConnection(object):
"""
Note that this function takes an instance ID, not an Instance, so
that it can be called by monitor.
- """
+ """
domain = self._conn.lookupByName(instance_id)
return domain.blockStats(disk)
@@ -350,6 +359,6 @@ class LibvirtConnection(object):
"""
Note that this function takes an instance ID, not an Instance, so
that it can be called by monitor.
- """
+ """
domain = self._conn.lookupByName(instance_id)
return domain.interfaceStats(interface)