{% set part_list = [] -%}
{%- for i, slave in enumerate(slave_instance_list) %}
{%    set slave_reference = slave.get('slave_reference', '') %}
{%    set publish_section_title = 'publish-%s' % slave_reference %}
{%    do part_list.append(publish_section_title) %}
[{{ publish_section_title }}]
recipe = slapos.cookbook:publish.serialised
-slave-reference = {{ slave_reference }}
info = Your SIM card has been attached to service ${slap-configuration:instance-title}.
{%- endfor %}

[buildout]
parts =
  directory
  lte-gnb-request
  lte-mme-request
  check-cpu-temperature.py
  publish-connection-information
{% for part in part_list -%}
{{ '  %s' % part }}
{% endfor %}

extends = {{ monitor_template }}

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

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

[directory]
recipe = slapos.cookbook:mkdirectory
software = {{ buildout_directory }}
home = ${buildout:directory}
etc = ${:home}/etc
var = ${:home}/var
etc = ${:home}/etc
bin = ${:home}/bin
run = ${:var}/run
script = ${:etc}/run
service = ${:etc}/service
promise = ${:etc}/promise
log = ${:var}/log

[request-common-base]
recipe = slapos.cookbook:requestoptional.serialised
software-url = {{ slap_connection['software-release-url'] }}
server-url = {{ slap_connection['server-url'] }}
computer-id = {{ slap_connection['computer-id'] }}
partition-id = {{ slap_connection['partition-id'] }}
key-file = {{ slap_connection['key-file'] }}
cert-file = {{ slap_connection['cert-file'] }}

sla-computer_guid = {{ slap_connection['computer-id'] }}

config-monitor-password = ${monitor-htpasswd:passwd}
config-sub-instance = true

[lte-mme-request]
<= request-common-base
name = MME
software-type = mme
config-name = mme
{%- for key, value in slapparameter_dict.items() %}
config-{{ key }} = {{ dumps(value) }}
{% endfor %}
config-slave-list = {{ dumps(slave_instance_list) }}
return = monitor-base-url epc-ipv6

[lte-gnb-request]
<= request-common-base
name = gNB
software-type = gnb
config-name = gnb
{%- for key, value in slapparameter_dict.items() %}
config-{{ key }} = {{ dumps(value) }}
{% endfor %}
return = monitor-base-url

[monitor-base-url-dict]
lte-mme-request =  ${lte-mme-request:connection-monitor-base-url}
lte-gnb-request =  ${lte-gnb-request:connection-monitor-base-url}

[macro.promise]
<= monitor-promise-base
name = ${:_buildout_section_name_}

[check-cpu-temperature.py]
<= macro.promise
promise = check_cpu_temperature
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-frequency = {{ slapparameter_dict.get("promise_cpu_temperature_frequency", 5) }}
config-max-spot-temp = {{ slapparameter_dict.get("promise_cpu_max_spot_temp", 90) }}
config-max-avg-temp = {{ slapparameter_dict.get("promise_cpu_max_avg_temp", 80) }}
config-avg-temp-duration = {{ slapparameter_dict.get("promise_cpu_avg_temp_duration", 600) }}
config-avg-flag-file = ${directory:var}/promise_cpu_avg_flag_file

[publish-connection-information]
recipe = slapos.cookbook:publish.serialised
<= monitor-publish
epc-ipv6 =  ${lte-mme-request:connection-epc-ipv6}
epc-ipv4 =  {{ epc_ipv4 }}
