[buildout]
parts =
  directory
  ltelogs
  enb-config
  enb-service
  xamari-xlog-service
{% if slapparameter_dict.get('xlog_fluentbit_forward_host') %}
  xlog-fluentbit-service
{% endif %}
  amarisoft-stats-service
  amarisoft-rf-info-service
{% if ru == "lopcomm" %}
  lopcomm-firmware-dl
  lopcomm-rrh-stats-service
  lopcomm-rrh-supervision-service
  lopcomm-rrh-reset-info-service
{%  if slapparameter_dict.get("cron_schedule", None) %}
  lopcomm-rrh-reset-cron
{%  endif %}
  lopcomm-rrh-config-template
  lopcomm-rrh-software-template
  netconf-connection-promise
  firmware-update-promise
  rrh-netconf-socket-promise
  lopcomm-cu-config
  sshd-service
  sshd-add-authorized-key
  sshd-promise
  check-lopcomm-vswr.py
  check-lopcomm-pa-current.py
  check-lopcomm-pa-output-power.py
  check-lopcomm-lof.py
  check-lopcomm-rssi.py
  check-lopcomm-sync.py
  check-lopcomm-config-log.py
  check-lopcomm-stats-log.py
{% endif %}
{% if slapparameter_dict.get("dnsmasq", None) %}
  dnsmasq-service
{% endif %}
  check-sdr-busy.py
  check-baseband-latency.py
  check-amarisoft-stats-log.py
{% if not ru == "lopcomm"  %}
  check-rx-saturated.py
{% endif %}
  monitor-base
  publish-connection-information
{% set extra_part_list = [] %}

extends = {{ monitor_template }}

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

[monitor-httpd-conf-parameter]
httpd-include-file = {{ buildout_directory }}/etc/httpd-include-file.conf
port = ${monitor-instance-parameter:monitor-httpd-port}
url = https://[${monitor-instance-parameter:monitor-httpd-ipv6}]:${:port}

[monitor-instance-parameter]
monitor-httpd-port = ${monitor-address:port}

[monitor-address]
recipe = slapos.cookbook:free_port
minimum = 8035
maximum = 8055
ip = ${monitor-instance-parameter:monitor-httpd-ipv6}

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

configuration.com_ws_port = 9001
configuration.com_addr = 127.0.1.2
configuration.mme_addr = 127.0.1.100
configuration.gtp_addr = 127.0.1.1
configuration.default_lte_bandwidth = {{ default_lte_bandwidth }}
configuration.default_lte_inactivity_timer = {{ default_lte_inactivity_timer }}
configuration.default_n_antenna_dl = {{ default_n_antenna_dl }}
configuration.default_n_antenna_ul = {{ default_n_antenna_ul }}

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

[ltelogs]
recipe = slapos.recipe.template:jinja2
url = {{ ltelogs_template }}
output = ${directory:home}/ltelogs.sh
extensions = jinja2.ext.do
context =
  section directory directory

{% if slapparameter_dict.get("enb_config_link", None) %}
[enb-config-dl]
recipe = slapos.recipe.build:download
url = {{ slapparameter_dict.get("enb_config_link") }}
version = {{ slapparameter_dict.get("enb_config_version") }}
offline = false
{% endif %}

{% if slapparameter_dict.get("cu_config_link", None) %}
[cu-config-dl]
recipe = slapos.recipe.build:download
url = {{ slapparameter_dict.get("cu_config_link") }}
version = {{ slapparameter_dict.get("cu_config_version") }}
offline = false
{% endif %}


[enb-sh-wrapper]
recipe = slapos.recipe.template
output = ${directory:bin}/${:_buildout_section_name_}
enb-log = ${directory:log}/enb-output.log
inline =
  #!/bin/sh
{% if not slapparameter_dict.get("testing", False) %}
  sudo -n /opt/amarisoft/rm-tmp-lte;
  sudo -n /opt/amarisoft/init-sdr;
  sudo -n /opt/amarisoft/init-enb;
  (echo && echo && date "+[%Y/%m/%d %T.%N %Z] Starting eNB software..." && echo) >> ${:enb-log};
  tail -c 1M ${:enb-log} > ${:enb-log}.tmp;
  mv ${:enb-log}.tmp ${:enb-log};
  {{ enb }}/lteenb ${directory:etc}/enb.cfg >> ${:enb-log} 2>> ${:enb-log};
{% endif %}

