template-replicated.cfg.in 8.27 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

## Tells the Backupable recipe that we want a backup
[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 22 23
## First, we request with ip-list parameter hardcoded.
## Then, we request the same thing without this.
## XXX-Cedric: is it useful?
24 25 26 27 28 29
[request-{{namebase}}]
<= resilient
   slap-connection
   {{heriteLeader}}
software-type = {{typeexport}}
name = {{namebase}}0
30
return = ssh-public-key ssh-url notification-id ip
31

32 33 34
config =
# Resilient related parameters
  number authorized-key notify ip-list namebase
35
{% if slapparameter_dict is defined %}
36 37
# Software Instance related parameters
  {% for parameter_name in slapparameter_dict.keys() %}{{parameter_name}} {% endfor %}
38
{% endif %}
Marco Mariani's avatar
Marco Mariani committed
39
config-number = 0
40 41 42
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 =
43
# Bubble up all the instance parameters to the requested export instance.
44
{% if slapparameter_dict is defined %}
45 46
{% for parameter_name, parameter_value in slapparameter_dict.items() %}config-{{parameter_name}} = {{parameter_value}}
{% endfor %}
47
{% endif %}
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
{% 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 -%}
68

69 70 71 72 73 74 75 76 77 78 79
{% 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}}
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

Marco Mariani's avatar
Marco Mariani committed
84
config = number authorized-key on-notification ip-list namebase
Marco Mariani's avatar
Marco Mariani committed
85
config-number = {{id}}
86 87 88
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 =
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
{% 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 %}
109

110

111
{% endfor -%}
112 113 114 115 116

[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]
117
<= request-{{namebase}}
118
   iplist
119

120 121
{% for id in range(1,nbbackup|int) %}
[request-{{namebase}}-pseudo-replicating-{{id}}-2]
122
<= request-{{namebase}}-pseudo-replicating-{{id}}
123
   iplist
124

125 126 127 128 129 130 131 132
{% 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
133
## Having 3 backups pulling from the same PBS provides
134 135
##only availability, not resiliency

136
[request-pbs-common]
137 138 139 140
<= slap-connection
recipe = slapos.cookbook:request
software-url = ${slap-connection:software-release-url}
software-type = pull-backup
141 142 143 144 145 146

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

[request-pbs-{{namebase}}-{{id}}]
<= request-pbs-common
name = PBS ({{namebase}} / {{id}})
147 148
return = ssh-key notification-url feeds-url
slave = false
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
{% 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 %}

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 176 177 178 179 180
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
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 186
sla = instance_guid
sla-instance_guid = ${request-pbs-{{namebase}}-{{id}}:instance_guid}
187 188

[request-pull-backup-server-{{namebase}}-backup-{{id}}]
189
<= request-pbs-common
190 191 192 193 194 195 196 197
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}
198
config-name = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}
199 200
config-title = Pushing to {{namebase}} backup {{id}}
slave = true
201 202
sla = instance_guid
sla-instance_guid = ${request-pbs-{{namebase}}-{{id}}:instance_guid}
203 204
{% endfor %}

205 206 207 208 209 210 211 212
[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 %}

213
{% endmacro %}
214