[buildout]

eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }}
offline = true

parts += 
  kvm-disk-image-corruption-promise

# Here, we don't need KVM to run to import data, so we don't
# even extend the kvm instance profile.
extends = 
  {{ pbsready_import_template }}

[resilient-publish-connection-parameter]
monitor-base-url = ${monitor-publish-parameters:monitor-base-url}
monitor-url = ${monitor-publish-parameters:monitor-url}
monitor-user = ${monitor-publish-parameters:monitor-user}
monitor-password = ${monitor-publish-parameters:monitor-password}

[monitor-instance-parameter]
monitor-httpd-port = 8276
monitor-title = {{ slapparameter_dict.get('name', 'Kvm Resilient clone') }}
cors-domains = {{ slapparameter_dict.get('monitor-cors-domains', '') }}
{%   if slapparameter_dict.get('monitor-username', '') -%}
username = {{ slapparameter_dict['monitor-username'] }}
{%   endif -%}
{%   if slapparameter_dict.get('monitor-password', '') -%}
password = {{ slapparameter_dict['monitor-password'] }}
{%   endif -%}
instance-configuration =
  raw takeover-url ${resilient-publish-connection-parameter:takeover-url}
  raw takeover-password ${resilient-publish-connection-parameter:takeover-password}

[directory]
recipe = slapos.cookbook:mkdirectory
etc = ${buildout:directory}/etc
bin = ${buildout:directory}/bin
srv = ${buildout:directory}/srv
var = ${buildout:directory}/var
log = ${:var}/log
scripts = ${:etc}/run
services = ${:etc}/service
novnc-conf = ${:etc}/novnc
run = ${:var}/run
ca-dir = ${:srv}/ssl
cron-entries = ${:etc}/cron.d
crontabs = ${:etc}/crontabs
cronstamps = ${:etc}/cronstamps

[importer]
recipe = slapos.recipe.template:jinja2
template = {{ template_kvm_import }}
rendered = ${directory:bin}/${slap-parameter:namebase}-importer
mode = 0700
# Resilient stack wants a "wrapper" parameter
wrapper = ${:rendered}
context =
    section directory directory
    raw zcat_binary {{ zcat_binary }}
    raw gzip_binary {{ gzip_binary }}

backup-disk-path = ${directory:backup}/virtual.qcow2

[kvm-disk-image-corruption-bin]
recipe = collective.recipe.template
input = inline:#!/bin/sh
  QEMU_IMAGE="${directory:srv}/virtual.qcow2"
  if [ ! -s "$QEMU_IMAGE" ]; then
    exit 0
  fi
  {{ qemu_location }}/bin/qemu-img check $QEMU_IMAGE
  RETURN_CODE=$?
  if [ $RETURN_CODE -eq 0 ] || [ $RETURN_CODE -eq 3 ]; then
    exit 0
  else
    exit 1
  fi
output = ${directory:bin}/kvm-disk-image-corruption
mode = 700

[kvm-disk-image-corruption-promise]
# Check that disk image is not corrupted
<= monitor-promise-base
module = check_command_execute
name = kvm-disk-image-corruption.py
config-command = ${kvm-disk-image-corruption-bin:output}
