[buildout]
parts =
  switch-softwaretype

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

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

[jinja2-template-base]
recipe = slapos.recipe.template:jinja2
rendered = $${buildout:directory}/$${:filename}
extra-context =
context =
    import json_module json
    key eggs_directory buildout:eggs-directory
    key develop_eggs_directory buildout:develop-eggs-directory
    raw buildout_directory ${buildout:directory}
    section slap_connection slap-connection
    key slapparameter_dict slap-configuration:configuration
    $${:extra-context}

[switch-softwaretype]
recipe = slapos.cookbook:switch-softwaretype
enb-epc = dynamic-template-lte-enb-epc:rendered
gnb-epc = dynamic-template-lte-gnb-epc:rendered
enb = dynamic-template-lte-enb:rendered
gnb = dynamic-template-lte-gnb:rendered
epc = dynamic-template-lte-epc:rendered
RootSoftwareInstance = $${:enb-epc}

[local-ipv4-address]
recipe = slapos.recipe.build
init = 
  import socket
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  try:
      s.connect(('1.1.1.1', 1))
      ip = s.getsockname()[0]
  except Exception:
      ip = '127.0.0.1'
  finally:
      s.close()
  options['local-ipv4'] = ip

[dynamic-template-lte-enb-epc]
< = jinja2-template-base
template = ${template-lte-enb-epc:target}
filename = instance-lte-enb-epc.cfg
extensions = jinja2.ext.do
extra-context =
    raw monitor_template ${monitor2-template:rendered}
    key local_ipv4 local-ipv4-address:local-ipv4
 
[dynamic-template-lte-gnb-epc]
< = jinja2-template-base
template = ${template-lte-gnb-epc:target}
filename = instance-lte-gnb-epc.cfg
extensions = jinja2.ext.do
extra-context =
    raw monitor_template ${monitor2-template:rendered}
    key local_ipv4 local-ipv4-address:local-ipv4
 
[dynamic-template-lte-enb]
< = jinja2-template-base
template = ${template-lte-enb:target}
filename = instance-lte-enb.cfg
extensions = jinja2.ext.do
extra-context =
    raw monitor_template ${monitor2-template:rendered}
    raw enb   ${enb:destination}
    raw enb_template   ${enb.jinja2.cfg:target}
    raw ltelogs_template   ${ltelogs.jinja2.sh:target}
    raw sdr_busy_promise   ${sdr-busy-promise:target}
    raw openssl_location ${openssl:location}
    raw default_dl_earfcn ${enb:default-dl-earfcn}
    raw default_lte_dl_freq ${enb:default-lte-dl-freq}
    raw default_lte_band ${enb:default-lte-band}
    raw default_lte_n_rb_dl ${enb:default-lte-n-rb-dl}
    raw default_lte_tx_gain ${enb:default-lte-tx-gain}
    raw default_lte_rx_gain ${enb:default-lte-rx-gain}
    raw min_frequency ${enb:min-frequency}
    raw max_frequency ${enb:max-frequency}
    key local_ipv4 local-ipv4-address:local-ipv4

[dynamic-template-lte-gnb]
< = jinja2-template-base
template = ${template-lte-gnb:target}
filename = instance-lte-gnb.cfg
extensions = jinja2.ext.do
extra-context =
    raw monitor_template ${monitor2-template:rendered}
    raw enb   ${enb:destination}
    raw gnb_template   ${gnb.jinja2.cfg:target}
    raw ltelogs_template   ${ltelogs.jinja2.sh:target}
    raw sdr_busy_promise   ${sdr-busy-promise:target}
    raw openssl_location ${openssl:location}
    raw default_dl_nr_arfcn ${enb:default-dl-nr-arfcn}
    raw default_nr_band ${enb:default-nr-band}
    raw default_nr_dl_freq ${enb:default-nr-dl-freq}
    raw default_nr_bandwidth ${enb:default-nr-bandwidth}
    raw default_nr_tx_gain ${enb:default-nr-tx-gain}
    raw default_nr_rx_gain ${enb:default-nr-rx-gain}
    raw min_frequency ${enb:min-frequency}
    raw max_frequency ${enb:max-frequency}
    key local_ipv4 local-ipv4-address:local-ipv4

[dynamic-template-lte-epc]
< = jinja2-template-base
template = ${template-lte-epc:target}
filename = instance-lte-epc.cfg
extensions = jinja2.ext.do
extra-context =
    raw monitor_template ${monitor2-template:rendered}
    raw interface_up_promise   ${interface-up-promise:target}
    raw mme   ${mme:destination}
    raw mme_template   ${mme.jinja2.cfg:target}
    raw ims_template   ${ims.jinja2.cfg:target}
    raw ltelogs_template   ${ltelogs.jinja2.sh:target}
    raw openssl_location ${openssl:location}
    raw nghttp2_location ${nghttp2:location}
    key ue_db_path ue-db-config:rendered

[ue-db-config]
recipe = slapos.recipe.template:jinja2
template = ${ue_db.jinja2.cfg:target}
filename = ue_db.cfg
extensions = jinja2.ext.do
rendered = $${buildout:directory}/$${:filename}
context =
    key slave_instance_list slap-configuration:slave-instance-list