Add endpoints for static DHCP leases
Overview
Add following endpoints:
- /lan/update_client - update DHCP client config
- /lan/delete_client - delete DHCP client
The difference between set_client and update_client is that
set_client should fail to add DHCP client which already exists.
I.e. don't accidentally overwrite existing config when setting new static lease.
update_client should fail to update non-existing client.
delete_client should fail on deleting non-existing client.
Input data
ip, mac and hostname has to be unique, unless you are overwriting the same host - e.g. update just IP address of dhcp client, but keep the same hostname
-
set_client+update_client
{
"type": "object",
"properties": {
"mac": {"type": "string", "format": "macaddress"},
"ip": {
"oneOf": [
{"type": "string", "format": "ipv4"},
{"enum": ["ignore"]}
]
},
"hostname": {"type": "string", "minLength": 1}
},
"additionalProperties": false,
"required": ["ip", "mac", "hostname"]
}
delete_client
{
"type": "object",
"properties": {
"mac": {"type": "string", "format": "macaddress"}
},
"additionalProperties": false,
"required": ["mac"]
}
Foris-controller return either {'result': True} on success or {'result': False, 'reason': 'reason-what-went-wrong'} on failure.
Reasons for failure for particular operations are defined in json schema (set/update/dhcp_client_{set,update,delete}_reply):
return values
But we don't handle these failures in flask yet, because we would need to refactor error handling in reforis and re-test whole reforis again.
So I propose two approaches
- either endpoints will return either
{'result': True}or string with error message (e.g.Cannot add lease). It won't be the great UX at the moment, but we could add better error handling as separate MR. - or return either
{'result': True}on success or{'result': False, 'reason': 'reason-what-went-wrong'}on failure and handle that failure in JS - effectively bypassing API errors
cc: @msasek, @agumroian
Part of #168 (closed)