[enb-service]
recipe = slapos.cookbook:wrapper
init = ${ltelogs:output} ${directory:log}/enb.log; sleep 2
command-line = ${enb-sh-wrapper:output}
wrapper-path = ${directory:service}/enb
mode = 0775
reserve-cpu = True
pidfile = ${directory:run}/enb.pid
hash-files =
  ${enb-config:output}
  ${enb-sh-wrapper:output}
environment =
  LD_LIBRARY_PATH={{ openssl_location }}/lib
  AMARISOFT_PATH=/opt/amarisoft/.amarisoft

{% if slapparameter_dict.get("dnsmasq", None) %}
[dnsmasq-service]
recipe = slapos.cookbook:wrapper
port = 5353
ip = ${slap-configuration:tun-ipv4-addr}
command-line = {{ dnsmasq_location }}/sbin/dnsmasq --conf-file={{ dnsmasq_config_path }} -x ${directory:run}/dnsmasq.pid --local-service --keep-in-foreground
wrapper-path = ${directory:service}/dnsmasq
mode = 0775
hash-files =
  {{ dnsmasq_config_path }}

#[dnsmasq-listen-promise]
#<= monitor-promise-base
#promise = check_socket_listening
#name = dnsmasq-port-listening.py
#config-host = ${dnsmasq-service:ip}
#config-port = ${dnsmasq-service:port}
{% endif %}

[xamari-xlog-script]
recipe = slapos.recipe.template
output = ${directory:bin}/${:_buildout_section_name_}
period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
stats_logspec = stats[samples,rf]/${:period}s
{%- if slapparameter_dict.get("enb_drb_stats_enabled", True) %}
drb_stats_logspec = x.drb_stats/${:period}s
{%- else %}
drb_stats_logspec =
{%- endif %}
rotatespec = 100MB.9
logspec = ${:stats_logspec} ${:drb_stats_logspec}
{%- if slapparameter_dict.get("websocket_password", "") %}
websock = ws://[${slap-configuration:ipv6-random}]:9001
{%- else %}
websock = ws://127.0.1.2:9001
{%- endif %}
xamari = {{ buildout_directory }}/bin/xamari
logfile = ${monitor-directory:public}/enb.xlog
inline =
  #!/bin/sh
  exec ${:xamari} xlog --rotate ${:rotatespec} ${:websock} ${:logfile} ${:logspec}

[xamari-xlog-service]
recipe = slapos.cookbook:wrapper
wrapper-path = ${directory:service}/${:_buildout_section_name_}
command-line = ${xamari-xlog-script:output}
hash-files = ${:command-line}

{% if slapparameter_dict.get('xlog_fluentbit_forward_host') %}
[xlog-fluentbit-config]
recipe = slapos.recipe.template
output = ${directory:etc}/${:_buildout_section_name_}.cfg
logfile = ${xamari-xlog-script:logfile}
forward-host = {{ slapparameter_dict.get('xlog_fluentbit_forward_host', '') }}
forward-port = {{ slapparameter_dict.get('xlog_fluentbit_forward_port', '') }}
forward-shared-key = {{ slapparameter_dict.get('xlog_fluentbit_forward_shared_key', '') }}
forward-self-hostname = {{ ors_id['ors-id'] }}
inline =
  [SERVICE]
      flush           5
  [INPUT]
      name            tail
      path            ${:logfile}
      Read_from_Head  True
  [OUTPUT]
      name            forward
      match           *
      Host            ${:forward-host}
{%- if slapparameter_dict.get('xlog_fluentbit_forward_port') %}
      Port            ${:forward-port}
{%- endif %}
      Shared_Key      ${:forward-shared-key}
      Self_Hostname   ${:forward-self-hostname}
      tls             on
      tls.verify      off

[xlog-fluentbit-service]
recipe  = slapos.cookbook:wrapper
fluentbit =  {{ fluent_bit_location }}/bin/fluent-bit
fluentbit-config = ${xlog-fluentbit-config:output}
command-line = ${:fluentbit} -c ${:fluentbit-config}
wrapper-path = ${directory:service}/${:_buildout_section_name_}
hash-files = ${:fluentbit-config}
{% endif %}

