You don't use the partition kwarg, so don't pass it. It's confusing.
> + """Setup the LXC container
> +
> + It will mount the loopback image to the container directory in order
> + to create the root filesystem for the container
> + """
> + nbd = False
> + device = _link_device(image, nbd)
> + err = utils.execute('sudo', 'mount', device, container_dir)
> + if err:
> + raise exception.Error(_('Failed to mount filesystem: %s')
> + % err)
> + _unlink_device(device, nbd)
> +
> +
> +def destroy_container(target, instance):
> + """Destroy the container once it terminates
> +
> + It will umount the container that is mounted, try to find the loopback
> + device associated with the container and delete it.
> + """
> + try:
> + container_dir = '%s/rootfs' % target
> + utils.execute('sudo', 'umount', container_dir)
> + finally:
> + for loop in utils.popen('sudo losetup -a').readlines():
> === modified file 'nova/virt/disk.py' device( device, nbd) (image, container_dir=None, partition=None):
> --- nova/virt/disk.py 2011-03-17 15:29:04 +0000
> +++ nova/virt/disk.py 2011-03-24 10:26:05 +0000
> @@ -115,6 +115,37 @@
> _unlink_
>
>
> +def setup_container
You don't use the partition kwarg, so don't pass it. It's confusing.
> + """Setup the LXC container 'sudo', 'mount', device, container_dir) Error(_ ('Failed to mount filesystem: %s') device( device, nbd) container( target, instance): 'sudo', 'umount', container_dir)
> +
> + It will mount the loopback image to the container directory in order
> + to create the root filesystem for the container
> + """
> + nbd = False
> + device = _link_device(image, nbd)
> + err = utils.execute(
> + if err:
> + raise exception.
> + % err)
> + _unlink_
> +
> +
> +def destroy_
> + """Destroy the container once it terminates
> +
> + It will umount the container that is mounted, try to find the loopback
> + device associated with the container and delete it.
> + """
> + try:
> + container_dir = '%s/rootfs' % target
> + utils.execute(
> + finally:
> + for loop in utils.popen('sudo losetup -a').readlines():
There's no such things as utils.popen.
> + if instance['name'] in loop: 'sudo', 'losetup', '--detach', device) libvirt. xml.template' libvirt. xml.template 2011-03-23 19:46:24 +0000 libvirt. xml.template 2011-03-24 10:26:05 +0000 {name}< /name> ${memory_ kb}</memory> sbin/init< /init>
> + device = loop.split(loop, ':')
> + utils.execute(
> +
> +
> def _link_device(image, nbd):
> """Link image to device using loopback or nbd"""
> if nbd:
>
> === modified file 'nova/virt/
> --- nova/virt/
> +++ nova/virt/
> @@ -2,6 +2,12 @@
> <name>$
> <memory>
> <os>
> +#if $type == 'lxc'
> + #set $disk_prefix = ''
> + #set $disk_bus = ''
> + <type>exe</type>
> + <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
Your indentations don't line up.
> #end if {vcpus} </vcpu> basepath} /rootfs' />
> </os>
> <features>
> @@ -44,6 +51,12 @@
> </features>
> <vcpu>$
> <devices>
> +#if $type == 'lxc'
> + <filesystem type='mount'>
> + <source dir='${
> + <target dir='/'/>
> + </filesystem>
> +#else
You're still missing a unit test for this. What's the difficulty?
> #if $getVar('rescue', False) {driver_ type}'/ > disk_prefix} b' bus='${disk_bus}'/>
> <disk type='file'>
> <driver type='$
> @@ -68,6 +81,7 @@
> <target dev='${
> </disk>
> #end if
> + #end if
Again, odd indentation. It's hard enough to read as it is. Please make sure that #if's line up with their corresponding "#end if"s.
> === modified file 'nova/virt/ libvirt_ conn.py' libvirt_ conn.py 2011-03-24 10:15:52 +0000 libvirt_ conn.py 2011-03-24 10:26:05 +0000 string( 'libvirt_ type', string( 'libvirt_ uri', _('instance %(instance_name)s: deleting instance files' container( target, instance) exists( target) : rmtree( target) xen_console( virsh_output) to_file( data, console_log) libvirt_ xml) 'mkdir' , '-p', container_dir) os.open( basepath( 'console. log', ''), 'key_data' ]) get_by_ instance( context. get_admin_ context( ), data(basepath( 'disk') , key, net, target_ partition, use_cow_ images) container( basepath( 'disk') , dir=container_ dir, target_ partition) _('instance %(inst_name)s: ignoring error injecting'
> --- nova/virt/
> +++ nova/virt/
> @@ -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**
>
> @@ -85,7 +85,7 @@
> flags.DEFINE_
> 'kvm',
> 'Libvirt domain type (valid options are: '
> - 'kvm, qemu, uml, xen)')
> + 'kvm, lxc, qemu, uml, xen)')
> flags.DEFINE_
> '',
> 'Override the default libvirt URI (which is dependent'
> @@ -218,6 +218,8 @@
> 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
> @@ -296,6 +298,8 @@
> instance_name = instance['name']
> LOG.info(
> ' %(target)s') % locals())
> + if FLAGS.libvirt_type == 'lxc':
> + disk.destroy_
> if os.path.
> shutil.
>
> @@ -518,6 +522,9 @@
> instance['name'])
> data = self._flush_
> fpath = self._append_
> + elif FLAGS.libvirt_type == 'lxc':
> + # LXC is also special
> + LOG.info(_("Unable to read LXC console"))
> else:
> fpath = console_log
>
> @@ -624,6 +631,10 @@
> f.write(
> f.close()
>
> + if FLAGS.libvirt_type == 'lxc':
> + container_dir = '%s/rootfs' % basepath(suffix='')
> + utils.execute(
> +
> # NOTE(vish): No need add the suffix to console.log
> os.close(
> os.O_CREAT | os.O_WRONLY, 0660))
> @@ -683,6 +694,9 @@
> if not inst['kernel_id']:
> target_partition = "1"
>
> + if FLAGS.libvirt_type == 'lxc':
> + target_partition = None
> +
> key = str(inst[
> net = None
> network_ref = db.network_
> @@ -720,6 +734,11 @@
> disk.inject_
> partition=
> nbd=FLAGS.
> +
> + if FLAGS.libvirt_type == 'lxc':
> + disk.setup_
> + container_
> + partition=
> except Exception as e:
> # This could be a windows image, or a vmdk format disk
> LOG.warn(