template-replicated.cfg.in 11.4 KB
Newer Older
1
{% macro replicate(namebase, nbbackup, typeexport, typeimport, heriteLeader='', heriteBackup='', slapparameter_dict={}, monitor_parameter_dict={}) %}
2 3

{% set sla_parameter_dict = {} -%}
4 5 6
{% set monitor_dict = monitor_parameter_dict.get('parameter', {}) -%}
{% set monitor_return = ' '.join(monitor_parameter_dict.get('return', [])) -%}
{% set monitor_url_list = [] -%}
7 8 9 10 11 12 13 14 15
# prepare sla-parameters
{% if slapparameter_dict is defined -%}
{%   for key in slapparameter_dict.keys() -%}
{%     if key.startswith('-sla-') -%}
{%       do sla_parameter_dict.__setitem__(key, slapparameter_dict.pop(key)) -%}
{%     endif -%}
{%   endfor -%}
{% endif -%}

16

17 18 19 20 21 22 23
[resilient-directory]
recipe = slapos.cookbook:mkdirectory
home = ${buildout:directory}
etc = ${:home}/etc
promise = ${:etc}/promise


24 25
## Tells the Backupable recipe that we want a backup
[resilient]
26
recipe = slapos.cookbook:request
27
config-namebase = {{namebase}}
28
software-url = ${slap-connection:software-release-url}
29 30 31 32 33 34 35

[request-{{namebase}}]
<= resilient
   slap-connection
   {{heriteLeader}}
software-type = {{typeexport}}
name = {{namebase}}0
36 37
return = ssh-public-key ssh-url notification-id ip {{ monitor_return }}

Marco Mariani's avatar
Marco Mariani committed
38
config-number = 0
39 40
config-authorized-key = {% for id in range(1,nbbackup|int) %} ${request-pbs-{{namebase}}-{{id}}:connection-ssh-key}{% endfor %}
config-notify = {% for id in range(1,nbbackup|int) %} ${request-pbs-{{namebase}}-{{id}}:connection-notification-url}{% endfor %}
41
config-name = {{namebase}}0
42
# Bubble up all the instance parameters to the requested export instance.
43
{% if slapparameter_dict is defined %}
44
{% for parameter_name, parameter_value in slapparameter_dict.items() %}
45
{% if parameter_value is string %}
46
config-{{parameter_name}} = {{ parameter_value.split('\n') | join('\n  ') }}
47 48 49
{% else %}
config-{{parameter_name}} = {{ parameter_value }}
{% endif %}
50
{% endfor %}
51
{% endif %}
52 53 54
{% for key, value in monitor_dict.iteritems() -%}
config-{{ key }} = {{ value }}
{% endfor -%}
55 56 57
{% if sla_parameter_dict == {} -%}
sla-mode = unique_by_network
{% else %}
58 59 60 61 62 63 64 65 66 67 68 69
{%   set sla_key_main = "-sla-%s%s-" % (namebase, 0) -%}
{%   set sla_key_secondary = "-sla-%s-" % (0) -%}
{%   set sla_key_main_length = sla_key_main | length -%}
{%   set sla_key_secondary_length = sla_key_secondary | length -%}
{%   set sla_dict = {} -%}
{%   for key in sla_parameter_dict.keys() -%}
{%     if key.startswith(sla_key_main) -%}
{%       do sla_dict.__setitem__(key[sla_key_main_length:], sla_parameter_dict.get(key)) -%}
{%     elif key.startswith(sla_key_secondary) and not sla_dict.has_key(key[sla_key_secondary_length:]) -%}
{%         do sla_dict.__setitem__(key[sla_key_secondary_length:], sla_parameter_dict.get(key)) -%}
{%     endif -%}
{%   endfor -%}
70
{%   for key, value in sla_dict.iteritems() -%}
71
sla-{{ key }} = {{ value }}
72
{%   endfor -%}
73
{% endif -%}
74

75 76 77 78
{% if 'monitor-base-url' in monitor_return and not monitor_parameter_dict.get('set-monitor-url', False) -%}
{% do monitor_url_list.append('${request-' ~ namebase ~ ':connection-monitor-base-url}') -%}
{% endif -%}

79 80 81 82 83 84 85 86 87 88 89
{% for id in range(1,nbbackup|int) %}

[request-{{namebase}}-pseudo-replicating-{{id}}]
<= slap-connection
   resilient
   {{heriteBackup}}
recipe = slapos.cookbook:request
name = {{namebase}}{{id}}

software-url = ${slap-connection:software-release-url}
software-type = {{typeimport}}
90
return = ssh-public-key ssh-url notification-url ip takeover-url takeover-password  {{ monitor_return }}
91

92
pbs-notification-id = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}-push
93

94 95 96 97
{% if slapparameter_dict.get("software-root") %}
config-software-root = {{ slapparameter_dict.get("software-root") }}
{% endif %}