[amarisoft-stats-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/amarisoft-stats.json.log
context =
  section directory directory
  key slapparameter_dict slap-configuration:configuration
  key log_file :log-output
  raw stats_period {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
  raw testing {{ slapparameter_dict.get("testing", False) }}
  raw python_path {{ buildout_directory}}/bin/pythonwitheggs
mode = 0775
url = {{ amarisoft_stats_template }}
output = ${directory:bin}/amarisoft-stats.py

[amarisoft-rf-info-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/amarisoft-rf-info.json.log
context =
  section directory directory
  key slapparameter_dict slap-configuration:configuration
  key log_file :log-output
  raw stats_period {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
  raw testing {{ slapparameter_dict.get("testing", False) }}
  raw python_path {{ buildout_directory}}/bin/pythonwitheggs
mode = 0775
url = {{ amarisoft_rf_info_template }}
output = ${directory:bin}/amarisoft-rf-info.py

[lopcomm-rrh-stats-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/lopcomm-rrh-stats.log
json-log-output = ${directory:var}/log/lopcomm-rrh-stats.json.log
cfg-json-log-output = ${directory:var}/log/lopcomm-rrh-config.json.log
supervision-json-log-output = ${directory:var}/log/lopcomm-rrh-supervision.json.log
ncsession-json-log-output = ${directory:var}/log/lopcomm-rrh-ncsession.json.log
software-json-log-output = ${directory:var}/log/lopcomm-rrh-software.json.log
context =
  section directory directory
  section slap_configuration slap-configuration
  key slapparameter_dict slap-configuration:configuration
  key log_file :log-output
  key json_log_file :json-log-output
  key cfg_json_log_file :cfg-json-log-output
  key supervision_json_log_file :supervision-json-log-output
  key ncsession_json_log_file :ncsession-json-log-output
  key software_json_log_file :software-json-log-output
  raw testing {{ slapparameter_dict.get("testing", False) }}
  raw python_path {{ buildout_directory}}/bin/pythonwitheggs
  raw buildout_directory_path {{ buildout_directory }}
  import netaddr netaddr
mode = 0775
url = {{ lopcomm_rrh_stats_template }}
output = ${directory:bin}/lopcomm-rrh-stats.py

[lopcomm-cu-config]
<= config-base
{% if slapparameter_dict.get("cu_config_link", None) %}
url = ${enb-config-dl:target}
{% else %}
url = {{ cu_config_template }}
{% endif %}
output = ${directory:etc}/cu_config.xml

[lopcomm-rrh-config-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/lopcomm-rrh-config.log
context =
  section directory directory
  section slap_configuration slap-configuration
  key slapparameter_dict slap-configuration:configuration
  key log_file :log-output
  raw testing {{ slapparameter_dict.get("testing", False) }}
  raw python_path {{ buildout_directory}}/bin/pythonwitheggs
  raw buildout_directory_path {{ buildout_directory }}
  raw CreateProcessingEle_template {{ CreateProcessingEle_template }}
  key cu_config_template lopcomm-cu-config:output
  import netaddr netaddr
mode = 0775
url = {{ lopcomm_rrh_config_template }}
output = ${directory:script}/lopcomm-rrh-config.py

[lopcomm-rrh-software-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/lopcomm-rrh-software.log
software-reply-json-log-output = ${directory:var}/log/lopcomm-rrh-software-reply.json.log
remote-file-path = sftp://${user-info:pw-name}@[${slap-configuration:ipv6-random}]:${sshd-port:port}${lopcomm-firmware-dl:destination}
context =
  section directory directory
  section slap_configuration slap-configuration
  key slapparameter_dict slap-configuration:configuration
  key log_file :log-output
  key software_reply_json_log_file :software-reply-json-log-output
  key remote_file_path :remote-file-path
  raw testing {{ slapparameter_dict.get("testing", False) }}
  raw python_path {{ buildout_directory}}/bin/pythonwitheggs
  raw buildout_directory_path {{ buildout_directory }}
  raw etc_path ${directory:etc}
  raw firmware_name ${lopcomm-firmware-dl:filename}
  import netaddr netaddr
mode = 0775
url = {{ lopcomm_rrh_software_template }}
output = ${directory:script}/lopcomm-rrh-software.py

[lopcomm-rrh-supervision-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/lopcomm-rrh-supervision.log
supervision-reply-json-log-output = ${directory:var}/log/lopcomm-rrh-supervision-reply.json.log
context =
  section directory directory
  section slap_configuration slap-configuration
  key slapparameter_dict slap-configuration:configuration
  key log_file :log-output
  key supervision_reply_json_log_file :supervision-reply-json-log-output
  raw testing {{ slapparameter_dict.get("testing", False) }}
  raw python_path {{ buildout_directory}}/bin/pythonwitheggs
  raw buildout_directory_path {{ buildout_directory }}
  raw etc_path ${directory:etc}
  import netaddr netaddr
mode = 0775
url = {{ lopcomm_rrh_supervision_template }}
output = ${directory:bin}/lopcomm-rrh-supervision.py

[lopcomm-rrh-reset-info-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/lopcomm-rrh-reset-info.log
json-log-output = ${directory:var}/log/lopcomm-rrh-reset-info.json.log
context =
  section slap_configuration slap-configuration
  key log_file :log-output
  key json_log_file :json-log-output
  raw stats_period {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
  raw testing {{ slapparameter_dict.get("testing", False) }}
  raw python_path {{ buildout_directory}}/bin/pythonwitheggs
  import netaddr netaddr
mode = 0775
url = {{ lopcomm_rrh_reset_info_template }}
output = ${directory:bin}/lopcomm-rrh-reset-info.py

[lopcomm-rrh-reset-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/lopcomm-rrh-reset.log
json-log-output = ${directory:var}/log/lopcomm-rrh-reset.json.log
context =
  section slap_configuration slap-configuration
  key log_file :log-output
  raw python_path {{ buildout_directory}}/bin/pythonwitheggs
  raw buildout_directory_path {{ buildout_directory }}
  import netaddr netaddr
mode = 0775
url = {{ lopcomm_rrh_reset_template }}
output = ${directory:etc}/lopcomm-rrh-reset.py

[lopcomm-rrh-reset-cron]
recipe = slapos.cookbook:cron.d
cron-entries = ${cron:cron-entries}
name = rrh-resest
frequency = {{ slapparameter_dict.get("cron_schedule", "") }}
command = {{ buildout_directory}}/bin/pythonwitheggs ${lopcomm-rrh-reset-template:output}

[netconf-connection-promise]
<= monitor-promise-base
promise = check_command_execute
name = netconf-connection-promise.py
config-command = [ -f ${directory:etc}/is_netconf_connected ]

[firmware-update-promise]
<= monitor-promise-base
promise = check_command_execute
name = firmware-update-promise.py
config-command = [ -f ${directory:etc}/is_firmware_updated ]

[rrh-netconf-socket-promise]
<= monitor-promise-base
promise = check_socket_listening
name = rrh-netconf-socket-promise.py
config-host = ${slap-configuration:tap-ipv6-gateway}
config-port = 830

[amarisoft-stats-service]
recipe = slapos.cookbook:wrapper
command-line = ${amarisoft-stats-template:output}
wrapper-path = ${directory:service}/amarisoft-stats
mode = 0775
hash-files =
  ${amarisoft-stats-template:output}

[amarisoft-rf-info-service]
recipe = slapos.cookbook:wrapper
command-line = ${amarisoft-rf-info-template:output}
wrapper-path = ${directory:service}/amarisoft-rf-info
mode = 0775
hash-files =
  ${amarisoft-rf-info-template:output}

[lopcomm-rrh-stats-service]
recipe = slapos.cookbook:wrapper
command-line = ${lopcomm-rrh-stats-template:output}
wrapper-path = ${directory:service}/lopcomm-rrh-stats
mode = 0775
hash-files =
  ${lopcomm-rrh-stats-template:output}

[lopcomm-rrh-supervision-service]
recipe = slapos.cookbook:wrapper
command-line = ${lopcomm-rrh-supervision-template:output}
wrapper-path = ${directory:service}/lopcomm-rrh-supervision
mode = 0775
hash-files =
  ${lopcomm-rrh-supervision-template:output}

[lopcomm-rrh-reset-info-service]
recipe = slapos.cookbook:wrapper
command-line = ${lopcomm-rrh-reset-info-template:output}
wrapper-path = ${directory:service}/lopcomm-rrh-reset-info
mode = 0775
hash-files =
  ${lopcomm-rrh-reset-info-template:output}

[lopcomm-firmware-dl]
recipe = slapos.recipe.build:download
url = https://lab.nexedi.com/nexedi/ors-utils/raw/master/lopcomm-firmware/${:filename}
filename = PR.PRM61C70V1004.006.tar.gz
md5sum = 5139019aae77c2f3178a99915f1c57dc
destination = ${directory:etc}/${:filename}
offline = false

[user-info]
recipe = slapos.cookbook:userinfo

# Deploy openssh-server
[sshd-port]
recipe = slapos.cookbook:free_port
minimum = 22222
maximum = 22231
ip = ${slap-configuration:ipv6-random}

[sshd-config]
recipe = slapos.recipe.template:jinja2
output = ${directory:etc}/sshd.conf
path_pid = ${directory:run}/sshd.pid
inline =
  PidFile ${:path_pid}
  Port ${sshd-port:port}
  ListenAddress ${slap-configuration:ipv6-random}
  Protocol 2
  HostKey ${sshd-ssh-host-rsa-key:output}
  HostKey ${sshd-ssh-host-ecdsa-key:output}
  PasswordAuthentication no
  PubkeyAuthentication yes
  HostKeyAlgorithms ssh-rsa,ssh-dss,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp521
  AuthorizedKeysFile ${buildout:directory}/.ssh/authorized_keys
  Subsystem sftp {{ openssh_location }}/libexec/sftp-server

[sshd-service]
recipe = slapos.cookbook:wrapper
command-line = {{ openssh_location }}/sbin/sshd -D -e -f ${sshd-config:output}
wrapper-path = ${directory:service}/sshd
hash-files = ${sshd-config:output}
environment =
  HOME=${directory:home}

[sshd-add-authorized-key]
recipe = slapos.cookbook:dropbear.add_authorized_key
home = ${buildout:directory}
key = {{ slapparameter_dict.get("user-authorized-key", '') }}

[sshd-ssh-keygen-base]
recipe = plone.recipe.command
output = ${directory:etc}/${:_buildout_section_name_}
command = {{ openssh_output_keygen }} -f ${:output} -N '' ${:extra-args}

[sshd-ssh-host-rsa-key]
<=sshd-ssh-keygen-base
extra-args=-t rsa
[sshd-ssh-host-ecdsa-key]
<=sshd-ssh-keygen-base
extra-args=-t ecdsa -b 521

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

[config-base]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
extra-context =
context =
  section directory directory
  section slap_configuration slap-configuration
  key slapparameter_dict slap-configuration:configuration
  key gtp_addr_v6 slap-configuration:ipv6-random
  raw gtp_addr_v4 {{ lan_ipv4 }}
  raw one_watt {{ ors_version['one-watt'] }}
  raw tx_gain {{ ors_version['current-tx-gain'] }}
  raw rx_gain {{ ors_version['current-rx-gain'] }}
  raw earfcn  {{ ors_version['current-earfcn'] }}
  raw software_name {{ software_name }}
  raw rf_mode {{ rf_mode }}
  raw trx {{ trx }}
  raw bbu {{ bbu }}
  raw ru {{ ru }}
  import  netaddr netaddr
  ${:extra-context}

[sib-config]
<= config-base
url = {{ sib23_template }}
output = ${directory:etc}/sib23.cfg

[enb-config]
<= config-base
{% if slapparameter_dict.get("enb_config_link", None) %}
url = ${enb-config-dl:target}
{% else %}
url = {{ enb_template }}
{% endif %}
output = ${directory:etc}/enb.cfg
extra-context =
    key sib23_file sib-config:output

[publish-connection-information]
<= monitor-publish
recipe = slapos.cookbook:publish.serialised
{%- if slapparameter_dict.get("websocket_password", "") %}
websocket_url = ws://[${slap-configuration:ipv6-random}]:9001
{%- endif %}
enb-ipv6 = ${slap-configuration:ipv6-random}
enb-ipv4 = {{ lan_ipv4 }}
{% if bbu == "ors" %}
ors-version = {{ ors_version['ors-version'] }}
frequency-range-rating = {{ ors_version['range'] }}
current-tx-power-estimate = {{ ors_version['power-estimate'] }}
current-tx-gain = {{ ors_version['current-tx-gain'] }}
current-rx-gain = {{ ors_version['current-rx-gain'] }}
{% endif %}
current-earfcn  = {{ ors_version['current-earfcn'] }}
amarisoft-version = {{ lte_version }}
license-expiration = {{ lte_expiration }}
monitor-gadget-url = ${:monitor-base-url}/gadget/software.cfg.html
{% if ru == "lopcomm" %}
ssh-command = ssh ${user-info:pw-name}@${slap-configuration:ipv6-random} -p ${sshd-port:port}
ssh-url = ssh://${user-info:pw-name}@[${slap-configuration:ipv6-random}]:${sshd-port:port}
ru-firmware = ${lopcomm-firmware-dl:filename}
ru-ipv6 = ${slap-configuration:tap-ipv6-gateway}
{% endif %}

[monitor-instance-parameter]
{% if slapparameter_dict.get("name", None) %}
monitor-title = {{ slapparameter_dict['name'] | string }}
{% endif %}
{% if slapparameter_dict.get("monitor-password", None) %}
password = {{ slapparameter_dict['monitor-password'] | string }}
{% endif %}

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

[check-sdr-busy.py]
<= macro.promise
promise = check_sdr_busy
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-sdr = {{ sdr }}
config-sdr_dev  = 0
config-dma_chan = 0

[check-baseband-latency.py]
<= macro.promise
promise = check_baseband_latency
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-amarisoft-stats-log = ${amarisoft-stats-template:log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
config-min-txrx-delay = {{ slapparameter_dict.get("min_txrx_delay", 5) }}

[check-amarisoft-stats-log.py]
<= macro.promise
promise = check_amarisoft_stats_log
output = ${directory:plugins}/check-amarisoft-stats-log.py
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-amarisoft-stats-log = ${amarisoft-stats-template:log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}

[check-lopcomm-vswr.py]
<= macro.promise
promise = check_lopcomm_vswr
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-netconf-log = ${lopcomm-rrh-stats-template:json-log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}

[check-lopcomm-rssi.py]
<= macro.promise
promise = check_lopcomm_rssi
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-netconf-log = ${lopcomm-rrh-stats-template:json-log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}

[check-lopcomm-pa-current.py]
<= macro.promise
promise = check_lopcomm_pa_current
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-netconf-log = ${lopcomm-rrh-stats-template:json-log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}

[check-lopcomm-pa-output-power.py]
<= macro.promise
promise = check_lopcomm_pa_output_power
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-netconf-log = ${lopcomm-rrh-stats-template:json-log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}

[check-lopcomm-sync.py]
<= macro.promise
promise = check_lopcomm_sync
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-netconf-log = ${lopcomm-rrh-stats-template:json-log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}

[check-lopcomm-lof.py]
<= macro.promise
promise = check_lopcomm_lof
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-netconf-log = ${lopcomm-rrh-stats-template:json-log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}

[check-lopcomm-stats-log.py]
<= macro.promise
promise = check_lopcomm_stats_log
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-stats-log = ${lopcomm-rrh-stats-template:log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}

[check-lopcomm-config-log.py]
<= macro.promise
promise = check_lopcomm_config_log
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-config-log = ${lopcomm-rrh-config-template:log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}

{%  if ru == "lopcomm" %}
{%-   set cell_list = slapparameter_dict.get('cell_list', {'default': {}}) %}
{%-   for i, k in enumerate(cell_list) %}
{%-     set sfp_port = cell_list[k].get('cpri_port_number', i) %}
{%-     do extra_part_list.append('SFP%s-cpri-lock.py' % sfp_port) %}
[SFP{{sfp_port}}-cpri-lock.py]
<= macro.promise
promise = check_cpri_lock
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-sdr_dev  = {{ slapparameter_dict.get('sdr_number', 0) }}
config-sfp_port = {{ sfp_port }}
config-amarisoft-rf-info-log = ${amarisoft-rf-info-template:log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
{%-  endfor %}
{% endif %}

[check-rx-saturated.py]
<= macro.promise
promise = check_rx_saturated
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-rf-rx-chan-list = {{ list(range(0, int(slapparameter_dict.get('n_antenna_ul', default_n_antenna_ul)))) }}
config-amarisoft-stats-log = ${amarisoft-stats-template:log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
config-max-rx-sample-db = {{ slapparameter_dict.get("max_rx_sample_db", 0) }}

[buildout]
parts +=
{%- for part in extra_part_list %}
    {{ part }}
{%- endfor %}
