diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-02-20 02:47:34 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-02-20 02:47:34 +0000 |
| commit | 384a4ecd2563cf69a5aea5b6011ccb4beeaa95c0 (patch) | |
| tree | 320f60e77be561208e08ed0a0df41f13ff351d27 | |
| parent | 4bc4b25c8d155855b16b42a7f87eb2e1f1bd061b (diff) | |
| parent | 4cc266427307f4d9776207d30ceb1fbec35b3111 (diff) | |
| download | nova-384a4ecd2563cf69a5aea5b6011ccb4beeaa95c0.tar.gz nova-384a4ecd2563cf69a5aea5b6011ccb4beeaa95c0.tar.xz nova-384a4ecd2563cf69a5aea5b6011ccb4beeaa95c0.zip | |
Merge "libvirt: Fix LXC container creation"
| -rw-r--r-- | nova/tests/test_libvirt_blockinfo.py | 15 | ||||
| -rw-r--r-- | nova/virt/libvirt/blockinfo.py | 21 | ||||
| -rwxr-xr-x | nova/virt/libvirt/driver.py | 2 |
3 files changed, 37 insertions, 1 deletions
diff --git a/nova/tests/test_libvirt_blockinfo.py b/nova/tests/test_libvirt_blockinfo.py index 68f1fa394..5560e63fd 100644 --- a/nova/tests/test_libvirt_blockinfo.py +++ b/nova/tests/test_libvirt_blockinfo.py @@ -178,6 +178,21 @@ class LibvirtBlockInfoTest(test.TestCase): } self.assertEqual(mapping, expect) + def test_get_disk_mapping_lxc(self): + # A simple disk mapping setup, but for lxc + + user_context = context.RequestContext(self.user_id, self.project_id) + instance_ref = db.instance_create(user_context, self.test_instance) + + mapping = blockinfo.get_disk_mapping("lxc", instance_ref, + "lxc", "lxc", + None) + expect = { + 'disk': {'bus': 'lxc', 'dev': None, 'type': 'disk'}, + 'root': {'bus': 'lxc', 'dev': None, 'type': 'disk'} + } + self.assertEqual(mapping, expect) + def test_get_disk_mapping_simple_iso(self): # A simple disk mapping setup, but with a ISO for root device diff --git a/nova/virt/libvirt/blockinfo.py b/nova/virt/libvirt/blockinfo.py index 0098410cd..09e3809d9 100644 --- a/nova/virt/libvirt/blockinfo.py +++ b/nova/virt/libvirt/blockinfo.py @@ -116,6 +116,8 @@ def get_dev_prefix_for_disk_bus(disk_bus): return "sd" elif disk_bus == "uml": return "ubd" + elif disk_bus == "lxc": + return None else: raise exception.NovaException( _("Unable to determine disk prefix for %s") % @@ -150,6 +152,9 @@ def find_disk_dev_for_disk_bus(mapping, bus, last_device=False): """ dev_prefix = get_dev_prefix_for_disk_bus(bus) + if dev_prefix is None: + return None + max_dev = get_dev_count_for_disk_bus(bus) if last_device: devs = [max_dev - 1] @@ -172,6 +177,7 @@ def is_disk_bus_valid_for_virt(virt_type, disk_bus): 'kvm': ['virtio', 'scsi', 'ide', 'usb'], 'xen': ['xen', 'ide'], 'uml': ['uml'], + 'lxc': ['lxc'], } if virt_type not in valid_bus: @@ -207,6 +213,8 @@ def get_disk_bus_for_device_type(virt_type, if virt_type == "uml": if device_type == "disk": return "uml" + elif virt_type == "lxc": + return "lxc" elif virt_type == "xen": if device_type == "cdrom": return "ide" @@ -293,6 +301,19 @@ def get_disk_mapping(virt_type, instance, mapping = {} if virt_type == "lxc": + # NOTE(zul): This information is not used by the libvirt driver + # however we need to populate mapping so the image can be + # created when the instance is started. This can + # be removed when we convert LXC to use block devices. + root_disk_bus = disk_bus + root_device_type = 'disk' + + root_info = get_next_disk_info(mapping, + root_disk_bus, + root_device_type) + mapping['root'] = root_info + mapping['disk'] = root_info + return mapping if rescue: diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index e7d4d71a7..d1e201faf 100755 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -1823,7 +1823,7 @@ class LibvirtDriver(driver.ComputeDriver): guest.cpu = self.get_guest_cpu_config() - if 'root' in disk_mapping: + if 'root' in disk_mapping and disk_mapping['root']['dev'] is not None: root_device_name = "/dev/" + disk_mapping['root']['dev'] else: root_device_name = None |
