kea-dhcp-ha.j2 2.24 KB
Newer Older
Pietsch, Martin's avatar
Pietsch, Martin committed
1
{% macro ha(ipversion = "ipv4") %}
Pietsch, Martin's avatar
Pietsch, Martin committed
2 3 4 5 6
{%     set ha_servers = [] %}
{%-    for fctnhst in function_hosts -%}
{%-      set nodenetwork = hostvars[fctnhst].network %}
{%-      if nodenetwork.devices is defined %}
{%-        for ifname, ifdata in nodenetwork.devices.items() if ifdata.services is defined and ("dhcp-ha" in (ifdata.services | default([]))) %}
Pietsch, Martin's avatar
Pietsch, Martin committed
7
{%-          set has = {"name": fctnhst} %}
Pietsch, Martin's avatar
Pietsch, Martin committed
8
{%-          if ipversion == "ipv4" %}
Pietsch, Martin's avatar
Pietsch, Martin committed
9
{%-            do has.update({"url": 'http://%s:%s/' | format(ifdata.ipv4 | default("127.0.0.1"), kea_control_agent_port)}) %}
Pietsch, Martin's avatar
Pietsch, Martin committed
10
{%-          else %}
Pietsch, Martin's avatar
Pietsch, Martin committed
11
{%-            do has.update({"url": 'http://[%s]:%s/' | format(ifdata.ipv6 | default("::1"), kea_control_agent_port)}) %}
Pietsch, Martin's avatar
Pietsch, Martin committed
12 13 14 15 16 17 18 19 20 21 22 23
{%-          endif %}
{%-          if fctnhst != dhcp_primary_server or fctnhst != dhcp_secondary_server %}
{%-            do has.update({"auto-failover": false, "role": "backup"}) %}
{%-          elif fctnhst == dhcp_primary_server %}
{%-            do has.update({"auto-failover": true, "role": "primary"}) %}
{%-          else %}
{%-            if kea_ha_mode == "loadbalancing" %}
{%-              do has.update({"auto-failover": true, "role": "secondary"}) %}
{%-            else %}
{%-              do has.update({"auto-failover": true, "role": "standby"}) %}
{%-            endif %}
{%-          endif %}
Pietsch, Martin's avatar
Pietsch, Martin committed
24
{%-          do ha_servers.append(has) -%}
Pietsch, Martin's avatar
Pietsch, Martin committed
25 26 27 28
{%-        endfor %}
{%-      endif %}
{%-    endfor %}   

Pietsch, Martin's avatar
Pietsch, Martin committed
29
{%    if (ha_servers | length) > 1 %}
Pietsch, Martin's avatar
Pietsch, Martin committed
30 31
    "hooks-libraries": [
       {
Pietsch, Martin's avatar
Pietsch, Martin committed
32
          "library": "{{ system_app_root }}/lib/hooks/libdhcp_lease_cmds.so",
Pietsch, Martin's avatar
Pietsch, Martin committed
33 34 35
          "parameters": { }
       },
       {
Pietsch, Martin's avatar
Pietsch, Martin committed
36
          "library": "{{ system_app_root }}/lib/hooks/libdhcp_ha.so",
Pietsch, Martin's avatar
Pietsch, Martin committed
37 38
          "parameters": {
              "high-availability": [ {
Pietsch, Martin's avatar
Pietsch, Martin committed
39
                 "this-server-name": "{{ inventory_hostname }}",
Pietsch, Martin's avatar
Pietsch, Martin committed
40
{%    if kea_ha_mode == "loadbalancing" %}
Pietsch, Martin's avatar
Pietsch, Martin committed
41
                 "mode": "load-balancing",
Pietsch, Martin's avatar
Pietsch, Martin committed
42
{%    else %}
Pietsch, Martin's avatar
Pietsch, Martin committed
43
                 "mode": "hot-standby",
Pietsch, Martin's avatar
Pietsch, Martin committed
44
{%    endif %}
Pietsch, Martin's avatar
Pietsch, Martin committed
45 46 47 48
                 "heartbeat-delay": 10000,
                 "max-response-delay": 10000,
                 "max-ack-delay": 5000,
                 "max-unacked-clients": 5,
Pietsch, Martin's avatar
Pietsch, Martin committed
49
                 "peers": {{ ha_servers | to_nice_json(indent=8) }}
Pietsch, Martin's avatar
Pietsch, Martin committed
50 51 52
              }
          ]
      }
Pietsch, Martin's avatar
Pietsch, Martin committed
53 54
     }
  ],
Pietsch, Martin's avatar
Pietsch, Martin committed
55 56
{%-    endif -%}
{%- endmacro %}