[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 = instance-default:output
peer = instance-peer:output
RootSoftwareInstance = $${:default}

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

[dynamic-template-base]
recipe = slapos.recipe.template:jinja2
output = $${buildout:directory}/$${:_buildout_section_name_}.cfg
extra-context =
context =
  jsonkey default_parameter_dict :default-parameters
  key parameter_dict slap-configuration:configuration
  $${:extra-context}
default-parameters =
  {
    "autopilotIp": "192.168.27.1",
    "autopilotPort": 7909,
    "flightScript": "https://lab.nexedi.com/nexedi/flight-scripts/-/raw/v2.0/default.js",
    "isASimulation": false,
    "multicastIp": "ff15::1111",
    "netIf": "eth0",
    "droneGuidList": [],
    "subscriberGuidList":[]
  }

[instance-default]
<= dynamic-template-base
url = ${instance-default:target}
extensions = jinja2.ext.do

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

[gwsocket-port]
recipe = slapos.cookbook:free_port
minimum = 6789
maximum = 6799
ip = $${slap-configuration:ipv6-random}

[peer-configuration]
recipe = slapos.recipe.template:jinja2
output = $${directory:etc}/configuration.json
extensions = jinja2.ext.do
context =
  import json_module json
  key websocket_ip gwsocket-port:ip
  key websocket_port gwsocket-port:port
  key parameter_dict slap-configuration:configuration
inline =
  {% do parameter_dict.__setitem__('websocketIp', websocket_ip) -%}
  {% do parameter_dict.__setitem__('websocketPort', websocket_port) -%}
  {{ json_module.dumps(parameter_dict) }}

[instance-peer]
<= dynamic-template-base
url = ${instance-peer:output}
extra-context =
  key configuration peer-configuration:output
  key ipv6 slap-configuration:ipv6-random
  key websocket_port gwsocket-port:port
