{# device_type: kvm #}
{% extends 'base.jinja2' %}
{% block body %}

# allow job context override - use a different variable name, undefined if not in job context
{% set base_guest_fs_size = guestfs_size | default(512) %}
{% set qemu_guest_fs_interface = guestfs_interface | default('ide') %}
{% set boot_order = installer_boot_order | default('c') %}

actions:
  deploy:
    methods:
      image:
        parameters:
          guest:
            size: {{ base_guest_fs_size }}  # in Mb
            interface: {{ qemu_guest_fs_interface }}
  boot:
    connections:
      serial:
    methods:
      qemu:
        parameters:
          command:
{% if arch == 'arm64' %}
            qemu-system-aarch64
{% elif arch == 'amd64' %}
            qemu-system-x86_64
{% elif arch == 'i386' %}
            qemu-system-x86
{% endif %}
          boot_options:
{% if arch == 'arm64' %}
            {root: '{{ boot_root|default("/dev/vda2") }} rw rootwait', console: {{ boot_console|default('ttyAMA0 115200') }}, ip: dhcp, mem: 1024M}
{% elif arch == 'amd64' %}
            {root: {{ boot_root|default('/dev/sda1') }},
             console: {{ boot_console|default('ttyS0,115200') }},
             boot_order: {{ installer_boot_order }}}
{% else %}
            {root: {{ boot_root|default('/dev/sda1') }}, console: {{ boot_console|default('ttyS0,115200') }}}
{% endif %}
          options:
{% block qemu_options %}
          - -nographic
          - -enable-kvm
          - -cpu host
          - -net nic,model=virtio,macaddr={{ mac_addr|default('52:54:00:12:34:58') }} -net {{ netdevice|default('user') }}
          - -m {{ memory|default(512) }}
{% endblock qemu_options %}
{% endblock body %}
