diff options
| author | Chuck Short <zulcss@ubuntu.com> | 2011-02-27 12:51:19 -0500 |
|---|---|---|
| committer | Chuck Short <zulcss@ubuntu.com> | 2011-02-27 12:51:19 -0500 |
| commit | 1278af43c16daea1bcbd2d47cd2d81919fe2c37e (patch) | |
| tree | 4622b0399d77b54ca4604c21e4d285a03434b442 | |
| parent | edf5da85648659b1a7ad105248d69ef9f8c977e4 (diff) | |
Add lxc libvirt driver
| -rw-r--r-- | nova/virt/libvirt.xml.template | 14 | ||||
| -rw-r--r-- | nova/virt/libvirt_conn.py | 13 |
2 files changed, 25 insertions, 2 deletions
diff --git a/nova/virt/libvirt.xml.template b/nova/virt/libvirt.xml.template index 88bfbc668..87dea9039 100644 --- a/nova/virt/libvirt.xml.template +++ b/nova/virt/libvirt.xml.template @@ -2,6 +2,12 @@ <name>${name}</name> <memory>${memory_kb}</memory> <os> +#if $type == 'lxc' + #set $disk_prefix = '' + #set $disk_bus = '' + <type>exe</type> + <init>/sbin/init</init> +#else #if $type == 'uml' #set $disk_prefix = 'ubd' #set $disk_bus = 'uml' @@ -37,6 +43,7 @@ <boot dev="hd" /> #end if #end if + #end if #end if </os> <features> @@ -44,6 +51,12 @@ </features> <vcpu>${vcpus}</vcpu> <devices> +#if $type == 'lxc' + <filesystem type='mount'> + <source dir='${basepath}/rootfs'/> + <target dir='/'/> + </filesystem> +#else #if $getVar('rescue', False) <disk type='file'> <driver type='${driver_type}'/> @@ -68,6 +81,7 @@ <target dev='${disk_prefix}b' bus='${disk_bus}'/> </disk> #end if + #end if #end if <interface type='bridge'> <source bridge='${bridge_name}'/> diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 4e0fd106f..f97c10765 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -20,7 +20,7 @@ """ A connection to a hypervisor through libvirt. -Supports KVM, QEMU, UML, and XEN. +Supports KVM, LXC, QEMU, UML, and XEN. **Related Flags** @@ -83,7 +83,7 @@ flags.DEFINE_string('libvirt_xml_template', flags.DEFINE_string('libvirt_type', 'kvm', 'Libvirt domain type (valid options are: ' - 'kvm, qemu, uml, xen)') + 'kvm, lxc, qemu, uml, xen)') flags.DEFINE_string('libvirt_uri', '', 'Override the default libvirt URI (which is dependent' @@ -202,6 +202,8 @@ class LibvirtConnection(object): uri = FLAGS.libvirt_uri or 'uml:///system' elif FLAGS.libvirt_type == 'xen': uri = FLAGS.libvirt_uri or 'xen:///' + elif FLAGS.libvirt_type == 'lxc': + uri = FLAGS.libvirt_uri or 'lxc:///' else: uri = FLAGS.libvirt_uri or 'qemu:///system' return uri @@ -565,6 +567,10 @@ class LibvirtConnection(object): f.write(libvirt_xml) f.close() + if FLAGS.libvirt_type == 'lxc': + container_dir = '%s/rootfs' % basepath(suffix='') + utils.execute('mkdir -p %s' % container_dir) + # NOTE(vish): No need add the suffix to console.log os.close(os.open(basepath('console.log', ''), os.O_CREAT | os.O_WRONLY, 0660)) @@ -622,6 +628,9 @@ class LibvirtConnection(object): if not inst['kernel_id']: target_partition = "1" + if FLAGS.libvirt_type == 'lxc': + target_partition = None + key = str(inst['key_data']) net = None network_ref = db.network_get_by_instance(context.get_admin_context(), |
