{%- if slap_software_type == software_type %}

[jinja2-template-base]
recipe = slapos.recipe.template:jinja2
rendered = ${buildout:directory}/${:filename}
extra-context =
context =
    import json_module json
    ${:extra-context}

[slave-test-configuration]
<=jinja2-template-base
template = {{ template_json_edgetest_test }}
filename = srv/monitor/private/test.json
extensions = jinja2.ext.do 
extra-context = 
  section slave_information slap-configuration

{% set part_list = [] -%}
# Publish information for each slave
{%- set edgebot_software_type = 'edgebot' %}
{%- set edgebot_quantity = slapparameter_dict.pop('edgebot-quantity', '1') | int %}
{%- set edgebot_list = [] %}
{%- set edgebot_section_list = [] %}
{%- set slave_list_name = 'extra_slave_instance_list' %}
{%- set request_dict = {} %}
{%- set namebase = "edgebot" %}
{%- set authorized_slave_list = [] %}
{%- set monitor_base_url_dict = {} -%}
{%- for slave in sorted(slave_instance_list) %}
{%-   do authorized_slave_list.append(slave) %}
{%- endfor %}
{%- set monitor_base_port = int(slap_configuration['configuration.monitor-base-port']) %}
{%- for i in range(1, edgebot_quantity + 1) %}
{%-   set edgebot_name = "%s-%s" % (namebase, i) %}
{%-   set request_section_title = 'request-%s' % edgebot_name %}
{%-   do edgebot_list.append(edgebot_name) %}
{%-   do edgebot_section_list.append(request_section_title) %}
{%-   do part_list.append(request_section_title) %}
{%-   do request_dict.__setitem__(request_section_title,
                                  {
                                  'config': {'monitor-httpd-port': monitor_base_port + i},
                                  'name': edgebot_name,
                                  'sla': {},
                                  'state': 'started', 
                                  }) %}
{%- endfor %}

[replicate]
<= slap-connection
recipe = slapos.cookbook:request.serialised
config-monitor-cors-domains = {{ slapparameter_dict.get('monitor-cors-domains', 'monitor.app.officejs.com') }}
config-monitor-username = ${monitor-instance-parameter:username}
config-monitor-password = ${monitor-htpasswd:passwd}
software-url = ${slap-connection:software-release-url}
software-type = {{edgebot_software_type}}
return = monitor-base-url

{% for section, edgebot_request in request_dict.iteritems() %}
[{{section}}]
<= replicate
name = {{ edgebot_request.get('name') }}
{%-   if edgebot_request.get('state') %}
state = {{ edgebot_request.get('state') }}
{%-   endif%}
{%-   set slave_configuration_dict = slapparameter_dict %}
{%-   do slave_configuration_dict.update(edgebot_request.get('config')) %}
{%-   do slave_configuration_dict.__setitem__(slave_list_name, json_module.dumps(authorized_slave_list)) %}
{%-   for config_key, config_value in slave_configuration_dict.iteritems() %}
config-{{ config_key }} = {{ dumps(config_value) }}
{%   endfor -%}
{%-   if edgebot_request.get('sla') %}
{%-     for parameter, value in edgebot_request.get('sla').iteritems() %}
sla-{{ parameter }} = {{ value }}
{%-     endfor %}
{%-   else %}
# As no SLA was provided, by default it is requested on the same computer
sla-computer_guid = ${slap-connection:computer-id}
{%   endif %}
{%-  do monitor_base_url_dict.__setitem__(section, '${' ~ section ~ ':connection-monitor-base-url}') -%}
{%- endfor %}
{%- set directory_list = [] -%}
{%- for slave_instance in slave_instance_list -%}
{%-   set publish_section_title = 'publish-%s' % slave_instance.get('slave_reference')  -%}
{%-   do part_list.append(publish_section_title) %}
[{{ publish_section_title }}]
recipe = slapos.cookbook:publish
-slave-reference = {{ slave_instance.get('slave_reference') }}
{% endfor %}

[monitor-conf-parameters]
monitor-title = Monitor
password = ${monitor-htpasswd:passwd}

[monitor-base-url-dict]
{% for key, value in monitor_base_url_dict.items() -%}
{{ key }} = {{ value }}
{% endfor %}

[buildout]
extends = {{ instance_base_monitor }}
parts +=
  slave-test-configuration
{% for part in part_list %}
{{ '  %s' % part }}
{%- endfor %}
{%- endif %}