Resiliency: Only keep 10 increments of backup.
[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}}-{{id}}-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 [request-pbs-common]
137 <= slap-connection
138 recipe = slapos.cookbook:request
139 software-url = ${slap-connection:software-release-url}
140 software-type = pull-backup
141
142 {% for id in range(1,nbbackup|int) %}
143
144 [request-pbs-{{namebase}}-{{id}}]
145 <= request-pbs-common
146 name = PBS ({{namebase}} / {{id}})
147 return = ssh-key notification-url feeds-url
148 slave = false
149 {% if sla_parameter_dict -%}
150 {%   set sla_key_main = "-sla-%s%s-" % ("pbs", id) -%}
151 {%   set sla_key_secondary = "-sla-%s-" % (id) -%}
152 {%   set sla_key_main_length = sla_key_main | length -%}
153 {%   set sla_key_secondary_length = sla_key_secondary | length -%}
154 {%   set sla_dict = {} -%}
155 {%   for key in sla_parameter_dict.keys() -%}
156 {%     if key.startswith(sla_key_main) -%}
157 {%       do sla_dict.__setitem__(key[sla_key_main_length:], sla_parameter_dict.get(key)) -%}
158 {%     elif key.startswith(sla_key_secondary) and not sla_dict.has_key(key[sla_key_secondary_length:]) -%}
159 {%         do sla_dict.__setitem__(key[sla_key_secondary_length:], sla_parameter_dict.get(key)) -%}
160 {%     endif -%}
161 {%   endfor -%}
162 {%   if sla_dict %}
163 sla = {{ ' '.join(sla_dict.keys()) }}
164 {%     for key, value in sla_dict.iteritems() -%}
165 sla-{{ key }} = {{ value }}
166 {%     endfor %}
167 {%   endif %}
168 {% endif %}
169
170
171 [request-pull-backup-server-{{namebase}}-{{id}}]
172 <= request-pbs-common
173 name = PBS {{id}} pulling from ${request-{{namebase}}:name}
174 config = url name type server-key on-notification notify notification-id title remove-backup-older-than
175 config-url = ${request-{{namebase}}:connection-ssh-url}
176 config-type = pull
177 config-server-key = ${request-{{namebase}}:connection-ssh-public-key}
178 config-on-notification = ${request-{{namebase}}:connection-notification-id}
179 config-notify = ${request-pbs-{{namebase}}-{{id}}:connection-notification-url}
180 config-notification-id = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}-pull
181 config-name = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}
182 config-title = Pulling from {{namebase}}
183 config-remove-backup-older-than = {{ slapparameter_dict.get('remove-backup-older-than', '3B') }}
184 slave = true
185 sla = instance_guid
186 sla-instance_guid = ${request-pbs-{{namebase}}-{{id}}:instance_guid}
187
188 [request-pull-backup-server-{{namebase}}-backup-{{id}}]
189 <= request-pbs-common
190 name = PBS pushing on ${request-{{namebase}}-pseudo-replicating-{{id}}:name}
191 config = url name type server-key on-notification notify notification-id title
192 config-url = ${request-{{namebase}}-pseudo-replicating-{{id}}:connection-ssh-url}
193 config-type = push
194 config-server-key = ${request-{{namebase}}-pseudo-replicating-{{id}}:connection-ssh-public-key}
195 config-on-notification = ${request-pbs-{{namebase}}-{{id}}:connection-feeds-url}${request-pull-backup-server-{{namebase}}-{{id}}:config-notification-id}
196 config-notify = ${request-{{namebase}}-pseudo-replicating-{{id}}:connection-notification-url}
197 config-notification-id = ${request-{{namebase}}-pseudo-replicating-{{id}}:pbs-notification-id}
198 config-name = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}
199 config-title = Pushing to {{namebase}} backup {{id}}
200 slave = true
201 sla = instance_guid
202 sla-instance_guid = ${request-pbs-{{namebase}}-{{id}}:instance_guid}
203 {% endfor %}
204
205 [slap-parameter]
206 # Default parameters for distributed deployment
207 # I.e state "backup1 of maria should go there, ..."
208 {% for id in range(1,nbbackup|int) %}
209 {{namebase}}{{id}}-computer-guid =
210 pbs-{{namebase}}{{id}}-computer-guid =
211 {% endfor %}
212
213 {% endmacro %}
214