<?xml version="1.0"?>
<Envelope ovf:version="2.0" xml:lang="en-US" xmlns="http://schemas.dmtf.org/ovf/envelope/2" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/2" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:epasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_EthernetPortAllocationSettingData.xsd" xmlns:sasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_StorageAllocationSettingData.xsd">
    <References>
{%- for disk in disks %}
        <File ovf:id="file{{ loop.index }}" ovf:href="{{ disk.filename }}.vmdk"/>
{%- endfor %}
    </References>
    <DiskSection>
{%- for disk in disks %}
        <Disk ovf:capacity="{{ disk.size }}" ovf:diskId="disk{{ loop.index }}" ovf:fileRef="file{{ loop.index }}" ovf:format="http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized"/>
{%- endfor %}
    </DiskSection>
    <NetworkSection>
        <Info>Logical networks used in the package</Info>
        <Network ovf:name="NAT">
            <Description>Logical network used by this appliance.</Description>
        </Network>
    </NetworkSection>
    <VirtualSystem ovf:id="{{ name }}">
        <Description>{{ vm.description }}</Description>
        <name>{{ name }}</name>
        <OperatingSystemSection ovf:id="{{ os_id }}">
            <Info>Specifies the operating system installed</Info>
            <Description>{{ vm.system }}</Description>
        </OperatingSystemSection>
        <VirtualHardwareSection>
            <Info>Virtual hardware requirements for a virtual machine</Info>
            <Item>
                <rasd:Description>Virtual CPU</rasd:Description>
                <rasd:InstanceID>1</rasd:InstanceID>
                <rasd:ResourceType>3</rasd:ResourceType>
                <rasd:VirtualQuantity>{{ vm.num_cores }}</rasd:VirtualQuantity>
                <rasd:VirtualQuantityUnit>Count</rasd:VirtualQuantityUnit>
            </Item>
            <Item>
                <rasd:AllocationUnits>MegaBytes</rasd:AllocationUnits>
                <rasd:Description>Memory Size</rasd:Description>
                <rasd:InstanceID>2</rasd:InstanceID>
                <rasd:ResourceType>4</rasd:ResourceType>
                <rasd:VirtualQuantity>{{ vm.ram_size }}</rasd:VirtualQuantity>
            </Item>
            <Item>
                <rasd:Address>0</rasd:Address>
                <rasd:InstanceID>3</rasd:InstanceID>
                <rasd:ResourceSubType>PIIX4</rasd:ResourceSubType>
                <rasd:ResourceType>5</rasd:ResourceType>
            </Item>
            <Item>
                <rasd:Address>1</rasd:Address>
                <rasd:InstanceID>4</rasd:InstanceID>
                <rasd:ResourceSubType>PIIX4</rasd:ResourceSubType>
                <rasd:ResourceType>5</rasd:ResourceType>
            </Item>
{%- set ns = namespace(InstanceID = 4) %}{%- for disk in disks %}{%- set ns.InstanceID = ns.InstanceID + 1 %}
            <StorageItem>
                <sasd:AddressOnParent>{{ (loop.index - 1) % 2}}</sasd:AddressOnParent>
                <sasd:Caption>{{ disk.name }}</sasd:Caption>
                <sasd:Description>Disk Image</sasd:Description>
                <sasd:Parent>{% if loop.index < 3 %}3{% else %}4{% endif %}</sasd:Parent>
                <sasd:HostResource>/disk/disk{{ loop.index }}</sasd:HostResource>
                <sasd:InstanceID>{{ ns.InstanceID }}</sasd:InstanceID>
                <sasd:ResourceType>17</sasd:ResourceType>
            </StorageItem>
{%- endfor %}
{%- for interface in interfaces %}{%- set ns.InstanceID = ns.InstanceID + 1 %}
            <EthernetPortItem>
                <epasd:AutomaticAllocation>true</epasd:AutomaticAllocation>
                <epasd:Caption>{{ interface.vlan.name }}</epasd:Caption>
                <epasd:Connection>NAT</epasd:Connection>
                <epasd:InstanceID>{{ ns.InstanceID }}</epasd:InstanceID>
                <epasd:ResourceType>10</epasd:ResourceType>
            </EthernetPortItem>
{%- endfor %}
        </VirtualHardwareSection>
    </VirtualSystem>
</Envelope>
