apache-frontend: add possibility to change frontend software release through parameter
[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 {%   set state_key = "-frontend-%s-state" % i %}
53 {%   if slapparameter_dict.has_key(state_key) %}
54 state = {{ slapparameter_dict.pop(state_key) }}
55 {%   endif%}
56 {%   if sla_parameters %}
57 sla = {{ ' '.join(sla_parameters) }}
58 {%     for parameter in sla_parameters -%}
59 sla-{{ parameter }} = {{ slapparameter_dict.pop( sla_key + parameter ) }}
60 {%     endfor -%}
61 {%   endif -%}
62 {% endfor -%}
63
64 [replicate]
65 <= slap-connection
66 recipe = slapos.cookbook:requestoptional
67 {% set frontend_software_url_key = "-frontend-software-release-url" %}
68 {% if slapparameter_dict.has_key(frontend_software_url_key) %}
69 software-url = {{ slapparameter_dict.pop(frontend_software_url_key) }}
70 {% else %}
71 software-url = ${slap-connection:software-release-url}
72 {% endif %}
73 software-type = {{frontend_type}}
74 return = private-ipv4 public-ipv4 slave-instance-information-list monitor_url
75 config = {{ ' '.join(slapparameter_dict.keys()) + ' ' + slave_list_name }}
76 {% for parameter, value in slapparameter_dict.iteritems() -%}
77 config-{{parameter}} = {{ value }}
78 {% endfor -%}
79 config-{{ slave_list_name }} = {{ json_module.dumps(slave_instance_list) }}
80 connection-monitor_url =
81
82 [publish-information]
83 recipe = slapos.cookbook:publish
84 domain = {{ slapparameter_dict.get('domain') }}
85 slave-amount = {{ slave_instance_list | length }}
86 {% for frontend in frontend_section_list %}
87 {{ frontend }}-monitor-url = {{ '${' + frontend + ':connection-monitor_url}' }}
88 {% endfor -%}
89 {% for frontend in frontend_list -%}
90 #{{frontend}}-private-ipv4 = ${request-{{frontend}}:private-ipv4}
91 {% endfor -%}
92
93
94 #----------------------------
95 #--
96 #-- Publish slave information
97 [publish-slave-information]
98 recipe = slapos.cookbook:softwaretype
99 default = ${dynamic-publish-slave-information:rendered}
100 replicate = ${dynamic-publish-slave-information:rendered}
101 custom-personal = ${dynamic-publish-slave-information:rendered}
102 custom-group = ${dynamic-publish-slave-information:rendered}
103
104 [slave-information]
105 {% for frontend_section in frontend_section_list -%}
106 {{ frontend_section }} = {{ "${%s:connection-slave-instance-information-list}" % frontend_section }}
107 {% endfor -%}
108
109 [dynamic-publish-slave-information]
110 < = jinja2-template-base
111 template = {{ template_publish_slave_information }}
112 filename = dynamic-publish-slave-information.cfg
113 extensions = jinja2.ext.do
114 extra-context =
115     section slave_information slave-information
116
117 [buildout]
118 parts =
119   publish-slave-information
120   publish-information
121 {% for part in part_list -%}
122 {{ '  %s' % part }}
123 {% endfor -%}
124 #      publish-information
125
126 eggs-directory = {{ eggs_directory }}
127 develop-eggs-directory = {{ develop_eggs_directory }}
128 offline = true
129
130
131 [slap_connection]
132 # Kept for backward compatiblity
133 computer_id = ${slap-connection:computer-id}
134 partition_id = ${slap-connection:partition-id}
135 server_url = ${slap-connection:server-url}
136 software_release_url = ${slap-connection:software-release-url}
137 key_file = ${slap-connection:key-file}
138 cert_file = ${slap-connection:cert-file}
139
140 [slap-parameter]
141 slave_instance_list =
142 -frontend-quantity = 1
143 -frontend-type = single-default
144 {%- endif %}