[buildout]
parts =
  switch-softwaretype

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

[switch-softwaretype]
recipe = slapos.cookbook:switch-softwaretype
default = dynamic-template-fluentd:output
RootSoftwareInstance = $${:default}

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

[slap-configuration]
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}

[dynamic-template-fluentd]
recipe = slapos.recipe.template:jinja2
url = ${template-fluentd:output}
output = $${buildout:directory}/instance-fluentd.cfg
extensions = jinja2.ext.do
context =
  key fluentd_agent_conf fluentd-agent-conf:output
  key port_list fluentd-conf:port-list
  section directory directory

[fluentd-conf]
recipe = slapos.recipe.build
slapparameter-dict = $${slap-configuration:configuration}
init =
  import re
  options['text'] = options['slapparameter-dict'].get('conf_text') or ' '
  options['port-list'] = re.findall(r'<source>.*port (\d+).*<\/source>', options['text'], re.DOTALL)

[fluentd-agent-conf]
recipe  = slapos.recipe.template
inline = $${fluentd-conf:text}
output = $${directory:etc}/fluentd-agent.conf
