instance-apache-replicate.cfg.in 7.91 KB
Newer Older
1
{% if slap_software_type in software_type %}
2 3 4 5 6 7 8 9 10 11 12 13 14

[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
    key slap_software_type slap-parameter:slap_software_type
    key slave_instance_list slap-parameter:slave_instance_list
    ${:extra-context}

15
{% set part_list = [] %}
16 17
{% set single_type_key = 'single-' %}
{% if slap_software_type == "replicate" %}
18 19 20 21 22 23 24 25
{%   set frontend_type = slapparameter_dict.pop('-frontend-type', 'single-default') %}
{% elif slap_software_type in ['default', 'RootSoftwareInstance'] %}
{%   set frontend_type = "%s%s" % (single_type_key, 'custom-personal') %}
{% else %}
{%   set frontend_type = "%s%s" % (single_type_key, slap_software_type) %}
{% endif %}
{% set frontend_quantity = slapparameter_dict.pop('-frontend-quantity', '1') | int %}
{% set slave_list_name = 'extra_slave_instance_list' %}
26 27 28
{% set frontend_list = [] %}
{% set frontend_section_list = [] %}
{% set request_dict = {} %}
29
{% set namebase = 'caddy-frontend' %}
30
# XXX Dirty hack, not possible to define default value before
31 32 33 34
{% set sla_computer_caddy_1_key = '-sla-1-computer_guid' %}
{% if not sla_computer_caddy_1_key in slapparameter_dict %}
{%   do slapparameter_dict.__setitem__(sla_computer_caddy_1_key, '${slap-connection:computer-id}') %}
{% endif %}
35

36
# Here we request individually each frontend.
37
# The presence of sla parameters is checked and added if found
38 39 40 41
{% for i in range(1, frontend_quantity + 1) %}
{%   set frontend_name = "%s-%s" % (namebase, i) %}
{%   set request_section_title = 'request-%s' % frontend_name %}
{%   set sla_key = "-sla-%s-" % i %}
42 43 44 45 46 47 48 49 50
{%   set sla_key_length = sla_key | length %}
{%   set sla_dict = {} %}
{%   set config_key = "-frontend-config-%s-" % i %}
{%   set config_key_length = config_key | length %}
{%   set config_dict = {} %}
{%   for key in slapparameter_dict.keys() %}
{%     if key.startswith(sla_key) %}
{%       do sla_dict.__setitem__(key[sla_key_length:], slapparameter_dict.pop(key)) %}
# We check for specific configuration regarding the frontend
51
{%     elif key.startswith(config_key) %}
52
{%       do config_dict.__setitem__(key[config_key_length:], slapparameter_dict.pop(key)) %}
53 54 55 56 57
{%     endif %}
{%   endfor %}
{%   do frontend_list.append(frontend_name) %}
{%   do frontend_section_list.append(request_section_title) %}
{%   do part_list.append(request_section_title) %}
58 59 60 61 62 63 64 65 66
# Filling request dict for slave
{%   set state_key = "-frontend-%s-state" % i %}
{%   do request_dict.__setitem__(request_section_title,
                                  {
                                  'config': config_dict,
                                  'name': frontend_name,
                                  'sla': sla_dict,
                                  'state': slapparameter_dict.pop(state_key, None)
                                  }) %}
67
{% endfor %}
68

69
{% set authorized_slave_string = slapparameter_dict.pop('-frontend-authorized-slave-string', '') %}
70 71 72
{% set authorized_slave_list = [] %}
{% set rejected_slave_list = [] %}
{% for slave in slave_instance_list %}
73 74
{# BBB: apache_custom_https AND apache_custom_http #}
{%   if not ((slave.has_key('caddy_custom_http') or slave.has_key('apache_custom_http') or slave.has_key('caddy_custom_https') or slave.has_key('apache_custom_https')) and not slave.get('slave_reference') in authorized_slave_string) %}
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
{%     set slave_ok = True %}
{%     if slave.get('url') %}
{%       if subprocess_module.call([caddy_backend_url_validator, slave['url']]) == 1 %}
{%         set slave_ok = False %}
{%       endif %}
{%     endif %}
{%     if slave.get('https-url') %}
{%       if subprocess_module.call([caddy_backend_url_validator, slave['https-url']]) == 1 %}
{%         set slave_ok = False %}
{%       endif %}
{%     endif %}
{%     if slave_ok %}
{%       do authorized_slave_list.append(slave) %}
{%     else %}
{%       do rejected_slave_list.append(slave.get('slave_reference')) %}
{%     endif %}
91 92 93
{%   else %}
{%     do rejected_slave_list.append(slave.get('slave_reference')) %}
{%   endif %}
94
{% endfor %}
95

96 97 98
[monitor-instance-parameter]
monitor-httpd-port = {{ slapparameter_dict.get('monitor-httpd-port', '8196') }}

99 100 101 102 103 104
[replicate]
<= slap-connection
recipe = slapos.cookbook:requestoptional
config-monitor-cors-domains = {{ slapparameter_dict.get('monitor-cors-domains', 'monitor.app.officejs.com') }}
config-monitor-username = ${monitor-instance-parameter:username}
config-monitor-password = ${monitor-htpasswd:passwd}
105
config-monitor-httpd-port = {{ slapparameter_dict.get('monitor-httpd-port', '8196') }}
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

{% set frontend_software_url_key = "-frontend-software-release-url" %}
{% if slapparameter_dict.has_key(frontend_software_url_key) %}
software-url = {{ slapparameter_dict.pop(frontend_software_url_key) }}
{% else %}
software-url = ${slap-connection:software-release-url}
{% endif %}
software-type = {{frontend_type}}
return = private-ipv4 public-ipv4 slave-instance-information-list monitor-base-url

{% for section, frontend_request in request_dict.iteritems() %}
[{{section}}]
<= replicate
name = {{ frontend_request.get('name') }}
{%   if frontend_request.get('state') %}
state = {{ frontend_request.get('state') }}
{%   endif%}
123 124
{%   set slave_configuration_dict = slapparameter_dict %}
{%   do slave_configuration_dict.update(frontend_request.get('config')) %}
125 126 127 128
{%   do slave_configuration_dict.__setitem__(slave_list_name, json_module.dumps(authorized_slave_list)) %}
{%   do slave_configuration_dict.__setitem__("frontend-name", frontend_request.get('name')) %}
config-_ = {{ json_module.dumps(slave_configuration_dict) }}
{%   if frontend_request.get('sla') %}
129
{%     for parameter, value in frontend_request.get('sla').iteritems() %}
130
sla-{{ parameter }} = {{ value }}
131 132 133
{%     endfor %}
{%   endif %}
{% endfor %}
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156


[publish-information]
<= monitor-publish
recipe = slapos.cookbook:publish
domain = {{ slapparameter_dict.get('domain') }}
slave-amount = {{ slave_instance_list | length }}
accepted-slave-amount = {{ authorized_slave_list | length }}
rejected-slave-amount = {{ rejected_slave_list | length }}
rejected-slave-list = {{ json_module.dumps(rejected_slave_list) }}

#----------------------------
#--
#-- Publish slave information
[publish-slave-information]
recipe = slapos.cookbook:softwaretype
default = ${dynamic-publish-slave-information:rendered}
RootSoftwareInstance = ${dynamic-publish-slave-information:rendered}
replicate = ${dynamic-publish-slave-information:rendered}
custom-personal = ${dynamic-publish-slave-information:rendered}
custom-group = ${dynamic-publish-slave-information:rendered}

[slave-information]
157
{% for frontend_section in frontend_section_list %}
158
{{ frontend_section }} = {{ "${%s:connection-slave-instance-information-list}" % frontend_section }}
159
{% endfor %}
160 161 162 163 164 165 166 167 168 169 170 171 172

[dynamic-publish-slave-information]
< = jinja2-template-base
template = {{ template_publish_slave_information }}
filename = dynamic-publish-slave-information.cfg
extensions = jinja2.ext.do
extra-context =
    section slave_information slave-information

[monitor-conf-parameters]
monitor-url-list +=
{% for frontend in frontend_section_list %}
{{ '  ${' + frontend + ':connection-monitor-base-url}' }}
173
{% endfor %}
174 175 176 177 178 179 180

[buildout]
extends = {{ template_monitor }}
parts =
  monitor-base
  publish-slave-information
  publish-information
181
{% for part in part_list %}
182
{{ '  %s' % part }}
183
{% endfor %}
184 185 186 187 188 189 190 191
#      publish-information

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


[slap_connection]
192
# Kept for backward compatibility
193 194 195 196 197 198 199 200 201 202 203
computer_id = ${slap-connection:computer-id}
partition_id = ${slap-connection:partition-id}
server_url = ${slap-connection:server-url}
software_release_url = ${slap-connection:software-release-url}
key_file = ${slap-connection:key-file}
cert_file = ${slap-connection:cert-file}

[slap-parameter]
slave_instance_list =
-frontend-quantity = 1
-frontend-type = single-default
204
{% endif %}