instance-kvm-resilient.cfg.jinja2 3.29 KB
Newer Older
1 2 3
# vim: set ft=cfg:

{% import 'parts' as parts %}
4
{% import 'replicated' as replicated with context %}
5

6
{% set backup_amount = slapparameter_dict.pop('resilient-clone-number', "1")|int + 1 -%}
7
{% set monitor_dict = {} -%}
8
{% set monitor_return = [] -%}
9

10
{% if slapparameter_dict.get('enable-monitor', True) == True -%}
11
{% set monitor_return = ['monitor-base-url'] -%}
12
{% set monitor_parameter = {'monitor-cors-domains': slapparameter_dict.pop('monitor-cors-domains', "monitor.app.officejs.com")} -%}
13 14
{% set monitor_dict = {'parameter': monitor_parameter, 'return': monitor_return} -%}
{% endif -%}
15
{% set monitor_interface_url = slapparameter_dict.pop('monitor-interface-url', 'https://monitor.app.officejs.com') -%}
16

17 18 19 20 21 22 23
[buildout]
eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }}
offline = true

# += because we need to take up parts (like instance-custom, slapmonitor etc) from the profile we extended
parts +=
24
  {{ parts.replicate("kvm", backup_amount) }}
25
  publish-connection-information
26
  kvm-frontend-url-promise
27
  kvm-backend-url-promise
28

29
{% if monitor_dict -%}
30 31 32 33 34 35 36 37 38
extends = {{ template_monitor }}


[monitor-htpasswd]
recipe = slapos.cookbook:generate.password
storage-path = ${directory:etc}/.monitor_user
bytes = 8
username = admin

39 40 41 42 43
# XXX Monitoring Main Instane
[monitor-instance-parameter]
monitor-httpd-port = 8160
cors-domains = {{ monitor_parameter.get('monitor-cors-domains', '') }}

44 45 46 47 48
{%  do monitor_parameter.__setitem__('monitor-username', slapparameter_dict.get('monitor-username', 'admin'))%}
{%  do monitor_parameter.__setitem__('monitor-password', slapparameter_dict.get('monitor-password', '${monitor-htpasswd:passwd}'))%}
{% endif -%}

{{ replicated.replicate("kvm", backup_amount, "kvm-export", "kvm-import", slapparameter_dict=slapparameter_dict, monitor_parameter_dict=monitor_dict) }}
49

50 51
[directory]
recipe = slapos.cookbook:mkdirectory
52 53
etc = ${buildout:directory}/etc
promises = ${:etc}/promise
54

55
# Bubble down the parameters of the requested instance to the user
56
[request-kvm]
57
# Note: += doesn't work.
58 59
return =
# Resilient related parameters
60
  url ssh-public-key ssh-url notification-id ip {{ monitor_return | join(' ') }}
61
# KVM related parameters
62
# XXX: return ALL parameters (like nat rules), through jinja
63
  backend-url url ip
64

65
[publish-connection-information]
66 67 68
recipe = slapos.cookbook:publish
backend-url = ${request-kvm:connection-backend-url}
url = ${request-kvm:connection-url}
69
ipv6 = ${request-kvm:connection-ip}
70
{% if monitor_dict -%}
71 72
monitor-base-url = ${monitor-publish-parameters:monitor-base-url}
monitor-setup-url = {{ monitor_interface_url }}/#page=settings_configurator&url=${monitor-publish-parameters:monitor-url}&username=${monitor-publish-parameters:monitor-user}&password=${monitor-publish-parameters:monitor-password}
73
{% endif -%}
74 75 76 77 78 79 80 81 82 83 84

[kvm-frontend-url-promise]
# Check that url parameter is complete
recipe = collective.recipe.template
input = inline:#!/bin/sh
  URL="${request-kvm:connection-url}"
  if [[ ! "$URL" == https://* ]]; then
    exit 1
  fi
output = ${resilient-directory:promise}/kvm-frontend-url
mode = 700
85 86 87 88 89

[kvm-backend-url-promise]
# Check that backend url is reachable
recipe = slapos.cookbook:check_url_available
path = ${directory:promises}/frontend_promise
90
url = ${publish-connection-information:url}
91 92
dash_path = /bin/sh
curl_path = {{ curl_executable_location }}