kea-dhcp-ha.j2 2.25 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 %}   

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