resilient-stack : add -sla-%s-foo parameter magic
[slapos.git] / stack / resilient / template-replicated.cfg.in
1 {% macro replicate(namebase, nbbackup, typeexport, typeimport, heriteLeader='', heriteBackup='', slapparameter_dict={}) %}
2
3 {% set sla_parameter_dict = {} -%}
4 # prepare sla-parameters
5 {% if slapparameter_dict is defined -%}
6 {%   for key in slapparameter_dict.keys() -%}
7 {%     if key.startswith('-sla-') -%}
8 {%       do sla_parameter_dict.__setitem__(key, slapparameter_dict.pop(key)) -%}
9 {%     endif -%}
10 {%   endfor -%}
11 {% endif -%}
12
13
14 ## Tells the Backupable recipe that we want a backup
15 [resilient]
16 recipe = slapos.cookbook:request
17 config-namebase = {{namebase}}
18 software-url = ${slap-connection:software-release-url}
19
20 ## Every request is double to provide the 3 IPs.
21 ## First, we request with ip-list parameter hardcoded.
22 ## Then, we request the same thing without this.
23 ## XXX-Cedric: is it useful?
24 [request-{{namebase}}]
25 <= resilient
26    slap-connection
27    {{heriteLeader}}
28 software-type = {{typeexport}}
29 name = {{namebase}}0
30 return = ssh-public-key ssh-url notification-id ip
31
32 config =
33 # Resilient related parameters
34   number authorized-key notify ip-list namebase
35 {% if slapparameter_dict is defined %}
36 # Software Instance related parameters
37   {% for parameter_name in slapparameter_dict.keys() %}{{parameter_name}} {% endfor %}
38 {% endif %}
39 config-number = 0
40 config-authorized-key = {% for id in range(1,nbbackup|int) %} ${request-pbs-{{namebase}}-{{id}}:connection-ssh-key}{% endfor %}
41 config-notify = {% for id in range(1,nbbackup|int) %} ${request-pbs-{{namebase}}-{{id}}:connection-notification-url}{% endfor %}
42 config-ip-list =
43 # Bubble up all the instance parameters to the requested export instance.
44 {% if slapparameter_dict is defined %}
45 {% for parameter_name, parameter_value in slapparameter_dict.items() %}config-{{parameter_name}} = {{parameter_value}}
46 {% endfor %}
47 {% endif %}
48 {% if sla_parameter_dict -%}
49 {%   set sla_key_main = "-sla-%s%s-" % (namebase, 0) -%}
50 {%   set sla_key_secondary = "-sla-%s-" % (0) -%}
51 {%   set sla_key_main_length = sla_key_main | length -%}
52 {%   set sla_key_secondary_length = sla_key_secondary | length -%}
53 {%   set sla_dict = {} -%}
54 {%   for key in sla_parameter_dict.keys() -%}
55 {%     if key.startswith(sla_key_main) -%}
56 {%       do sla_dict.__setitem__(key[sla_key_main_length:], sla_parameter_dict.get(key)) -%}
57 {%     elif key.startswith(sla_key_secondary) and not sla_dict.has_key(key[sla_key_secondary_length:]) -%}
58 {%         do sla_dict.__setitem__(key[sla_key_secondary_length:], sla_parameter_dict.get(key)) -%}
59 {%     endif -%}
60 {%   endfor -%}
61 {%   if sla_dict %}
62 sla = {{ ' '.join(sla_dict.keys()) }}
63 {%     for key, value in sla_dict.iteritems() -%}
64 sla-{{ key }} = {{ value }}
65 {%     endfor -%}
66 {%   endif -%}
67 {% endif -%}
68
69 {% for id in range(1,nbbackup|int) %}
70
71 [request-{{namebase}}-pseudo-replicating-{{id}}]
72 <= slap-connection
73    resilient
74    {{heriteBackup}}
75 recipe = slapos.cookbook:request
76 name = {{namebase}}{{id}}
77
78 software-url = ${slap-connection:software-release-url}
79 software-type = {{typeimport}}
80 return = ssh-public-key ssh-url notification-url ip
81
82 pbs-notification-id = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-push
83
84 config = number authorized-key on-notification ip-list namebase
85 config-number = {{id}}
86 config-authorized-key = ${request-pbs-{{namebase}}-{{id}}:connection-ssh-key}
87 config-on-notification = ${request-pbs-{{namebase}}-{{id}}:connection-feeds-url}${:pbs-notification-id}
88 config-ip-list =
89 {% if sla_parameter_dict -%}
90 {%   set sla_key_main = "-sla-%s%s-" % (namebase, id) -%}
91 {%   set sla_key_secondary = "-sla-%s-" % (id) -%}
92 {%   set sla_key_main_length = sla_key_main | length -%}
93 {%   set sla_key_secondary_length = sla_key_secondary | length -%}
94 {%   set sla_dict = {} -%}
95 {%   for key in sla_parameter_dict.keys() -%}
96 {%     if key.startswith(sla_key_main) -%}
97 {%       do sla_dict.__setitem__(key[sla_key_main_length:], sla_parameter_dict.get(key)) -%}
98 {%     elif key.startswith(sla_key_secondary) and not sla_dict.has_key(key[sla_key_secondary_length:]) -%}
99 {%         do sla_dict.__setitem__(key[sla_key_secondary_length:], sla_parameter_dict.get(key)) -%}
100 {%     endif -%}
101 {%   endfor -%}
102 {%   if sla_dict %}
103 sla = {{ ' '.join(sla_dict.keys()) }}
104 {%     for key, value in sla_dict.iteritems() -%}
105 sla-{{ key }} = {{ value }}
106 {%     endfor -%}
107 {%   endif %}
108 {% endif %}
109
110
111 {% endfor -%}
112
113 [iplist]
114 config-ip-list = ${request-{{namebase}}:connection-ip}{% for j in range(1,nbbackup|int) %} ${request-{{namebase}}-pseudo-replicating-{{j}}:connection-ip}{% endfor %}
115
116 [request-{{namebase}}-2]
117 <= request-{{namebase}}
118    iplist
119
120 {% for id in range(1,nbbackup|int) %}
121 [request-{{namebase}}-pseudo-replicating-{{id}}-2]
122 <= request-{{namebase}}-pseudo-replicating-{{id}}
123    iplist
124
125 {% endfor %}
126
127
128
129 ## The PBS and their push / pull slaves
130 ## Adding a PBS provides resiliency
131 ## Adding a backup server provides availability
132
133 ## Having 3 backups pulling from the same PBS provides
134 ##only availability, not resiliency
135
136 ## WARNING : SLAVES ARE ALLOCATED AT RANDOM, THIS NEEDS TO BE FIXED.
137
138 [request-pbs-common]
139 <= slap-connection
140 recipe = slapos.cookbook:request
141 software-url = ${slap-connection:software-release-url}
142 software-type = pull-backup
143
144 {% for id in range(1,nbbackup|int) %}
145
146 [request-pbs-{{namebase}}-{{id}}]
147 <= request-pbs-common
148 name = PBS ({{namebase}} / {{id}})
149 return = ssh-key notification-url feeds-url
150 slave = false
151 {% if sla_parameter_dict -%}
152 {%   set sla_key_main = "-sla-%s%s-" % ("pbs", id) -%}
153 {%   set sla_key_secondary = "-sla-%s-" % (id) -%}
154 {%   set sla_key_main_length = sla_key_main | length -%}
155 {%   set sla_key_secondary_length = sla_key_secondary | length -%}
156 {%   set sla_dict = {} -%}
157 {%   for key in sla_parameter_dict.keys() -%}
158 {%     if key.startswith(sla_key_main) -%}
159 {%       do sla_dict.__setitem__(key[sla_key_main_length:], sla_parameter_dict.get(key)) -%}
160 {%     elif key.startswith(sla_key_secondary) and not sla_dict.has_key(key[sla_key_secondary_length:]) -%}
161 {%         do sla_dict.__setitem__(key[sla_key_secondary_length:], sla_parameter_dict.get(key)) -%}
162 {%     endif -%}
163 {%   endfor -%}
164 {%   if sla_dict %}
165 sla = {{ ' '.join(sla_dict.keys()) }}
166 {%     for key, value in sla_dict.iteritems() -%}
167 sla-{{ key }} = {{ value }}
168 {%     endfor %}
169 {%   endif %}
170 {% endif %}
171
172
173 [request-pull-backup-server-{{namebase}}-{{id}}]
174 <= request-pbs-common
175 name = PBS {{id}} pulling from ${request-{{namebase}}:name}
176 config = url name type server-key on-notification notify notification-id title
177 config-url = ${request-{{namebase}}:connection-ssh-url}
178 config-name = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}
179 config-type = pull
180 config-server-key = ${request-{{namebase}}:connection-ssh-public-key}
181 config-on-notification = ${request-{{namebase}}:connection-notification-id}
182 config-notify = ${request-pbs-{{namebase}}-{{id}}:connection-notification-url}
183 config-notification-id = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}-pull
184 config-title = Pulling from {{namebase}}
185 slave = true
186 sla = instance_guid
187 sla-instance_guid = ${request-pbs-{{namebase}}-{{id}}:instance_guid}
188
189 [request-pull-backup-server-{{namebase}}-backup-{{id}}]
190 <= request-pbs-common
191 name = PBS pushing on ${request-{{namebase}}-pseudo-replicating-{{id}}:name}
192 config = url name type server-key on-notification notify notification-id title
193 config-url = ${request-{{namebase}}-pseudo-replicating-{{id}}:connection-ssh-url}
194 config-name = ${request-pull-backup-server-{{namebase}}-{{id}}:config-name}
195 config-type = push
196 config-server-key = ${request-{{namebase}}-pseudo-replicating-{{id}}:connection-ssh-public-key}
197 config-on-notification = ${request-pbs-{{namebase}}-{{id}}:connection-feeds-url}${request-pull-backup-server-{{namebase}}-{{id}}:config-notification-id}
198 config-notify = ${request-{{namebase}}-pseudo-replicating-{{id}}:connection-notification-url}
199 config-notification-id = ${request-{{namebase}}-pseudo-replicating-{{id}}:pbs-notification-id}
200 config-title = Pushing to {{namebase}} backup {{id}}
201 slave = true
202 sla = instance_guid
203 sla-instance_guid = ${request-pbs-{{namebase}}-{{id}}:instance_guid}
204 {% endfor %}
205
206 [slap-parameter]
207 # Default parameters for distributed deployment
208 # I.e state "backup1 of maria should go there, ..."
209 {% for id in range(1,nbbackup|int) %}
210 {{namebase}}{{id}}-computer-guid =
211 pbs-{{namebase}}{{id}}-computer-guid =
212 {% endfor %}
213
214 {% endmacro %}
215