instance-apache-replicate.cfg.in 5.75 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 17 18
{% set single_type_key = 'single-' %}
{% if slap_software_type in ("replicate", "RootSoftwareInstance") %}
{%   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 24 25 26
{% set slave_list_name = 'extra_slave_instance_list' -%}
{% set frontend_list = [] %}
{% set frontend_section_list = [] %}
{% set namebase = 'apache-frontend' -%}
27 28 29 30 31
# 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 -%}
32

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
# 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 %}
{%   set sla_parameters = [] %}
{%   for key in slapparameter_dict.keys() %}
{%     if key.startswith(sla_key) %}
{%       do sla_parameters.append(key[sla_key_length:]) %}
{%     endif -%}
{%   endfor -%}
{%   do frontend_list.append(frontend_name) -%}
{%   do frontend_section_list.append(request_section_title) -%}
{%   do part_list.append(request_section_title) -%}
[{{request_section_title}}]
<= replicate
name = {{frontend_name}}
52 53 54 55
{%   set state_key = "-frontend-%s-state" % i %}
{%   if slapparameter_dict.has_key(state_key) %}
state = {{ slapparameter_dict.pop(state_key) }}
{%   endif%}
56 57 58 59 60 61 62 63
{%   if sla_parameters %}
sla = {{ ' '.join(sla_parameters) }}
{%     for parameter in sla_parameters -%}
sla-{{ parameter }} = {{ slapparameter_dict.pop( sla_key + parameter ) }}
{%     endfor -%}
{%   endif -%}
{% endfor -%}

64 65 66 67 68 69 70 71 72 73 74
{% 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 -%}

75 76
[replicate]
<= slap-connection
77
recipe = slapos.cookbook:requestoptional
78 79 80 81
{% 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 %}
82
software-url = ${slap-connection:software-release-url}
83
{% endif %}
84
software-type = {{frontend_type}}
85
return = private-ipv4 public-ipv4 slave-instance-information-list monitor_url
86 87 88 89
config = {{ ' '.join(slapparameter_dict.keys()) + ' ' + slave_list_name }}
{% for parameter, value in slapparameter_dict.iteritems() -%}
config-{{parameter}} = {{ value }}
{% endfor -%}
90
config-{{ slave_list_name }} = {{ json_module.dumps(authorized_slave_list) }}
91
connection-monitor_url =
92 93 94 95 96

[publish-information]
recipe = slapos.cookbook:publish
domain = {{ slapparameter_dict.get('domain') }}
slave-amount = {{ slave_instance_list | length }}
97 98 99
accepted-slave-amount = {{ authorized_slave_list | length }}
rejected-slave-amount = {{ rejected_slave_list | length }}
rejected-slave-list = {{ json_module.dumps(rejected_slave_list) }}
100 101 102
{% for frontend in frontend_section_list %}
{{ frontend }}-monitor-url = {{ '${' + frontend + ':connection-monitor_url}' }}
{% endfor -%}
103 104 105 106 107 108 109 110 111 112 113 114
{% for frontend in frontend_list -%}
#{{frontend}}-private-ipv4 = ${request-{{frontend}}:private-ipv4}
{% endfor -%}


#----------------------------
#--
#-- Publish slave information
[publish-slave-information]
recipe = slapos.cookbook:softwaretype
default = ${dynamic-publish-slave-information:rendered}
replicate = ${dynamic-publish-slave-information:rendered}
115 116
custom-personal = ${dynamic-publish-slave-information:rendered}
custom-group = ${dynamic-publish-slave-information:rendered}
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

[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

[buildout]
parts =
  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}

154 155
[slap-parameter]
slave_instance_list =
156 157
-frontend-quantity = 1
-frontend-type = single-default
158
{%- endif %}