Commit edb84236 authored by Pietsch, Martin's avatar Pietsch, Martin

add templates for dhcp4 and dhcp6

parent c9c868a5
{
"Dhcp4": {
{% if (dhcp_network_interfaces["default"] | default([])) != [] %}
"interfaces-config": {
"interfaces": {{ dhcp_network_interfaces["default"] | to_json() }},
"dhcp-socket-type": "udp"
},
{% endif %}
"control-socket": {
"socket-type": "unix",
"socket-name": "/tmp/kea-dhcp4-ctrl.sock"
},
{% if dhcp_backend == "memfile" %}
"lease-database": {
"type": "memfile",
"name": "/var/db/kea/kea-leases4"
},
{% elif dhcp_backend == "cassandra" %}
"lease-database": {
"type": "cql",
"keyspace": "{{ dhcp_db_dbname }}"
"contact-points": "{{ dhcp_db_host }}"
{% if dhcp_db_port is defined %}
"port": "{{ dhcp_db_port }}"
{% endif %}
},
{% else %}
"lease-database": {
"type": "{{ dhcp_backend }}",
"name": "{{ dhcp_db_dbname }}",
"host": "{{ dhcp_db_host }}",
{% if dhcp_db_port is defined %}
"port": "{{ dhcp_db_port }}"
{% endif %}
"user": "{{ dhcp_db_user }}"
"password": "{{ dhcp_db_password | default("") }}"
},
"hosts-database": {
"type": "{{ dhcp_backend }}",
"name": "{{ dhcp_db_dbname }}",
"host": "{{ dhcp_db_host }}",
{% if dhcp_db_port is defined %}
"port": "{{ dhcp_db_port }}"
{% endif %}
"user": "{{ dhcp_db_user }}"
"password": "{{ dhcp_db_password | default("") }}"
},
{% endif %}
"valid-lifetime": {{ dhcp_leasetimes["default"] }},
{%- set ipv4subnets = [] -%}
{%- for netclassname, netclass in network.classes.items() if netclass.dhcp is defined -%}
{%- if netclass.dhcp.ipv4 is defined -%}
{%- set ipv4subnet = {
"id": loop.index,
"pools": [ { "pool": "%s-%s" | format(netclass.dhcp.ipv4.from, netclass.dhcp.ipv4.to) } ]
} -%}
{%- if netclassname in dhcp_network_relays -%}
{%- do ipv4subnet.update({"relay": []}) -%}
{%- for rly in dhcp_network_relays[netclassname] if (rly | ipv4) != False -%}
{%- do ipv4subnet.relay.append(rly) -%}
{%- endfor -%}
{%- endif -%}
{%- set ods = [] -%}
{%- set hrsvs = [] -%}
{%- do ipv4subnet.update({"subnet": "%s/%s" | format(netclass.ipv4.gateway, netclass.ipv4.prefix) | ipaddr('network/prefix')}) -%}
{%- if netclass.dhcp.ipv4.nextserver is defined -%}
{%- do ods.append({"name": "tftp-server-name",
"code": 66,
"space": "dhcp4",
"csv-format": true,
"data": netclass.dhcp.ipv4.nextserver }) -%}
{%- do ipv4subnet.update({"next-server": netclass.dhcp.ipv4.nextserver }) -%}
{%- endif -%}
{%- if netclass.dhcp.bootfile is defined -%}
{%- do ods.append({"name": "boot-file-name",
"code": 67,
"space": "dhcp4",
"csv-format": true,
"data": netclass.dhcp.bootfile }) -%}
{%- endif -%}
{%- if netclass.dns is defined -%}
{%- if netclass.dns.nameservers is defined -%}
{%- if netclass.dns.nameservers.ipv4 is defined -%}
{%- do ods.append({"name": "domain-name-servers",
"code": 6,
"space": "dhcp4",
"csv-format": true,
"data": netclass.dns.nameservers.ipv4 }) -%}
{%- endif -%}
{%- endif -%}
{%- if netclass.dns.domain is defined -%}
{%- do ods.append({"name": "domain-name",
"code": 15,
"space": "dhcp4",
"csv-format": true,
"data": netclass.dns.domain }) -%}
{%- endif -%}
{%- endif -%}
{%- if dhcp_backend == "memfile" or dhcp_backend == "cassandra" -%}
{%- for host in groups['all'] -%}
{%- set nodenetwork = hostvars[host].network -%}
{%- if nodenetwork.devices is defined -%}
{%- for ifname, ifdata in nodenetwork.devices.items() if (nodenetwork.hostname | default(host)) != "localhost" and ifdata.class == netclassname -%}
{%- if ifdata.mac is defined -%}
{%- set hrsv = {"hw-address": ifdata.mac, "ip-address": ifdata.ipv4 } -%}
{%- if netclass.dns is defined -%}
{%- do hrsv.update({"hostname": "%s%s" | format(nodenetwork.hostname | default(host), netclass.dns.hostnamesuffix | default("")) }) -%}
{%- else -%}
{%- do hrsv.update({"hostname": nodenetwork.hostname | default(host) }) -%}
{%- endif -%}
{%- do hrsvs.append(hrsv) -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- if (ods | length) > 0 -%}
{%- do ipv4subnet.update({"option-data": ods}) -%}
{%- endif -%}
{%- if (hrsvs | length) > 0 -%}
{%- do ipv4subnet.update({"reservations": hrsvs}) -%}
{%- endif -%}
{%- do ipv4subnets.append(ipv4subnet) -%}
{%- endif -%}
{% endfor %}
"subnet4": {{ ipv4subnets | to_nice_json(indent=8) }}
},
"Logging":
{
"loggers": [
{
"name": "kea-dhcp4",
"output_options": [
{
"output": "/var/log/kea-dhcp4.log"
}
],
"severity": "INFO",
}
]
}
}
{
"Dhcp6": {
{% if (dhcp_network_interfaces["default"] | default([])) != [] %}
"interfaces-config": {
"interfaces": {{ dhcp_network_interfaces["default"] | to_json() }}
},
{% endif %}
"control-socket": {
"socket-type": "unix",
"socket-name": "/tmp/kea-dhcp6-ctrl.sock"
},
{% if dhcp_backend == "memfile" %}
"lease-database": {
"type": "memfile",
"name": "/var/db/kea/kea-leases6"
},
{% elif dhcp_backend == "cassandra" %}
"lease-database": {
"type": "cql",
"keyspace": "{{ dhcp_db_dbname }}"
"contact-points": "{{ dhcp_db_host }}"
{% if dhcp_db_port is defined %}
"port": "{{ dhcp_db_port }}"
{% endif %}
},
{% else %}
"lease-database": {
"type": "{{ dhcp_backend }}",
"name": "{{ dhcp_db_dbname }}",
"host": "{{ dhcp_db_host }}",
{% if dhcp_db_port is defined %}
"port": "{{ dhcp_db_port }}"
{% endif %}
"user": "{{ dhcp_db_user }}"
"password": "{{ dhcp_db_password | default("") }}"
},
"hosts-database": {
"type": "{{ dhcp_backend }}",
"name": "{{ dhcp_db_dbname }}",
"host": "{{ dhcp_db_host }}",
{% if dhcp_db_port is defined %}
"port": "{{ dhcp_db_port }}"
{% endif %}
"user": "{{ dhcp_db_user }}"
"password": "{{ dhcp_db_password | default("") }}"
},
{% endif %}
"valid-lifetime": {{ dhcp_leasetimes["default"] }},
{%- set ipv6subnets = [] -%}
{%- for netclassname, netclass in network.classes.items() if netclass.dhcp is defined -%}
{%- if netclass.dhcp.ipv6 is defined -%}
{%- set ipv6subnet = {
"id": loop.index,
"pools": [ { "pool": "%s-%s" | format(netclass.dhcp.ipv6.from, netclass.dhcp.ipv6.to) } ]
} -%}
{%- if netclassname in dhcp_network_relays -%}
{%- do ipv6subnet.update({"relay": []}) -%}
{%- for rly in dhcp_network_relays[netclassname] if (rly | ipv6) != False -%}
{%- do ipv6subnet.relay.append(rly) -%}
{%- endfor -%}
{%- set ods = [] -%}
{%- set hrsvs = [] -%}
{%- do ipv6subnet.update({"subnet": "%s/%s" | format(netclass.ipv6.gateway, netclass.ipv6.prefix) | ipaddr('network/prefix')}) -%}
{%- if netclass.dhcp.bootfile is defined and netclass.dhcp.ipv6.baseurl -%}
{%- do ods.append({"name": "bootfile-url",
"code": 59,
"space": "dhcp6",
"csv-format": true,
"data": '%s/%s' | format(netclass.dhcp.ipv6.baseurl, netclass.dhcp.bootfile) }) -%}
{%- endif -%}
{%- if netclass.dns is defined -%}
{%- if netclass.dns.nameservers is defined -%}
{%- if netclass.dns.nameservers.ipv6 is defined -%}
{%- do ods.append({"name": "dns-servers",
"code": 23,
"space": "dhcp6",
"csv-format": true,
"data": netclass.dns.nameservers.ipv6 }) -%}
{%- endif -%}
{%- endif -%}
{%- if netclass.dns.domain is defined -%}
{%- do ods.append({"name": "domain-search",
"code": 24,
"space": "dhcp6",
"csv-format": true,
"data": netclass.dns.domain }) -%}
{%- endif -%}
{%- endif -%}
{%- if dhcp_backend == "memfile" or dhcp_backend == "cassandra" -%}
{%- for host in groups['all'] -%}
{%- set nodenetwork = hostvars[host].network -%}
{%- if nodenetwork.devices is defined -%}
{%- for ifname, ifdata in nodenetwork.devices.items() if (nodenetwork.hostname | default(host)) != "localhost" and ifdata.class == netclassname -%}
{%- set hrsv = {"hw-address": ifdata.mac, "ip-address": ifdata.ipv6 } -%}
{%- if netclass.dns is defined -%}
{%- do hrsv.update({"hostname": "%s%s" | format(nodenetwork.hostname | default(host),netclass.dns.hostnamesuffix | default("")) }) -%}
{%- else -%}
{%- do hrsv.update({"hostname": nodenetwork.hostname | default(host) }) -%}
{%- endif -%}
{%- do hrsvs.append(hrsv) -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- if (ods | length) > 0 -%}
{%- do ipv6subnet.update({"option-data": ods}) -%}
{%- endif -%}
{%- if (hrsvs | length) > 0 -%}
{%- do ipv6subnet.update({"reservations": hrsvs}) -%}
{%- endif -%}
{%- do ipv6subnets.append(ipv6subnet) -%}
{%- endif -%}
{%- endif -%}
{% endfor %}
"subnet6": {{ ipv6subnets | to_nice_json(indent=8) }}
},
"Logging":
{
"loggers": [
{
"name": "kea-dhcp6",
"output_options": [
{
"output": "/var/log/kea-dhcp6.log"
}
],
"severity": "INFO",
}
]
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment