template-replicated.cfg.in 10.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
{% macro replicate(namebase, nbbackup, typeexport, typeimport, heriteLeader='', heriteBackup='', slapparameter_dict={}) %}

{% set sla_parameter_dict = {} -%}
# 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 -%}

13

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


21 22
## Tells the Backupable recipe that we want a backup
[resilient]
23
recipe = slapos.cookbook:request
24
config-namebase = {{namebase}}
25
software-url = ${slap-connection:software-release-url}
26 27

## Every request is double to provide the 3 IPs.
28 29 30
## First, we request with ip-list parameter hardcoded.
## Then, we request the same thing without this.
## XXX-Cedric: is it useful?
31 32 33 34 35 36
[request-{{namebase}}]
<= resilient
   slap-connection
   {{heriteLeader}}
software-type = {{typeexport}}
name = {{namebase}}0
37
return = ssh-public-key ssh-url notification-id ip
38 39 40
config =
# Resilient related parameters
  number authorized-key notify ip-list namebase
41
{% if slapparameter_dict is defined %}
42 43
# Software Instance related parameters
  {% for parameter_name in slapparameter_dict.keys() %}{{parameter_name}} {% endfor %}
44
{% endif %}
Marco Mariani's avatar
Marco Mariani committed
45
config-number = 0
46 47 48
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 %}
config-ip-list =
49
# Bubble up all the instance parameters to the requested export instance.
50
{% if slapparameter_dict is defined %}
51 52
{% for parameter_name, parameter_value in slapparameter_dict.items() %}config-{{parameter_name}} = {{parameter_value}}
{% endfor %}
53
{% endif %}
54 55 56 57
{% if sla_parameter_dict == {} -%}
sla = mode
sla-mode = unique_by_network
{% else %}
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
{%   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 -%}
{%   if sla_dict %}
sla = {{ ' '.join(sla_dict.keys()) }}
{%     for key, value in sla_dict.iteritems() -%}
sla-{{ key }} = {{ value }}
{%     endfor -%}
{%   endif -%}
{% endif -%}
77

78 79 80 81 82 83 84 85 86 87 88
{% 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}}
89
return = ssh-public-key ssh-url notification-url ip
90

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

Marco Mariani's avatar
Marco Mariani committed
93
config = number authorized-key on-notification ip-list namebase
Marco Mariani's avatar
Marco Mariani committed
94
config-number = {{id}}
95 96 97
config-authorized-key = ${request-pbs-{{namebase}}-{{id}}:connection-ssh-key}
config-on-notification = ${request-pbs-{{namebase}}-{{id}}:connection-feeds-url}${:pbs-notification-id}
config-ip-list =
98 99 100 101
{% if sla_parameter_dict == {} -%}
sla = mode
sla-mode = unique_by_network
{% else %}
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
{%   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 -%}
{%   if sla_dict %}
sla = {{ ' '.join(sla_dict.keys()) }}
{%     for key, value in sla_dict.iteritems() -%}
sla-{{ key }} = {{ value }}
{%     endfor -%}
{%   endif %}
{% endif %}
121

122 123 124
[publish-connection-informations]
feed-url-{{namebase}}-{{id}}-push = ${request-pbs-{{namebase}}-{{id}}:connection-feeds-url}${request-{{namebase}}-pseudo-replicating-{{id}}:pbs-notification-id}

125
{% endfor -%}
126

127

128 129 130 131
[iplist]
config-ip-list = ${request-{{namebase}}:connection-ip}{% for j in range(1,nbbackup|int) %} ${request-{{namebase}}-pseudo-replicating-{{j}}:connection-ip}{% endfor %}

[request-{{namebase}}-2]
132
<= request-{{namebase}}
133
   iplist
134

135 136 137 138 139 140 141
[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
  PUBLIC_KEY_CONTENT="${request-{{namebase}}-2:connection-ssh-public-key})"
142
  if [[ ! -n "$PUBLIC_KEY_CONTENT" || "$PUBLIC_KEY_CONTENT" == *None* ]]; then
143 144 145 146 147
    exit 1
  fi
output = ${resilient-directory:promise}/resilient-request-{{namebase}}-public-key
mode = 700

148 149
{% for id in range(1,nbbackup|int) %}
[request-{{namebase}}-pseudo-replicating-{{id}}-2]
150
<= request-{{namebase}}-pseudo-replicating-{{id}}
151
   iplist
152

153 154 155 156 157 158 159
[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
  PUBLIC_KEY_CONTENT="${request-{{namebase}}-pseudo-replicating-{{id}}-2: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 189
return = ssh-key notification-url feeds-url
slave = false
190 191 192 193
{% if sla_parameter_dict == {} -%}
sla = mode
sla-mode = unique_by_network
{% else %}
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
{%   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 -%}
{%   if sla_dict %}
sla = {{ ' '.join(sla_dict.keys()) }}
{%     for key, value in sla_dict.iteritems() -%}
sla-{{ key }} = {{ value }}
{%     endfor %}
{%   endif %}
{% endif %}

214 215 216 217 218 219 220
[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})"
221
  if [[ ! -n "$PUBLIC_KEY_CONTENT" || "$PUBLIC_KEY_CONTENT" == *None* ]]; then
222 223 224 225 226
    exit 1
  fi
output = ${resilient-directory:promise}/resilient-request-{{namebase}}-pseudo-replicating-{{id}}-public-key
mode = 700

227 228

[request-pull-backup-server-{{namebase}}-{{id}}]
229
<= request-pbs-common
230
name = PBS {{id}} pulling from ${request-{{namebase}}:name}
231
config = url name type server-key on-notification notify notification-id title remove-backup-older-than
232 233 234 235 236 237
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 243
sla = instance_guid
sla-instance_guid = ${request-pbs-{{namebase}}-{{id}}:instance_guid}
244

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


249
[request-pull-backup-server-{{namebase}}-backup-{{id}}]
250
<= request-pbs-common
251 252 253 254 255 256 257 258
name = PBS pushing on ${request-{{namebase}}-pseudo-replicating-{{id}}:name}
config = url name type server-key on-notification notify notification-id title
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}
259
config-name = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}
260 261
config-title = Pushing to {{namebase}} backup {{id}}
slave = true
262 263
sla = instance_guid
sla-instance_guid = ${request-pbs-{{namebase}}-{{id}}:instance_guid}
264 265
{% endfor %}

266 267 268 269 270 271 272 273
[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 %}

274
{% endmacro %}
275