Marco Mariani's avatar
Marco Mariani committed
98
config-number = {{id}}
99
config-name = {{namebase}}{{id}}
100 101
config-authorized-key = ${request-pbs-{{namebase}}-{{id}}:connection-ssh-key}
config-on-notification = ${request-pbs-{{namebase}}-{{id}}:connection-feeds-url}${:pbs-notification-id}
102 103 104
{% for key, value in monitor_dict.iteritems() -%}
config-{{ key }} = {{ value }}
{% endfor -%}
105 106 107
{% if sla_parameter_dict == {} -%}
sla-mode = unique_by_network
{% else %}
108 109 110 111 112 113 114 115 116 117 118 119
{%   set sla_key_main = "-sla-%s%s-" % (namebase, id) -%}
{%   set sla_key_secondary = "-sla-%s-" % (id) -%}
{%   set sla_key_main_length = sla_key_main | length -%}
{%   set sla_key_secondary_length = sla_key_secondary | length -%}
{%   set sla_dict = {} -%}
{%   for key in sla_parameter_dict.keys() -%}
{%     if key.startswith(sla_key_main) -%}
{%       do sla_dict.__setitem__(key[sla_key_main_length:], sla_parameter_dict.get(key)) -%}
{%     elif key.startswith(sla_key_secondary) and not sla_dict.has_key(key[sla_key_secondary_length:]) -%}
{%         do sla_dict.__setitem__(key[sla_key_secondary_length:], sla_parameter_dict.get(key)) -%}
{%     endif -%}
{%   endfor -%}
120
{%   for key, value in sla_dict.iteritems() -%}
121
sla-{{ key }} = {{ value }}
122
{%   endfor -%}
123
{% endif %}
124

125
[publish-connection-information]
126
feed-url-{{namebase}}-{{id}}-push = ${request-pbs-{{namebase}}-{{id}}:connection-feeds-url}${request-{{namebase}}-pseudo-replicating-{{id}}:pbs-notification-id}
127 128
takeover-{{namebase}}-{{id}}-url = ${request-{{namebase}}-pseudo-replicating-{{id}}:connection-takeover-url}
takeover-{{namebase}}-{{id}}-password = ${request-{{namebase}}-pseudo-replicating-{{id}}:connection-takeover-password}
129

130 131 132 133
{% if 'monitor-base-url' in monitor_return -%}
{% do monitor_url_list.append('${request-' ~ namebase ~ '-pseudo-replicating-' ~ id ~ ':connection-monitor-base-url}') -%}
{% endif -%}

134
{% endfor -%}
135

136

137

138 139 140 141 142 143
[resilient-request-{{namebase}}-public-key-promise]
# Check that public-key-value parameter exists and is not empty
# XXX: maybe we should consider empty values to be non-nexistent.
recipe = collective.recipe.template
# XXX: don't use system executable
input = inline:#!/bin/sh
144
  PUBLIC_KEY_CONTENT="${request-{{namebase}}:connection-ssh-public-key})"
145
  if [[ ! -n "$PUBLIC_KEY_CONTENT" || "$PUBLIC_KEY_CONTENT" == *None* ]]; then
146 147 148 149 150
    exit 1
  fi
output = ${resilient-directory:promise}/resilient-request-{{namebase}}-public-key
mode = 700

151
{% for id in range(1,nbbackup|int) %}
152

153 154 155 156 157 158
[resilient-request-{{namebase}}-pseudo-replicating-{{id}}-public-key-promise]
# Check that public-key-value parameter exists and is not empty
# XXX: maybe we should consider empty values to be non-nexistent.
recipe = collective.recipe.template
# XXX: don't use system executable
input = inline:#!/bin/sh
159
  PUBLIC_KEY_CONTENT="${request-{{namebase}}-pseudo-replicating-{{id}}:connection-ssh-public-key})"
160
  if [[ ! -n "$PUBLIC_KEY_CONTENT" || "$PUBLIC_KEY_CONTENT" == *None* ]]; then
161 162 163 164 165
    exit 1
  fi
output = ${resilient-directory:promise}/resilient-request-{{namebase}}-pseudo-replicating-{{id}}-public-key
mode = 700

166 167 168 169 170 171 172 173
{% endfor %}



## The PBS and their push / pull slaves
## Adding a PBS provides resiliency
## Adding a backup server provides availability

Cédric de Saint Martin's avatar
Cédric de Saint Martin committed
174
## Having 3 backups pulling from the same PBS provides
175 176
##only availability, not resiliency

177
[request-pbs-common]
178 179 180 181
<= slap-connection
recipe = slapos.cookbook:request
software-url = ${slap-connection:software-release-url}
software-type = pull-backup
182 183 184 185 186 187

{% for id in range(1,nbbackup|int) %}

