[buildout]
parts =
  switch_softwaretype

eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}

extends = ${template-resilient-templates:output}

[switch_softwaretype]
recipe = slapos.cookbook:switch-softwaretype
default = $${:kvm}
kvm-cluster = dynamic-template-kvm-cluster:output
kvm = dynamic-template-kvm:output

kvm-resilient = dynamic-template-kvm-resilient:output
kvm-import = dynamic-template-kvm-import:output
kvm-export = dynamic-template-kvm-export:output

frozen = instance-frozen:output
pull-backup = template-pull-backup:output

# XXX - If this configuration is not generated by slapgrid, use empty values
[storage-configuration]
storage-home =

[network-information]
global-ipv4-network =

[slap-configuration]
recipe = slapos.cookbook:slapconfiguration.serialised
computer = $${slap-connection:computer-id}
partition = $${slap-connection:partition-id}
url = $${slap-connection:server-url}
key = $${slap-connection:key-file}
cert = $${slap-connection:cert-file}
storage-home = $${storage-configuration:storage-home}

[jinja2-template-base]
recipe = slapos.recipe.template:jinja2
output = $${buildout:directory}/$${:filename}
extensions = jinja2.ext.do
extra-context =
context =
  key develop_eggs_directory buildout:develop-eggs-directory
  key eggs_directory buildout:eggs-directory
  key ipv4 slap-configuration:ipv4
  key ipv6 slap-configuration:ipv6
  key global_ipv4_prefix network-information:global-ipv4-network
  key storage_dict slap-configuration:storage-dict
  key slapparameter_dict slap-configuration:configuration
  key computer_id slap-configuration:computer
  raw openssl_executable_location ${openssl:location}/bin/openssl
  $${:extra-context}

[dynamic-template-kvm-cluster-parameters]

[dynamic-template-kvm-cluster]
<= jinja2-template-base
url = ${template-kvm-cluster:location}/instance-kvm-cluster.cfg.jinja2.in
filename = template-kvm-cluster.cfg
extra-context =
  section parameter_dict dynamic-template-kvm-cluster-parameters
  raw logrotate_cfg ${template-logrotate-base:output}
  raw template_content ${template-content:target}
  raw template_httpd_cfg ${template-httpd:output}
  raw template_monitor ${monitor2-template:output}

[dynamic-template-kvm]
<= jinja2-template-base
url = ${template-kvm:location}/instance-kvm.cfg.jinja2
filename = template-kvm.cfg
extra-context =
  section slap_configuration slap-configuration
  raw ansible_promise_tpl ${template-ansible-promise:target}
  raw curl_executable_location ${curl:location}/bin/curl
  raw dash_executable_location ${dash:location}/bin/dash
  raw dnsresolver_executable ${buildout:bin-directory}/dnsresolver
  raw dcron_executable_location ${dcron:location}/sbin/crond
  raw boot_image_select_source_config ${boot-image-select-source-config:target}
  raw whitelist_domains_default ${whitelist-domains-default:target}
  raw whitelist_firewall_download_controller ${whitelist-firewall-download-controller:output}
  raw image_download_controller ${image-download-controller:output}
  raw image_download_config_creator ${image-download-config-creator:output}
  raw logrotate_cfg ${template-logrotate-base:output}
  raw novnc_location ${noVNC:location}
  raw netcat_bin ${netcat:location}/bin/netcat
  raw nginx_executable ${nginx-output:nginx}
  raw nginx_mime ${nginx-output:mime}
  raw python_executable ${buildout:executable}
  raw python_eggs_executable ${buildout:bin-directory}/${python-with-eggs:interpreter}
  raw qemu_executable_location ${qemu:location}/bin/qemu-system-x86_64
  raw qemu_img_executable_location ${qemu:location}/bin/qemu-img
  raw qemu_start_promise_tpl ${template-qemu-ready:target}
  raw sixtunnel_executable_location ${6tunnel:location}/bin/6tunnel
  raw template_httpd_cfg ${template-httpd:output}
  raw template_content ${template-content:target}
  raw template_kvm_controller_run ${template-kvm-controller:target}
  raw template_kvm_run ${template-kvm-run:target}
  raw template_monitor ${monitor2-template:output}
  raw template_nginx ${template-nginx:target}
  raw websockify_executable_location ${buildout:directory}/bin/websockify
  raw wipe_disk_wrapper ${buildout:directory}/bin/securedelete
template-parts-destination = ${template-parts:target}
template-replicated-destination = ${template-replicated:target}
import-list = file parts :template-parts-destination
              file replicated :template-replicated-destination

[dynamic-template-kvm-resilient]
recipe = slapos.recipe.template:jinja2
url = ${template-kvm-resilient:location}/instance-kvm-resilient.cfg.jinja2
output = $${buildout:directory}/template-kvm-resilient.cfg
extensions = jinja2.ext.do
context =
    key develop_eggs_directory buildout:develop-eggs-directory
    key eggs_directory buildout:eggs-directory
    key slapparameter_dict slap-configuration:configuration
    raw curl_executable_location ${curl:location}/bin/curl
    raw template_monitor ${monitor2-template:output}
template-parts-destination = ${template-parts:target}
template-replicated-destination = ${template-replicated:target}
import-list = file parts :template-parts-destination
              file replicated :template-replicated-destination

[qmpbackup-binary]
recipe = slapos.cookbook:wrapper
environment =
  PATH=${qemu:location}/bin
  NO_COLOR=true
wrapper-path =
  $${buildout:bin-directory}/qmpbackup
command-line =
  ${buildout:bin-directory}/qmpbackup

[dynamic-template-kvm-export]
recipe = slapos.recipe.template:jinja2
url = ${template-kvm-export:location}/instance-kvm-export.cfg.jinja2
output = $${buildout:directory}/template-kvm-export.cfg
extensions = jinja2.ext.do
context =
    key develop_eggs_directory buildout:develop-eggs-directory
    key eggs_directory buildout:eggs-directory
    raw kvm_template $${dynamic-template-kvm:output}
    raw template_kvm_export ${template-kvm-export-script:target}
    key pbsready_export_template template-pbsready-export:output
    key slapparameter_dict slap-configuration:configuration
    key qmpbackup qmpbackup-binary:wrapper-path
    raw check_backup_directory ${check-backup-directory.sh:output}

[qmprestore-binary]
recipe = slapos.cookbook:wrapper
environment =
  PATH=${qemu:location}/bin
  NO_COLOR=true
wrapper-path =
  $${buildout:bin-directory}/qmprestore
command-line =
  ${buildout:bin-directory}/qmprestore

[dynamic-template-kvm-import]
recipe = slapos.recipe.template:jinja2
url = ${template-kvm-import:location}/instance-kvm-import.cfg.jinja2.in
output = $${buildout:directory}/template-kvm-import.cfg
extensions = jinja2.ext.do
context =
    key develop_eggs_directory buildout:develop-eggs-directory
    key eggs_directory buildout:eggs-directory
    raw qemu_location ${qemu:location}
    raw template_kvm_import ${template-kvm-import-script:target}
    key pbsready_import_template template-pbsready-import:output
    key slapparameter_dict slap-configuration:configuration
    key qmprestore qmprestore-binary:wrapper-path
