[buildout]
parts =
  dnsmasq-service
  dnsmasq-promise-v6
  dnsmasq-promise-v4
  publish-connection-parameter

eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
extends = ${monitor2-template:output}

[directory]
recipe = slapos.cookbook:mkdirectory
home = $${buildout:directory}
etc = $${:home}/etc/
var = $${:home}/var/
run = $${:var}/run/
bin = $${:home}/bin/
services = $${:etc}/service/

[instance-parameter]
recipe = slapos.cookbook:slapconfiguration
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}

[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}

[publish-connection-parameter]
recipe = slapos.cookbook:publish.serialised
dnsresolver-url-v6 = dns://[$${slap-configuration:ipv6-random}]:$${dnsmasq-service:port}
dnsresolver-url-v4 = dns://[$${slap-configuration:ipv4-random}]:$${dnsmasq-service:port}

[dnsmasq-config]
recipe = slapos.recipe.template:jinja2
output = $${directory:etc}/dnsmasq.conf
port = 5353
context =
  key configuration slap-configuration:configuration
inline =
  port=$${:port}
  listen-address=$${slap-configuration:ipv6-random}
  listen-address=$${slap-configuration:ipv4-random}
  {%- for nameserver in configuration['nameserver-list'] %}
  server={{ nameserver }}
  {%- endfor %}
  cache-size={{ configuration.get('cache-size', 5000) }}
  bind-interfaces
  no-resolv
  keep-in-foreground

[dnsmasq-service]
recipe = slapos.cookbook:wrapper
command-line = ${dnsmasq-output:dnsmasq} -C $${dnsmasq-config:output}
hash-existing-files = $${buildout:directory}/buildout.cfg
hash-files = $${dnsmasq-config:output}
wrapper-path = $${directory:services}/dnsmasq
port = $${dnsmasq-config:port}

[dnsmasq-promise-v6]
<= monitor-promise-base
promise = check_socket_listening
name = dnsmasq-v6.py
config-host = $${slap-configuration:ipv6-random}
config-port = $${dnsmasq-service:port}

[dnsmasq-promise-v4]
<= dnsmasq-promise-v6
name = dnsmasq-v4.py
config-host = $${slap-configuration:ipv4-random}
