<domain type='kvm'>
    <name>{{machinename}}</name>
    <memory unit='MB'>{{memory}}</memory>
    <vcpu placement='static'>{{nrcpu}}</vcpu>
    <os>
        <type arch='x86_64' machine='pc'>hvm</type>
        <boot dev='hd'/>
    </os>
    <features>
        <acpi/>
        <apic/>
        <pae/>
    </features>
    <clock offset='utc'/>
    <on_poweroff>destroy</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>restart</on_crash>
    <devices>
        <emulator>/usr/bin/qemu-system-x86_64</emulator>
        {% for disk in disks %}
          <disk type='volume' device='disk'>
            <driver name='qemu' type='qcow2'/>
            <source pool='{{disk.pool.name}}' volume='{{disk.name}}'/>
            <target dev='vd{{"abcdefghijklmnopqrstuvwxyz"[loop.index0]}}' bus='virtio'/>
            {% if disk.disk_iops %}
            <iotune>
                <total_bytes_sec>{{disk.disk_iops}}</total_bytes_sec>
            </iotune>
            {% endif %}
          </disk>
        {% endfor %}
        {% if cloudinit %}
          <disk type='file' device='cdrom'>
            <driver name='qemu' type='raw'/>
            <source file='{{image_path}}'/>
            <target dev='hda' bus='ide'/>
          </disk>
        {% endif %}
        {% for nic in nics %}
            {{nic.to_xml()}}
        {% endfor %}
        <graphics type='vnc' autoport='yes' listen='0.0.0.0'>
            <listen type='address' address='0.0.0.0'/>
        </graphics>
        <serial type='pty'>
            <source path='/dev/pts/1'/>
            <target port='0'/>
            <alias name='serial0'/>
        </serial>
        <console type='pty' tty='/dev/pts/1'>
            <source path='/dev/pts/1'/>
            <target type='serial' port='0'/>
            <alias name='serial0'/>
        </console>
    </devices>
</domain>