[request-pbs-{{namebase}}-{{id}}]
<= request-pbs-common
name = PBS ({{namebase}} / {{id}})
188
config-ignore-known-hosts-file = ${slap-parameter:ignore-known-hosts-file}
189 190 191 192 193
config-monitor-title = PBS ${slap-connection:computer-id}-{{namebase}}-{{id}}
{% for key, value in monitor_dict.iteritems() -%}
config-{{ key }} = {{ value }}
{% endfor -%}
return = ssh-key notification-url feeds-url  {{ monitor_return }}
194
slave = false
195 196 197
{% if sla_parameter_dict == {} -%}
sla-mode = unique_by_network
{% else %}
198 199 200 201 202 203 204 205 206 207 208 209
{%   set sla_key_main = "-sla-%s%s-" % ("pbs", id) -%}
{%   set sla_key_secondary = "-sla-%s-" % (id) -%}
{%   set sla_key_main_length = sla_key_main | length -%}
{%   set sla_key_secondary_length = sla_key_secondary | length -%}
{%   set sla_dict = {} -%}
{%   for key in sla_parameter_dict.keys() -%}
{%     if key.startswith(sla_key_main) -%}
{%       do sla_dict.__setitem__(key[sla_key_main_length:], sla_parameter_dict.get(key)) -%}
{%     elif key.startswith(sla_key_secondary) and not sla_dict.has_key(key[sla_key_secondary_length:]) -%}
{%         do sla_dict.__setitem__(key[sla_key_secondary_length:], sla_parameter_dict.get(key)) -%}
{%     endif -%}
{%   endfor -%}
210
{%   for key, value in sla_dict.iteritems() -%}
211
sla-{{ key }} = {{ value }}
212
{%   endfor %}
213 214
{% endif %}

215 216 217 218 219 220 221
[resilient-request-pbs-{{namebase}}-{{id}}-public-key-promise]
# Check that public-key-value parameter exists and is not empty
# XXX: maybe we should consider empty values to be non-nexistent.
recipe = collective.recipe.template
# XXX: don't use system executable
input = inline:#!/bin/sh
  PUBLIC_KEY_CONTENT="${request-pbs-{{namebase}}-{{id}}:connection-ssh-key}:connection-ssh-key})"
222
  if [[ ! -n "$PUBLIC_KEY_CONTENT" || "$PUBLIC_KEY_CONTENT" == *None* ]]; then
223 224 225 226 227
    exit 1
  fi
output = ${resilient-directory:promise}/resilient-request-{{namebase}}-pseudo-replicating-{{id}}-public-key
mode = 700

228 229

[request-pull-backup-server-{{namebase}}-{{id}}]
230
<= request-pbs-common
231 232 233 234 235 236 237
name = PBS {{id}} pulling from ${request-{{namebase}}:name}
config-url = ${request-{{namebase}}:connection-ssh-url}
config-type = pull
config-server-key = ${request-{{namebase}}:connection-ssh-public-key}
config-on-notification = ${request-{{namebase}}:connection-notification-id}
config-notify = ${request-pbs-{{namebase}}-{{id}}:connection-notification-url}
config-notification-id = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}-pull
238
config-name = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}
239
config-title = Pulling from {{namebase}}
240
config-remove-backup-older-than = {{ slapparameter_dict.get('remove-backup-older-than', '2W') }}
241
slave = true
242
sla-instance_guid = ${request-pbs-{{namebase}}-{{id}}:instance_guid}
243

244
[publish-connection-information]
245 246
feed-url-{{namebase}}-{{id}}-pull = ${request-pbs-{{namebase}}-{{id}}:connection-feeds-url}${request-pull-backup-server-{{namebase}}-{{id}}:config-notification-id}

247 248 249 250 251 252 253 254 255 256 257
{% if 'monitor-base-url' in monitor_return -%}
{% do monitor_url_list.append('${request-pbs-' ~ namebase ~ '-' ~ id ~ ':connection-monitor-base-url}') -%}
{% endif -%}

{% if monitor_parameter_dict.get('set-monitor-url', False) -%}
[request-{{namebase}}]
config-monitor-url-list = {{ monitor_url_list | join(' ') }}
{% else -%}
[monitor-conf-parameters]
monitor-url-list = {{ monitor_url_list | join(' ') }}
{% endif -%}
258

259
[request-pull-backup-server-{{namebase}}-backup-{{id}}]
260
<= request-pbs-common
261 262 263 264 265 266 267
name = PBS pushing on ${request-{{namebase}}-pseudo-replicating-{{id}}:name}
config-url = ${request-{{namebase}}-pseudo-replicating-{{id}}:connection-ssh-url}
config-type = push
config-server-key = ${request-{{namebase}}-pseudo-replicating-{{id}}:connection-ssh-public-key}
config-on-notification = ${request-pbs-{{namebase}}-{{id}}:connection-feeds-url}${request-pull-backup-server-{{namebase}}-{{id}}:config-notification-id}
config-notify = ${request-{{namebase}}-pseudo-replicating-{{id}}:connection-notification-url}
config-notification-id = ${request-{{namebase}}-pseudo-replicating-{{id}}:pbs-notification-id}
268
config-name = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}
269 270
config-title = Pushing to {{namebase}} backup {{id}}
slave = true
271
sla-instance_guid = ${request-pbs-{{namebase}}-{{id}}:instance_guid}
272 273
{% endfor %}

274 275 276 277 278 279 280
[slap-parameter]
# Default parameters for distributed deployment
# I.e state "backup1 of maria should go there, ..."
{% for id in range(1,nbbackup|int) %}
{{namebase}}{{id}}-computer-guid =
pbs-{{namebase}}{{id}}-computer-guid =
{% endfor %}
281
ignore-known-hosts-file = false
282

283
{% endmacro %}
284