apache-frontend: add default values for parameter in replicate
[slapos.git] / software / apache-frontend / templates / apache-custom-slave-list.cfg.in
1 {% if software_type == slap_software_type -%}
2
3 {% set cached_server_dict = {} -%}
4 {% set part_list = [] -%}
5 {% set cache_access = "http://%s:%s" % (local_ipv4, cache_port) -%}
6 {% set generic_instance_parameter_dict = {'cache_access': cache_access,} -%}
7 {% if extra_slave_instance_list -%}
8 {%   set slave_instance_information_list = []-%}
9 {%   set slave_instance_list = slave_instance_list + json_module.loads(extra_slave_instance_list) -%}
10 {% endif -%}
11 [jinja2-template-base]
12 recipe = slapos.recipe.template:jinja2
13 rendered = {{ apache_configuration_directory }}/${:filename}
14 extra-context =
15 context =
16     key eggs_directory buildout:eggs-directory
17     key develop_eggs_directory buildout:develop-eggs-directory
18     ${:extra-context}
19
20 # Loop trhought slave list to set up slaves
21 {% for slave_instance in slave_instance_list -%}
22 {%   set slave_reference = slave_instance.get('slave_reference') -%}
23 {%   set slave_section_title = 'dynamic-template-slave-instance-%s' % slave_reference -%}
24 {%   set slave_parameter_dict = generic_instance_parameter_dict.copy() -%}
25 {%   do part_list.append(slave_section_title) -%}
26 # Set Up log files
27 {%   do slave_parameter_dict.__setitem__('access_log', '/'.join([apache_log_directory, '%s_access_log' % slave_reference])) -%}
28 {%   do slave_parameter_dict.__setitem__('error_log', '/'.join([apache_log_directory, '%s_error_log' % slave_reference])) -%}
29 # Set up apache configuration file for slave
30 [{{ slave_section_title }}]
31 < = jinja2-template-base
32 template = {{ template_slave_configuration }}
33 filename = {{ '%s.conf' % slave_reference }}
34 extra-context =
35     key apache_custom_https {{ 'slave-instance-%s-configuration:apache_custom_https' % slave_reference }}
36     key apache_custom_http {{ 'slave-instance-%s-configuration:apache_custom_http' % slave_reference }}
37     raw https_port {{ https_port }}
38     raw http_port {{ http_port }}
39 {{ '\n' }}
40
41 # Set ssl certificates for each slave
42 {%   for cert_name in ('ssl_key', 'ssl_crt', 'ssl_ca_crt', 'ssl_csr')-%}
43 {%     if cert_name in slave_instance -%}
44 {%       set cert_title = '%s-%s' % (slave_reference, cert_name.replace('ssl_', '')) -%}
45 {%       set cert_file = '/'.join([custom_ssl_directory, cert_title.replace('-','.')]) -%}
46 {%       do part_list.append(cert_title) -%}
47 {%       do slave_parameter_dict.__setitem__(cert_name, cert_file) -%}
48 # Store certificates on fs
49 [{{ cert_title }}]
50 < = jinja2-template-base
51 template = {{ empty_template }}
52 rendered = {{ cert_file }}
53 extra-context =
54     key content {{ cert_title + '-config:value' }}
55 # Store certificate in config
56 [{{ cert_title + '-config' }}]
57 value = {{ dumps(slave_instance.get(cert_name)) }}
58 {%     endif -%}
59 {%   endfor -%}
60
61 # Set apache configuration value for slave
62 [{{ ('slave-instance-%s-configuration' % slave_reference) }}]
63 {% set apache_custom_http = ((slave_instance.get('apache_custom_http', '')) % slave_parameter_dict) -%}
64 {% set apache_custom_https = ((slave_instance.get('apache_custom_https', '')) % slave_parameter_dict) -%}
65 apache_custom_http = {{ dumps(apache_custom_http) }}
66 apache_custom_https = {{ dumps(apache_custom_https) }}
67 {{ '\n' }}
68
69 # The slave use cache
70 {%   if 'enable_cache' in slave_instance and 'url' in slave_instance and 'domain' in slave_instance -%}
71 {%     do cached_server_dict.__setitem__(slave_instance.get('domain'), slave_instance.get('url')) -%}
72 {%   endif -%}
73
74 # Publish slave information
75 {%   if not extra_slave_instance_list -%}
76 {%     set publish_section_title = 'publish-%s-connection-information' % slave_instance.get('slave_reference') -%}
77 {%     do part_list.append(publish_section_title) -%}
78 [{{ publish_section_title }}]
79 recipe = slapos.cookbook:publish
80 public-ipv4 = {{ public_ipv4 }}
81 slave-reference = {{ slave_instance.get('slave_reference') }}
82 {%   else -%}
83 {%     do slave_instance_information_list.append({'slave-reference':slave_instance.get('slave_reference'), 'public-ipv4':public_ipv4}) -%}
84 {%   endif -%}
85 {% endfor -%}
86
87 # Publish information for the instance
88 {% set publish_section_title = 'publish-apache-information' -%}
89 {% do part_list.append(publish_section_title) -%}
90 [{{ publish_section_title }}]
91 recipe = slapos.cookbook:publish
92 public-ipv4 = {{ public_ipv4 }}
93 private-ipv4 = {{ local_ipv4 }}
94 {% if extra_slave_instance_list -%}
95 slave-instance-information-list = {{ json_module.dumps(slave_instance_information_list) }}
96 {% endif -%}
97
98 {% do part_list.append('cached-rewrite-rules') -%}
99 [cached-rewrite-rules]
100 < = jinja2-template-base
101 template = {{ template_rewrite_cached }}
102 rendered = {{ rewrite_cached_configuration }}
103 extra-context =
104     import json_module json
105     key server_dict rewrite-rules:rules
106
107 [rewrite-rules]
108 rules = {{ dumps(cached_server_dict) }}
109
110 [buildout]
111 parts +=
112 {% for part in part_list -%}
113 {{ '    %s' % part }}
114 {% endfor -%}
115
116 eggs-directory = {{ eggs_directory }}
117 develop-eggs-directory = {{ develop_eggs_directory }}
118 offline = true
119 cache-access = {{ cache_access }}
120
121 {% endif -%}