summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Santa Barbara <justinsb@justinsb-desktop>2010-07-31 21:35:58 -0700
committerJustin Santa Barbara <justinsb@justinsb-desktop>2010-07-31 21:35:58 -0700
commit6c32e87c1be80230cf058586cee5a94cd25670b8 (patch)
tree2359a0408fc208632226e86eb2abc5dea2fd3507
parent08f8bb4183a5a44f71c4c447a46668ecff6a03fb (diff)
Fixed up some of the raw disk stuff that broke in the abstraction out of libvirt
-rw-r--r--nova/compute/disk.py3
-rw-r--r--nova/virt/libvirt_conn.py48
2 files changed, 38 insertions, 13 deletions
diff --git a/nova/compute/disk.py b/nova/compute/disk.py
index 848ce8b54..cace849fa 100644
--- a/nova/compute/disk.py
+++ b/nova/compute/disk.py
@@ -109,6 +109,9 @@ def inject_data(image, key=None, net=None, dns=None, remove_network_udev=False,
else:
mapped_device = device
+ if not os.path.exists(mapped_device):
+ raise exception.Error('Mapped device was not found: %s' % mapped_device)
+
# Configure ext2fs so that it doesn't auto-check every N boots
out, err = yield execute('sudo tune2fs -c 0 -i 0 %s' % mapped_device)
diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py
index 8d473296a..d18158678 100644
--- a/nova/virt/libvirt_conn.py
+++ b/nova/virt/libvirt_conn.py
@@ -195,32 +195,54 @@ class LibvirtConnection(object):
user = manager.AuthManager().get_user(data['user_id'])
if not os.path.exists(basepath('disk')):
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'), user)
- if not os.path.exists(basepath('ramdisk')):
- yield images.fetch(data['ramdisk_id'], basepath('ramdisk'), user)
+
+ using_kernel = data['kernel_id'] and True
+
+ if using_kernel:
+ if not os.path.exists(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'), user)
execute = lambda cmd, input=None: \
process.simple_execute(cmd=cmd,
input=input,
error_ok=1)
+ # For now, we assume that if we're not using a kernel, we're using a partitioned disk image
+ # where the target partition is the first partition
+ target_partition = None
+ if not using_kernel:
+ target_partition = "1"
+
key = data['key_data']
net = None
if FLAGS.simple_network:
- with open(FLAGS.simple_network_template) as f:
- net = f.read() % {'address': data['private_dns_name'],
+ network_info = {'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}
- if key or net:
+
+ with open(FLAGS.simple_network_template) as f:
+ net = f.read() % network_info
+
+ with open(FLAGS.simple_network_dns_template) as f:
+ dns = str(Template(f.read(), searchList=[ network_info ] ))
+
+
+ if key or net or dns:
logging.info('Injecting data into image %s', data['image_id'])
- yield disk.inject_data(basepath('disk-raw'), key, net, execute=execute)
+ try:
+ yield disk.inject_data(basepath('disk-raw'), key=key, net=net, dns=dns, remove_network_udev=True, partition=target_partition, execute=execute)
+ except Exception as e:
+ # This could be a windows image, or a vmdk format disk
+ logging.warn('Could not inject data; ignoring. (%s)' % e)
- if os.path.exists(basepath('disk')):
- yield process.simple_execute('rm -f %s' % basepath('disk'))
+ if using_kernel:
+ if os.path.exists(basepath('disk')):
+ yield process.simple_execute('rm -f %s' % basepath('disk'))
bytes = (instance_types.INSTANCE_TYPES[data['instance_type']]['local_gb']
* 1024 * 1024 * 1024)
@@ -232,15 +254,15 @@ class LibvirtConnection(object):
return os.path.abspath(os.path.join(instance.datamodel['basepath'], path))
- def toXml(self):
+ def toXml(self, instance):
# TODO(termie): cache?
logging.debug("Starting the toXML method")
template_contents = open(FLAGS.libvirt_xml_template).read()
- xml_info = self.datamodel.copy()
+ xml_info = instance.datamodel.copy()
# TODO(joshua): Make this xml express the attached disks as well
# TODO(termie): lazy lazy hack because xml is annoying
- xml_info['nova'] = json.dumps(self.datamodel.copy())
+ xml_info['nova'] = json.dumps(instance.datamodel.copy())
if xml_info['kernel_id']:
xml_info['kernel'] = xml_info['basepath'] + "/kernel"