{# device_type: qemu #}
{% extends 'base.yaml.jinja2' %}

{% block vland %}
{# disabled #}
{% endblock vland %}

{% 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 qemu_guest_fs_driveid = guestfs_driveid | default('lavatest') %}

{# see https://packages.debian.org/buster/amd64/qemu-system-misc/filelist #}
{% set qemu_misc_architectures = [
'alpha', 'cris', 'lm32', 'm68k', 'microblaze', 'microblazeel',
'moxie', 'or32', 's390x', 'sh4', 'sh4eb', 'tricore', 'unicore32',
'xtensa', 'xtensaeb'] %}

available_architectures:
- arm64
- arm
- aarch64
- amd64
- x86_64
- hppa
- i386
- mips
- mipsel
- mips64
- mips64el
- nios2
- ppc
- ppc64
- ppc64le
- riscv64
- sparc
- sparc64
{% for arch in qemu_misc_architectures %}
- {{ arch }}
{% endfor %}

actions:
  deploy:
    connections:
      serial:
      lxc:
    methods:
      nfs:
      lxc:
      image:
        parameters:
          guest:
            size: {{ base_guest_fs_size }}  # in Mb
            interface: {{ qemu_guest_fs_interface }}
            driveid: {{ qemu_guest_fs_driveid }}
  boot:
    connections:
      serial:
      ssh:
      lxc:
    methods:
      qemu:
{% block qemu_method %}
        parameters:
          command:
{# start arch command #}
{% if arch == 'arm64' or arch == 'aarch64' %}
            qemu-system-aarch64
{% elif arch == 'arm' %}
            qemu-system-arm
{% elif arch == 'amd64' or arch == 'x86_64' %}
            qemu-system-x86_64
{% elif arch == 'hppa' %}
            qemu-system-hppa
{% elif arch == 'i386' %}
            qemu-system-i386
{% elif arch == 'mips' %}
            qemu-system-mips
{% elif arch == 'mipsel' %}
            qemu-system-mipsel
{% elif arch == 'mips64' %}
            qemu-system-mips64
{% elif arch == 'mips64el' %}
            qemu-system-mips64el
{% elif arch == 'nios2' %}
            qemu-system-nios2
{% elif arch == 'ppc' %}
            qemu-system-ppc
{% elif arch == 'ppc64' %}
            qemu-system-ppc64
{% elif arch == 'ppc64le' %}
            qemu-system-ppc64le
{% elif arch == 'riscv64' %}
            qemu-system-riscv64
{% elif arch == 'sparc' %}
            qemu-system-sparc
{% elif arch == 'sparc64' %}
            qemu-system-sparc64
{% else %}
{# binary comes from the qemu-system-misc package #}
            qemu-system-{{ arch }}
{% endif %}
{# end arch command #}
          # used by installers to relate to the empty target device
          boot_options:
{# start arch root #}
{% if arch == 'arm64' or arch == 'aarch64' %}
            {root: '{{ boot_root|default("/dev/vda2") }} rw rootwait', console: {{ boot_console|default('ttyAMA0 115200') }}, ip: dhcp, mem: 1024M}
{% elif arch == 'arm' %}
{% elif arch == 'amd64' %}
            {root: {{ boot_root|default('/dev/sda1') }},
             console: '{{ boot_console|default('ttyS0,115200') }}',
             boot_order: c}
{% else %}
            {root: {{ boot_root|default('/dev/sda1') }}, console: {{ boot_console|default('ttyS0,115200') }}}
{% endif %}
{# end arch root #}
          options:
{% block qemu_options %}
{# arch cpu #}
{% if arch == 'arm64' or arch == 'aarch64' %}
          - -cpu {{ cpu|default('cortex-a57') }}
          - -machine {{ machine|default('virt') }}
{% elif arch == 'arm' %}
          - -cpu {{ cpu|default('cortex-a15') }}
          - -machine {{ machine|default('virt') }}
{% elif arch == 'amd64' or arch == 'x86_64' %}
          - -cpu {{ cpu|default('qemu64') }}
          - -machine {{ machine|default('q35') }}
{% elif arch == 'hppa' %}
{% if cpu %}
          - -cpu {{ cpu }}
{% endif %}
          - -machine {{ machine|default('hppa') }}
{% elif arch == 'i386' %}
          - -cpu {{ cpu|default('qemu32') }}
          - -machine {{ machine|default('q35') }}
{% elif arch == 'm68k' %}
{% if cpu %}
          - -cpu {{ cpu }}
{% endif %}
          - -machine {{ machine|default('mcf5208evb') }}
{% elif arch == 'mips' %}
{% if cpu %}
          - -cpu {{ cpu }}
{% endif %}
          - -machine {{ machine|default('malta') }}
{% elif arch == 'mipsel' %}
{% if cpu %}
          - -cpu {{ cpu }}
{% endif %}
          - -machine {{ machine|default('malta') }}
{% elif arch == 'mips64' %}
{% if cpu %}
          - -cpu {{ cpu }}
{% endif %}
          - -machine {{ machine|default('malta') }}
{% elif arch == 'mips64el' %}
{% if cpu %}
          - -cpu {{ cpu }}
{% endif %}
          - -machine {{ machine|default('malta') }}
{% elif arch == 'nios2' %}
{% if cpu %}
          - -cpu {{ cpu }}
{% endif %}
          - -machine {{ machine|default('10m50-ghrd') }}
{% elif arch == 'ppc' %}
{% if cpu %}
          - -cpu {{ cpu }}
{% endif %}
          - -machine {{ machine|default('g3beige') }}
{% elif arch == 'ppc64' %}
{% if cpu %}
          - -cpu {{ cpu }}
{% endif %}
          - -machine {{ machine|default('pseries') }}
{% elif arch == 'ppc64le' %}
{% if cpu %}
          - -cpu {{ cpu }}
{% endif %}
          - -machine {{ machine|default('pseries') }}
{% elif arch == 'riscv64' %}
          - -cpu {{ cpu|default('rv64') }}
          - -machine {{ machine|default('virt') }}
{% elif arch == 's390x' %}
{% if cpu %}
          - -cpu {{ cpu|default('max') }}
{% endif %}
          - -machine {{ machine|default('s390-ccw-virtio') }}
{% elif arch == 'sh4' %}
{% if cpu %}
          - -cpu {{ cpu|default('max') }}
{% endif %}
          - -machine {{ machine|default('r2d') }}
{% elif arch == 'sparc' %}
{% if cpu %}
          - -cpu {{ cpu }}
{% endif %}
          - -machine {{ machine|default('SS-5') }}
{% elif arch == 'sparc64' %}
{% if cpu %}
          - -cpu {{ cpu }}
{% endif %}
          - -machine {{ machine|default('sun4u') }}
{% elif arch == 'xtensa' %}
{% if cpu %}
          - -cpu {{ cpu }}
{% endif %}
          - -machine {{ machine|default('sim') }}
{% endif %}
{% if arch == 'arm64' or arch == 'aarch64' or arch == 'arm' %}
{# arch cpu + vga #}
{% if vga %}
          - {{ vga }}
{% endif %}
{# arch cpu #}
{# arch cpu + serial #}
{% if serial %}
          - {{ serial }}
{% endif %}
{# arch cpu #}
{% else %}
{# not arch cpu #}
{% if not no_kvm %}
          - -cpu host
          - -enable-kvm
{% endif %}
{# end no_kvm #}
{% endif %}
{# end arch cpu #}
          - -nographic
{% if no_network is defined and no_network is sameas true %}
          - -nic none
{% else %}
          - -net nic,{{ model|default('model=virtio') }},macaddr={{ mac_addr|default('52:54:00:12:34:58') }} -net {{ netdevice|default('user') }}
{% endif %}
          - -m {{ memory|default(1024) }}
          - -monitor {{ monitor|default('none') }}
{# If you need to pass -soundhw in extra_options, then see doc/v2/qemu_options.rst for how to set the environment var QEMU_AUDIO_DRV=none #}
{% if extra_options %}
          extra: {{ extra_options }}
{% endif %}
{% endblock qemu_options -%}
{% endblock qemu_method %}
      qemu-nfs:
{{ self.qemu_method() }}
          append:
            console: {{ console_device|default('ttyAMA0') }}
            root: /dev/nfs
            nfsrootargs: {{ base_nfsroot_args }}
            ipargs: {{ base_ip_args }}
{% endblock body %}
