apache-runner: add log access and publish monitoring url
[slapos.git] / software / apache-frontend / instance-apache-replicate.cfg.in
1 {% if slap_software_type in software_type -%}
2
3 [jinja2-template-base]
4 recipe = slapos.recipe.template:jinja2
5 rendered = ${buildout:directory}/${:filename}
6 extra-context =
7 context =
8     import json_module json
9     key eggs_directory buildout:eggs-directory
10     key develop_eggs_directory buildout:develop-eggs-directory
11     key slap_software_type slap-parameter:slap_software_type
12     key slave_instance_list slap-parameter:slave_instance_list
13     ${:extra-context}
14
15 {% set part_list = [] -%}
16 {% set single_type_key = 'single-' %}
17 {% if slap_software_type in ("replicate", "RootSoftwareInstance") %}
18 {%   set frontend_type = slapparameter_dict.pop('-frontend-type', 'single-default') -%}
19 {% else -%}
20 {%   set frontend_type = "%s%s" % (single_type_key, slap_software_type) -%}
21 {% endif -%}
22 {% set frontend_quantity = slapparameter_dict.pop('-frontend-quantity', '1') | int -%}
23 {% set slave_list_name = 'extra_slave_instance_list' -%}
24 {% set frontend_list = [] %}
25 {% set frontend_section_list = [] %}
26 {% set namebase = 'apache-frontend' -%}
27 # XXX Dirty hack, not possible to define default value before
28 {% set sla_computer_apache_1_key = '-sla-1-computer_guid' -%}
29 {% if not sla_computer_apache_1_key in slapparameter_dict -%}
30 {%   do slapparameter_dict.__setitem__(sla_computer_apache_1_key, '${slap-connection:computer-id}') -%}
31 {% endif -%}
32
33 # Here we request individualy each frontend.
34 # The presence of sla parameters is checked and added if found
35 {% for i in range(1, frontend_quantity + 1) -%}
36 {%   set frontend_name = "%s-%s" % (namebase, i) -%}
37 {%   set request_section_title = 'request-%s' % frontend_name -%}
38 {%   set sla_key = "-sla-%s-" % i -%}
39 {%   set sla_key_length = sla_key | length %}
40 {%   set sla_parameters = [] %}
41 {%   for key in slapparameter_dict.keys() %}
42 {%     if key.startswith(sla_key) %}
43 {%       do sla_parameters.append(key[sla_key_length:]) %}
44 {%     endif -%}
45 {%   endfor -%}
46 {%   do frontend_list.append(frontend_name) -%}
47 {%   do frontend_section_list.append(request_section_title) -%}
48 {%   do part_list.append(request_section_title) -%}
49 [{{request_section_title}}]
50 <= replicate
51 name = {{frontend_name}}
52 {%   if sla_parameters %}
53 sla = {{ ' '.join(sla_parameters) }}
54 {%     for parameter in sla_parameters -%}
55 sla-{{ parameter }} = {{ slapparameter_dict.pop( sla_key + parameter ) }}
56 {%     endfor -%}
57 {%   endif -%}
58 {% endfor -%}
59
60 [replicate]
61 <= slap-connection
62 recipe = slapos.cookbook:requestoptional
63 software-url = ${slap-connection:software-release-url}
64 software-type = {{frontend_type}}
65 return = private-ipv4 public-ipv4 slave-instance-information-list monitor_url
66 config = {{ ' '.join(slapparameter_dict.keys()) + ' ' + slave_list_name }}
67 {% for parameter, value in slapparameter_dict.iteritems() -%}
68 config-{{parameter}} = {{ value }}
69 {% endfor -%}
70 config-{{ slave_list_name }} = {{ json_module.dumps(slave_instance_list) }}
71 connection-monitor_url =
72
73 [publish-information]
74 recipe = slapos.cookbook:publish
75 domain = {{ slapparameter_dict.get('domain') }}
76 slave-amount = {{ slave_instance_list | length }}
77 {% for frontend in frontend_section_list %}
78 {{ frontend }}-monitor-url = {{ '${' + frontend + ':connection-monitor_url}' }}
79 {% endfor -%}
80 {% for frontend in frontend_list -%}
81 #{{frontend}}-private-ipv4 = ${request-{{frontend}}:private-ipv4}
82 {% endfor -%}
83
84
85 #----------------------------
86 #--
87 #-- Publish slave information
88 [publish-slave-information]
89 recipe = slapos.cookbook:softwaretype
90 default = ${dynamic-publish-slave-information:rendered}
91 replicate = ${dynamic-publish-slave-information:rendered}
92 custom-personal = ${dynamic-publish-slave-information:rendered}
93 custom-group = ${dynamic-publish-slave-information:rendered}
94
95 [slave-information]
96 {% for frontend_section in frontend_section_list -%}
97 {{ frontend_section }} = {{ "${%s:connection-slave-instance-information-list}" % frontend_section }}
98 {% endfor -%}
99
100 [dynamic-publish-slave-information]
101 < = jinja2-template-base
102 template = {{ template_publish_slave_information }}
103 filename = dynamic-publish-slave-information.cfg
104 extensions = jinja2.ext.do
105 extra-context =
106     section slave_information slave-information
107
108 [buildout]
109 parts =
110   publish-slave-information
111   publish-information
112 {% for part in part_list -%}
113 {{ '  %s' % part }}
114 {% endfor -%}
115 #      publish-information
116
117 eggs-directory = {{ eggs_directory }}
118 develop-eggs-directory = {{ develop_eggs_directory }}
119 offline = true
120
121
122 [slap_connection]
123 # Kept for backward compatiblity
124 computer_id = ${slap-connection:computer-id}
125 partition_id = ${slap-connection:partition-id}
126 server_url = ${slap-connection:server-url}
127 software_release_url = ${slap-connection:software-release-url}
128 key_file = ${slap-connection:key-file}
129 cert_file = ${slap-connection:cert-file}
130
131 [slap-parameter]
132 slave_instance_list =
133 -frontend-quantity = 1
134 -frontend-type = single-default
135 {%- endif %}