template-replicated.cfg.in 10.1 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
{% if sla_parameter_dict -%}
{%   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 -%}
74

75

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

89
pbs-notification-id = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}-push
90

Marco Mariani's avatar
Marco Mariani committed
91
config = number authorized-key on-notification ip-list namebase
Marco Mariani's avatar
Marco Mariani committed
92
config-number = {{id}}
93 94 95
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 =
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
{% if sla_parameter_dict -%}
{%   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 %}
116

117
{% endfor -%}
118

119

120 121 122 123
[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]
124
<= request-{{namebase}}
125
   iplist
126

127 128 129 130 131 132 133
[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})"
134
  if [[ ! -n "$PUBLIC_KEY_CONTENT" || "$PUBLIC_KEY_CONTENT" == *None* ]]; then
135 136 137 138 139
    exit 1
  fi
output = ${resilient-directory:promise}/resilient-request-{{namebase}}-public-key
mode = 700

140 141
{% for id in range(1,nbbackup|int) %}
[request-{{namebase}}-pseudo-replicating-{{id}}-2]
142
<= request-{{namebase}}-pseudo-replicating-{{id}}
143
   iplist
144

145 146 147 148 149 150 151
[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})"
152
  if [[ ! -n "$PUBLIC_KEY_CONTENT" || "$PUBLIC_KEY_CONTENT" == *None* ]]; then
153 154 155 156 157
    exit 1
  fi
output = ${resilient-directory:promise}/resilient-request-{{namebase}}-pseudo-replicating-{{id}}-public-key
mode = 700

158 159 160 161 162 163 164 165
{% 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
166
## Having 3 backups pulling from the same PBS provides
167 168
##only availability, not resiliency

169
[request-pbs-common]
170 171 172 173
<= slap-connection
recipe = slapos.cookbook:request
software-url = ${slap-connection:software-release-url}
software-type = pull-backup
174 175 176 177 178 179

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

[request-pbs-{{namebase}}-{{id}}]
<= request-pbs-common
name = PBS ({{namebase}} / {{id}})
180 181
return = ssh-key notification-url feeds-url
slave = false
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
{% if sla_parameter_dict -%}
{%   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 %}

203 204 205 206 207 208 209
[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})"
210
  if [[ ! -n "$PUBLIC_KEY_CONTENT" || "$PUBLIC_KEY_CONTENT" == *None* ]]; then
211 212 213 214 215
    exit 1
  fi
output = ${resilient-directory:promise}/resilient-request-{{namebase}}-pseudo-replicating-{{id}}-public-key
mode = 700

216 217

[request-pull-backup-server-{{namebase}}-{{id}}]
218
<= request-pbs-common
219
name = PBS {{id}} pulling from ${request-{{namebase}}:name}
220
config = url name type server-key on-notification notify notification-id title remove-backup-older-than
221 222 223 224 225 226
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
227
config-name = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}
228
config-title = Pulling from {{namebase}}
229
config-remove-backup-older-than = {{ slapparameter_dict.get('remove-backup-older-than', '3B') }}
230
slave = true
231 232
sla = instance_guid
sla-instance_guid = ${request-pbs-{{namebase}}-{{id}}:instance_guid}
233 234

[request-pull-backup-server-{{namebase}}-backup-{{id}}]
235
<= request-pbs-common
236 237 238 239 240 241 242 243
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}
244
config-name = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}
245 246
config-title = Pushing to {{namebase}} backup {{id}}
slave = true
247 248
sla = instance_guid
sla-instance_guid = ${request-pbs-{{namebase}}-{{id}}:instance_guid}
249 250
{% endfor %}

251 252 253 254 255 256 257 258
[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 %}

259
{% endmacro %}
260