Commit
… plugin configure hook, keep empty templates to inform people. (ref; #7361)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,17 +34,45 @@ function kea_services() | |
$services[] = [ | ||
'description' => gettext('KEA DHCPv4 server'), | ||
'pidfile' => '/var/run/kea/kea-dhcp4.kea-dhcp4.pid', | ||
'configd' => [ | ||
'restart' => ['kea restart'], | ||
'start' => ['kea start'], | ||
'stop' => ['kea stop'], | ||
'php' => [ | ||
'restart' => ['kea_configure_do'], | ||
'start' => ['kea_configure_do'], | ||
'stop' => ['kea_service_stop'], | ||
], | ||
'name' => 'kea-dhcpv4', | ||
]; | ||
} | ||
return $services; | ||
} | ||
|
||
function kea_configure() | ||
{ | ||
return [ | ||
'bootup' => ['kea_configure_do'], | ||
'kea_start' => ['kea_configure_do'], | ||
'kea_stop' => ['kea_service_stop'] | ||
]; | ||
} | ||
|
||
function kea_configure_do($verbose = false) | ||
{ | ||
$keaDhcpv4 = new \OPNsense\Kea\KeaDhcpv4(); | ||
if ($keaDhcpv4->isEnabled()) { | ||
service_log('Starting KEA DHCP...', $verbose); | ||
$keaDhcpv4->generateConfig(); | ||
(new \OPNsense\Kea\KeaCtrlAgent())->generateConfig(); | ||
if (isvalidpid('/var/run/kea/kea-dhcp4.kea-dhcp4.pid')) { | ||
mwexec("/usr/local/etc/rc.d/kea onestop", false); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
AdSchellevis
Author
Member
|
||
} | ||
mwexec_bg("/usr/local/etc/rc.d/kea onestart", false); | ||
This comment has been minimized.
Sorry, something went wrong.
fichtner
Member
|
||
service_log("done.\n", $verbose); | ||
} | ||
} | ||
|
||
function kea_service_stop() | ||
{ | ||
mwexec("/usr/local/etc/rc.d/kea onestop", false); | ||
This comment has been minimized.
Sorry, something went wrong.
fichtner
Member
|
||
} | ||
|
||
function kea_syslog() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
kea-dhcp4.conf:/usr/local/etc/kea/kea-dhcp4.conf | ||
rc.conf.d:/etc/rc.conf.d/kea | ||
keactrl.conf:/usr/local/etc/kea/keactrl.conf | ||
kea-ctrl-agent.conf:/usr/local/etc/kea/kea-ctrl-agent.conf |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1 @@ | ||
{ | ||
"Control-agent": { | ||
"http-host": "{{ OPNsense.Kea.ctrl_agent.general.http_host|default('127.0.0.1')}}", | ||
"http-port": {{ OPNsense.Kea.ctrl_agent.general.http_port|default('8000')}}, | ||
"control-sockets": { | ||
"dhcp4": { | ||
"socket-type": "unix", | ||
"socket-name": "/var/run/kea4-ctrl-socket" | ||
}, | ||
"dhcp6": { | ||
"socket-type": "unix", | ||
"socket-name": "/var/run/kea6-ctrl-socket" | ||
}, | ||
"d2": { | ||
"socket-type": "unix", | ||
"socket-name": "/var/run/kea-ddns-ctrl-socket" | ||
} | ||
}, | ||
"loggers": [ | ||
{ | ||
"name": "kea-ctrl-agent", | ||
"output_options": [ | ||
{ | ||
"output": "syslog" | ||
} | ||
], | ||
"severity": "INFO", | ||
"debuglevel": 0 | ||
} | ||
] | ||
} | ||
} | ||
## json output constructed in kea_configure_do() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1 @@ | ||
{%- if not helpers.empty('OPNsense.Kea.dhcp4.general.interfaces') and not helpers.empty('OPNsense.Kea.dhcp4.general.enabled') -%} | ||
{%- set reservation_fields = ({ | ||
'hw-address': 'hw_address', | ||
'ip-address': 'ip_address', | ||
'hostname': 'hostname' | ||
}) -%} | ||
{%- set option_data_defaults = ({ | ||
'domain_name': system.domain | ||
}) -%} | ||
{%- set general = OPNsense.Kea.dhcp4.general -%} | ||
{ | ||
"Dhcp4": { | ||
"valid-lifetime": {{general.valid_lifetime}}, | ||
"interfaces-config": { | ||
"interfaces": ["{{helpers.physical_interfaces(general.interfaces.split(','))|join('","')}}"] | ||
}, | ||
"lease-database": { | ||
"type": "memfile", | ||
"persist": true | ||
}, | ||
"control-socket": { | ||
"socket-type": "unix", | ||
"socket-name": "/var/run/kea4-ctrl-socket" | ||
}, | ||
"loggers": [ | ||
{ | ||
"name": "kea-dhcp4", | ||
"output_options": [ | ||
{ | ||
"output": "syslog" | ||
} | ||
], | ||
"severity": "INFO" | ||
} | ||
], | ||
"subnet4": [ | ||
{% for subnet in helpers.toList('OPNsense.Kea.dhcp4.subnets.subnet4') %} | ||
{ | ||
"id": {{loop.index}}, | ||
"subnet": "{{subnet.subnet}}", | ||
"option-data": [ | ||
{% for od_attr in (subnet.option_data|list + option_data_defaults|list)|unique if subnet.option_data[od_attr]|length > 1 or od_attr in option_data_defaults %} | ||
{ | ||
"name": "{{od_attr.replace('_','-')}}", | ||
"data": {{subnet.option_data[od_attr]|default(option_data_defaults[od_attr])|tojson}} | ||
}{% if not loop.last %},{% endif +%} | ||
{% endfor %} | ||
], | ||
"pools": [ | ||
{% for pool in (subnet.pools|default('')).split("\n") if pool|length > 1%} | ||
{ "pool": "{{pool}}" }{% if not loop.last %},{% endif +%} | ||
{% endfor %} | ||
], | ||
"reservations": [ | ||
{% for reservation in helpers.toList('OPNsense.Kea.dhcp4.reservations.reservation') if reservation.subnet == subnet['@uuid'] %} | ||
{ | ||
{% for res_key, res_prop in reservation_fields.items() if reservation[res_prop]|length > 1 %} | ||
"{{res_key}}": {{reservation[res_prop]|tojson}}{% if not loop.last %},{% endif +%} | ||
{% endfor %} | ||
}{% if not loop.last %},{% endif +%} | ||
{% endfor %} | ||
] | ||
}{% if not loop.last %},{% endif +%} | ||
{% endfor %} | ||
] | ||
{% if not helpers.empty('OPNsense.Kea.ctrl_agent.general.enabled') %} | ||
,"hooks-libraries": [ | ||
{ | ||
"library": "/usr/local/lib/kea/hooks/libdhcp_lease_cmds.so", | ||
"parameters": { } | ||
}, | ||
{% if not helpers.empty('OPNsense.Kea.dhcp4.ha.enabled') %} | ||
{ | ||
"library": "/usr/local/lib/kea/hooks/libdhcp_ha.so", | ||
"parameters": { | ||
"high-availability": [ { | ||
"this-server-name": {{OPNsense.Kea.dhcp4.ha.this_server_name|default(system.hostname)|tojson}}, | ||
"mode": "hot-standby", | ||
"heartbeat-delay": 10000, | ||
"max-response-delay": 60000, | ||
"max-ack-delay": 5000, | ||
"max-unacked-clients": 5, | ||
"sync-timeout": 60000, | ||
"peers": [ | ||
{% for peer in helpers.toList('OPNsense.Kea.dhcp4.ha_peers.peer') %} | ||
{ | ||
"name": {{peer.name|tojson}}, | ||
"role": {{peer.role|tojson}}, | ||
"url": {{peer.url|default('')|tojson}} | ||
}{% if not loop.last %},{% endif +%} | ||
{% endfor %} | ||
] | ||
} ] | ||
} | ||
} | ||
{% endif %} | ||
] | ||
{% endif %} | ||
} | ||
} | ||
{%- endif -%} | ||
## json output constructed in kea_configure_do() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
{% if not helpers.empty('OPNsense.Kea.dhcp4.general.interfaces') and not helpers.empty('OPNsense.Kea.dhcp4.general.enabled') %} | ||
kea_enable="YES" | ||
{% else %} | ||
kea_enable="NO" | ||
{% endif %} |
3 comments
on commit d241cfd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking more.. didn't you just have to add a setup.sh for kea that runs the configuration render via pluginctl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fichtner that might work indeed, let me put that on the list to try. none of the options are great, but also opens the discussion if we need a template helper to render model json output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda like the kea_setup use... but I'm also thinking we could extend the plugin system for this "template" based action and add more shims to make it less code and reusable (for the pseudo-legacy parts we have). All in all I think that's a good direction to keep moving and improving all using newer approaches that are easier to maintain and extend. :)
What are we going to accomplish hardcoding
kea_enable
to NO and still using kea script with "onexxx" actions? I think either we don't want to use rc.d at all or use it in full, which is also what the mutable service controller will do.