<domain type='${type}'>
    <name>${name}</name>
    <memory>${memory_kb}</memory>
    <os>
#if $type == 'lxc'
        <type>exe</type>
        <init>/sbin/init</init>
#else if $type == 'uml'
    #set $root_disk_bus = 'uml'
    #set $ephemeral_disk_bus = 'uml'
        <type>uml</type>
        <kernel>/usr/bin/linux</kernel>
        #set $root_device_name = $getVar('root_device_name', '/dev/ubda')
        <root>${root_device_name}</root>
#else
    #if $type == 'xen'
        #set $root_disk_bus = 'scsi'
        #set $ephemeral_disk_bus = 'scsi'
            <type>linux</type>
            #set $root_device_name = $getVar('root_device_name', '/dev/xvda')
            <root>${root_device_name}</root>
    #else
        #set $ephemeral_disk_bus = 'virtio'
        #if $root_device_type == 'cdrom'
            #set $root_disk_bus = 'ide'
        #else
            #set $root_disk_bus = 'virtio'
        #end if
            <type>hvm</type>
    #end if
    #if $getVar('rescue', False)
        <kernel>${basepath}/kernel.rescue</kernel>
        <initrd>${basepath}/ramdisk.rescue</initrd>
    #else
        #if $getVar('kernel', None)
            <kernel>${kernel}</kernel>
            #if $type == 'xen'
                <cmdline>ro</cmdline>
            #else
                #set $root_device_name = $getVar('root_device_name', '/dev/vda')
                <cmdline>root=${root_device_name} console=ttyS0</cmdline>
            #end if
            #if $getVar('ramdisk', None)
                <initrd>${ramdisk}</initrd>
            #end if
        #else
            <boot dev="hd" />
        #end if
    #end if
#end if
    </os>
    <features>
        <acpi/>
    </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}'/>
            <source file='${basepath}/disk.rescue'/>
            <target dev='${disk_prefix}a' bus='${ephemeral_disk_bus}'/>
        </disk>
        <disk type='file'>
            <driver type='${driver_type}'/>
            <source file='${basepath}/disk'/>
            <target dev='${disk_prefix}b' bus='${ephemeral_disk_bus}'/>
        </disk>
    #else
        #if not ($getVar('ebs_root', False))
        <disk type='file' device='${root_device_type}'>
            <driver type='${driver_type}'/>
            <source file='${basepath}/disk'/>
            <target dev='${root_device}' bus='${root_disk_bus}'/>
        </disk>
        #end if
        #if $getVar('local_device', False)
            <disk type='file'>
                <driver type='${driver_type}'/>
                <source file='${basepath}/disk.local'/>
                <target dev='${local_device}' bus='${ephemeral_disk_bus}'/>
            </disk>
        #end if
        #for $eph in $ephemerals
         <disk type='block'>
                <driver type='${driver_type}'/>
                <source dev='${basepath}/${eph.device_path}'/>
                <target dev='${eph.device}' bus='${ephemeral_disk_bus}'/>
         </disk>
        #end for
        #if $getVar('swap_device', False)
            <disk type='file'>
                <driver type='${driver_type}'/>
                <source file='${basepath}/disk.swap'/>
                <target dev='${swap_device}' bus='${ephemeral_disk_bus}'/>
            </disk>
        #end if
        #for $vol in $volumes
            ${vol}
        #end for
    #end if
    #if $getVar('config_drive', False)
        <disk type='file'>
            <driver type='raw' />
            <source file='${basepath}/disk.config' />
            <target dev='${disk_prefix}z' bus='${ephemeral_disk_bus}' />
        </disk>
    #end if
#end if

#for $nic in $nics
    #if $vif_type == 'ethernet'
        <interface type='ethernet'>
            <target dev='${nic.name}' />
            <mac address='${nic.mac_address}' />
            <script path='${nic.script}' />
        </interface>
    #else if $vif_type == '802.1Qbh'
       <interface type='direct'>
            <mac address='${nic.mac_address}'/>
            <source dev='${nic.device_name}' mode='private'/>
            <virtualport type='802.1Qbh'>
                <parameters profileid='${nic.profile_name}'/>
            </virtualport>
            <model type='virtio'/>
       </interface>
    #else
        <interface type='bridge'>
            <source bridge='${nic.bridge_name}'/>
            <mac address='${nic.mac_address}'/>
#if $getVar('use_virtio_for_bridges', True)
            <model type='virtio'/>
#end if
            <filterref filter="nova-instance-${name}-${nic.id}">
                <parameter name="IP" value="${nic.ip_address}" />
                <parameter name="DHCPSERVER" value="${nic.dhcp_server}" />
#if $getVar('nic.extra_params', False)
                ${nic.extra_params}
#end if
#if $getVar('nic.gateway_v6', False)
                <parameter name="RASERVER" value="${nic.gateway_v6}" />
#end if
            </filterref>
        </interface>
    #end if

#end for
        <!-- The order is significant here.  File must be defined first -->
        <serial type="file">
            <source path='${basepath}/console.log'/>
            <target port='1'/>
        </serial>

        <console type='pty' tty='/dev/pts/2'>
            <source path='/dev/pts/2'/>
            <target port='0'/>
        </console>

        <serial type='pty'>
            <source path='/dev/pts/2'/>
            <target port='0'/>
        </serial>

#if $getVar('vncserver_listen', False)
        <graphics type='vnc' port='-1' autoport='yes' keymap='${vnc_keymap}' listen='${vncserver_listen}'/>
#end if
    </devices>
</domain>
