apiVersion: v1
kind: ConfigMap
metadata:
  namespace: {{ .Release.Namespace }}
  name: {{ .Release.Name }}
data:
  config.yaml: |
    "/Runner":
      # The directory used to store data files. Defaults to (depending on 
      # values available):
      #  * $XDG_DATA_HOME/vmrunner/${vm.name}
      #  * $HOME/.local/share/vmrunner/${vm.name}
      #  * ./${vm.name}
      "dataDir": "/var/local/vm-data"
      
      # The directory used to store runtime files. Defaults to (depending on 
      # values available):
      #  * $XDG_RUNTIME_DIR/vmrunner/${vm.name}
      #  * /tmp/${USER}/vmrunner/${vm.name}
      #  * /tmp/vmrunner/${vm.name}
      # "runtimeDir": "$XDG_RUNTIME_DIR/vmrunner/${vm.name}"
      
      # The template to use. Resolved relative to /usr/share/vmrunner/templates.
      # "template": "Standard-VM-latest.ftl.yaml"
    
      # The template is copied to the data diretory when the VM starts for
      # the first time. Subsequent starts use the copy unless this option is set.
      "updateTemplate": true
    
      # Define the VM (required)
      "vm":
        # The VM's name (required)
        "name": "{{ .Release.Name }}"
        
        # The machine's uuid. If none is specified, a uuid is generated
        # and stored in the data directory. If the uuid is important
        # (e.g. because licenses depend on it) it is recommaned to specify
        # it here explicitly or to carefully backup the data directory.
        {{- if hasKey .Values.vm "machineUuid" }}
        "uuid": "{{ .Values.vm.machineUuid }}"
        {{- end }}

        # Whether to provide a software TPM (defaults to false)
        "useTpm": {{ .Values.vm.useTpm }}
        
        # How to boot (see https://github.com/mnlipp/VM-Operator/blob/main/org.jdrupes.vmoperator.runner.qemu/resources/org/jdrupes/vmoperator/runner/qemu/defaults.yaml):
        #  * bios
        #  * uefi[-4m]
        #  * secure[-4m]
        {{- if and (hasKey .Values.vm "efiBoot") (not .Values.vm.efiBoot) }}
        "firmware": "bios"
        {{- else }}
        "firmware": "{{ .Values.vm.firmware }}"
        {{- end }}
        
        # When terminating, a graceful powerdown is attempted. If it
        # doesn't succeed within the given timeout (seconds) SIGTERM
        # is sent to Qemu.
        "powerdownTimeout": "{{ .Values.vm.powerdownTimeout }}"
        
        # RAM settings
        "maximumRam": "{{ .Values.vm.maximumMemory }}"
        "currentRam": "{{ .Values.vm.currentMemory }}"
        
        # CPU settings
        "cpuModel": "{{ .Values.vm.cpuModel }}"
        # Setting maximumCpus to 1 omits the "-smp" options. The defaults (0)
        # cause the corresponding property to be omitted from the "-smp" option.
        # If currentCpus is greater than maximumCpus, the latter is adjusted.
        "maximumCpus": {{ .Values.vm.maximumCpus }}
        "currentCpus": {{ .Values.vm.currentCpus }}
        # "cpuSockets": 0
        # "diesPerSocket": 0
        # "coresPerSocket": 0
        # "threadsPerCore": 0
        # "accelertor": "kvm"
        
        # RTC settings.
        "rtcBase": "{{ .Values.vm.rtcBase }}"
        # "rtcClock": "rt"
        
        # Network settings
        # Supported types are "tap" and "user" (for debugging). Type "user"
        # supports only the property "net".
        # "network":
        # - "type": "tap"
        #   "bridge": "br0"
        #   "device": "virtio-net"
        #   "mac": (undefined)
        "network":
        {{- range $index, $network := .Values.vm.networks }}
        {{- if hasKey $network "bridge" }}
        - "type": "tap"
        {{- if hasKey $network.bridge "name" }}
          "bridge": "{{ $network.bridge.name }}"
        {{- end }}
        {{- if hasKey $network.bridge "mac" }}
          "mac": "{{ $network.bridge.mac }}"
        {{- end }}
        {{- end }}
        {{- end }}
    
        # There are no default drives. The supported types are "ide-cd"
        # and "raw". All types support a "bootindex" property.
        # Type "raw" can have a property "file" (if backed by a file on
        # the host) or a property "device" (if backed by a device).    
        # "drives":
        # - "type": "ide-cd"
        #   "bootindex": (undefined)
        #   "file": (undefined)
        "drives":
        {{- range $index, $disk := .Values.vm.disks }}
        - "type": "raw"
          "device": "/dev/disk-{{ $index }}"
        {{- end }}

        "display":
          "spice":
            "port": {{ .Values.vm.spicePort }}
            {{- if hasKey .Values.vm "spiceTicket" }}
            "ticket": "{{ .Values.vm.spiceTicket }}"
            {{- end }}
            {{- if hasKey .Values.vm "streamingVideo" }}
            "streamingVideo": "{{ .Values.vm.streamingVideo }}"
            {{- end }}
            # "usbRedirects": 2

  logging.properties: |
    handlers=java.util.logging.ConsoleHandler
    
    #org.jgrapes.level=FINE
    #org.jgrapes.core.handlerTracking.level=FINER
    
    org.jdrupes.vmoperator.runner.qemu.level=FINE
    
    java.util.logging.ConsoleHandler.level=ALL
    java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
    java.util.logging.SimpleFormatter.format=%1$tb %1$td %1$tT %4$s %5$s%6$s%n
    