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

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

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

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

69 70 71 72 73 74 75 76 77 78 79
{% set authorized_slave_string = slapparameter_dict.pop('-frontend-authorized-slave-string', '') -%}
{% set authorized_slave_list = [] %}
{% set rejected_slave_list = [] %}
{% for slave in slave_instance_list %}
{%   if not (slave.has_key('apache_custom_http') and not slave.get('slave_reference') in authorized_slave_string) %}
{%     do authorized_slave_list.append(slave) %}
{%   else %}
{%     do rejected_slave_list.append(slave.get('slave_reference')) %}
{%   endif %}
{% endfor -%}

80 81
[replicate]
<= slap-connection
82
recipe = slapos.cookbook:requestoptional
83
config-monitor-cors-domains = {{ slapparameter_dict.get('monitor-cors-domains', 'monitor.app.officejs.com') }}
84
config-monitor-username = ${monitor-instance-parameter:username}
85 86
config-monitor-password = ${monitor-htpasswd:passwd}

87 88 89 90
{% 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 %}
91
software-url = ${slap-connection:software-release-url}
92
{% endif %}
93
software-type = {{frontend_type}}
94
return = private-ipv4 public-ipv4 slave-instance-information-list monitor-base-url
95

96 97 98 99 100 101 102 103 104 105
{% 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%}
{%   set slave_configuration_dict = frontend_request.get('config') %}
{%   do slave_configuration_dict.update(**slapparameter_dict) %}
{%   do slave_configuration_dict.__setitem__(slave_list_name, json_module.dumps(authorized_slave_list)) %}
106
{%   do slave_configuration_dict.__setitem__("frontend-name", frontend_request.get('name')) %}
107 108 109 110 111 112 113 114 115
config-_ = {{ json_module.dumps(slave_configuration_dict) }}
{%   if frontend_request.get('sla') %}
{%     for parameter, value in frontend_request.get('sla').iteritems() -%}
sla-{{ parameter }} = {{ value }}
{%     endfor -%}
{%   endif -%}
{% endfor -%}


116 117 118 119
[publish-information]
recipe = slapos.cookbook:publish
domain = {{ slapparameter_dict.get('domain') }}
slave-amount = {{ slave_instance_list | length }}
120 121 122
accepted-slave-amount = {{ authorized_slave_list | length }}
rejected-slave-amount = {{ rejected_slave_list | length }}
rejected-slave-list = {{ json_module.dumps(rejected_slave_list) }}
123 124 125 126
monitor-base-url = ${monitor-conf-parameters:base-url}
monitor-url = ${:monitor-base-url}/public/feeds
monitor-user = ${monitor-instance-parameter:username}
monitor-password = ${monitor-instance-parameter:password}
127 128 129
{% set monitor_interface_url = slapparameter_dict.get('monitor-interface-url', 'https://monitor.app.officejs.com') -%}
monitor-setup-url = {{ monitor_interface_url }}/#page=settings_configurator&url=${:monitor-url}

130 131 132 133 134 135 136

#----------------------------
#--
#-- Publish slave information
[publish-slave-information]
recipe = slapos.cookbook:softwaretype
default = ${dynamic-publish-slave-information:rendered}
137
RootSoftwareInstance = ${dynamic-publish-slave-information:rendered}
138
replicate = ${dynamic-publish-slave-information:rendered}
139 140
custom-personal = ${dynamic-publish-slave-information:rendered}
custom-group = ${dynamic-publish-slave-information:rendered}
141 142 143 144 145 146 147 148 149 150 151 152 153 154

[slave-information]
{% for frontend_section in frontend_section_list -%}
{{ frontend_section }} = {{ "${%s:connection-slave-instance-information-list}" % frontend_section }}
{% endfor -%}

[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

155 156 157 158 159 160
[monitor-conf-parameters]
monitor-url-list +=
{% for frontend in frontend_section_list %}
{{ '  ${' + frontend + ':connection-monitor-base-url}' }}
{% endfor -%}

161
[buildout]
162
extends = {{ template_monitor }}
163
parts =
164
  monitor-base
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
  publish-slave-information
  publish-information
{% for part in part_list -%}
{{ '  %s' % part }}
{% endfor -%}
#      publish-information

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


[slap_connection]
# Kept for backward compatiblity
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}

186 187
[slap-parameter]
slave_instance_list =
188 189
-frontend-quantity = 1
-frontend-type = single-default
190
{%- endif %}