[buildout]
parts =
  instance
  publish-connection-parameter

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

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

[instance-parameter]
port = 8888
host = $${slapconfiguration:ipv4-random}
cert_file = $${generate-certificate:cert_file}
key_file = $${generate-certificate:key_file}
logfile = $${directory:log}/ipython_notebook.log
notebook_dir = $${directory:notebook_dir}

[generate-certificate]
recipe = plone.recipe.command
command =
  if [ ! -e $${instance-parameter:key_file} ]
  then
    ${openssl-output:openssl} req -x509 -nodes -days 3650 \
      -subj "/C=AA/ST=X/L=X/O=Dis/CN=$${instance-parameter:host}" \
      -newkey rsa:1024 -keyout $${instance-parameter:key_file} \
      -out $${instance-parameter:cert_file}
  fi
update-command = $${:command}
cert_file = $${directory:etc}/ipython_notebook_cert.crt
key_file = $${directory:etc}/ipython_notebook_cert.key

[instance]
recipe = slapos.cookbook:wrapper
command-line =
  ${buildout:bin-directory}/ipython notebook
  --no-browser 
  --matplotlib=inline
  --ip=$${instance-parameter:host} 
  --port=$${instance-parameter:port}
  --port-retries=0
  --certfile=$${instance-parameter:cert_file}
  --keyfile=$${instance-parameter:key_file}
  --notebook-dir=$${instance-parameter:notebook_dir}
  --logfile=$${instance-parameter:logfile}
wrapper-path = $${directory:service}/ipython_notebook
parameters-extra = true

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

[publish-connection-parameter]
recipe = slapos.cookbook:publishurl
url = https://$${instance-parameter:host}:$${instance-parameter:port}