From e80018d0307d08925b298f1ea1597a70d86f5b58 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Wed, 16 Oct 2019 23:10:01 +0200 Subject: [PATCH] [393-global-search-through-leases-by-mac-or-hostname-w-o-specifying-a-subnet-id] Added new command docs --- doc/sphinx/api-files.txt | 5 ++ doc/sphinx/api/lease4-get-by-client-id.json | 20 +++++++ doc/sphinx/api/lease4-get-by-hostname.json | 20 +++++++ doc/sphinx/api/lease4-get-by-hw-address.json | 20 +++++++ doc/sphinx/api/lease6-get-by-duid.json | 20 +++++++ doc/sphinx/api/lease6-get-by-hostname.json | 20 +++++++ doc/sphinx/arm/hooks-lease-cmds.rst | 58 ++++++++++++++++++++ src/hooks/dhcp/lease_cmds/lease_cmds.cc | 20 +++---- 8 files changed, 171 insertions(+), 12 deletions(-) create mode 100644 doc/sphinx/api/lease4-get-by-client-id.json create mode 100644 doc/sphinx/api/lease4-get-by-hostname.json create mode 100644 doc/sphinx/api/lease4-get-by-hw-address.json create mode 100644 doc/sphinx/api/lease6-get-by-duid.json create mode 100644 doc/sphinx/api/lease6-get-by-hostname.json diff --git a/doc/sphinx/api-files.txt b/doc/sphinx/api-files.txt index b358a0a93b..248bea7403 100644 --- a/doc/sphinx/api-files.txt +++ b/doc/sphinx/api-files.txt @@ -26,6 +26,9 @@ api/ha-sync.json api/lease4-add.json api/lease4-del.json api/lease4-get-all.json +api/lease4-get-by-client-id.json +api/lease4-get-by-hostname.json +api/lease4-get-by-hw-address.json api/lease4-get.json api/lease4-update.json api/lease4-wipe.json @@ -33,6 +36,8 @@ api/lease6-add.json api/lease6-bulk-apply.json api/lease6-del.json api/lease6-get-all.json +api/lease6-get-by-duid.json +api/lease6-get-by-hostname.json api/lease6-get.json api/lease6-update.json api/lease6-wipe.json diff --git a/doc/sphinx/api/lease4-get-by-client-id.json b/doc/sphinx/api/lease4-get-by-client-id.json new file mode 100644 index 0000000000..a3a199cfdb --- /dev/null +++ b/doc/sphinx/api/lease4-get-by-client-id.json @@ -0,0 +1,20 @@ +{ + "avail": "1.7.1", + "brief": [ + "This command retrieves all IPv4 leases with the specified client id." + ], + "cmd-syntax": [ + "{", + " \"command\": \"lease4-get-by-client-id\",", + " \"arguments\": {", + " \"client-id\": \"42:42:42:42:42:42:42:42\"", + " }", + "}" + ], + "description": "See ", + "hook": "lease_cmds", + "name": "lease4-get-by-client-id", + "support": [ + "kea-dhcp4" + ] +} diff --git a/doc/sphinx/api/lease4-get-by-hostname.json b/doc/sphinx/api/lease4-get-by-hostname.json new file mode 100644 index 0000000000..33bb6f7ee8 --- /dev/null +++ b/doc/sphinx/api/lease4-get-by-hostname.json @@ -0,0 +1,20 @@ +{ + "avail": "1.7.1", + "brief": [ + "This command retrieves all IPv4 leases with the specified hostname." + ], + "cmd-syntax": [ + "{", + " \"command\": \"lease4-get-by-hostname\",", + " \"arguments\": {", + " \"hostname\": \"myhost.example.com.\"", + " }", + "}" + ], + "description": "See ", + "hook": "lease_cmds", + "name": "lease4-get-by-hostname", + "support": [ + "kea-dhcp4" + ] +} diff --git a/doc/sphinx/api/lease4-get-by-hw-address.json b/doc/sphinx/api/lease4-get-by-hw-address.json new file mode 100644 index 0000000000..b864db8582 --- /dev/null +++ b/doc/sphinx/api/lease4-get-by-hw-address.json @@ -0,0 +1,20 @@ +{ + "avail": "1.7.1", + "brief": [ + "This command retrieves all IPv4 leases with the specified hardware address." + ], + "cmd-syntax": [ + "{", + " \"command\": \"lease4-get-by-hw-address\",", + " \"arguments\": {", + " \"hw-address\": \"08:08:08:08:08:08\"", + " }", + "}" + ], + "description": "See ", + "hook": "lease_cmds", + "name": "lease4-get-by-hw-address", + "support": [ + "kea-dhcp4" + ] +} diff --git a/doc/sphinx/api/lease6-get-by-duid.json b/doc/sphinx/api/lease6-get-by-duid.json new file mode 100644 index 0000000000..2d30fec25c --- /dev/null +++ b/doc/sphinx/api/lease6-get-by-duid.json @@ -0,0 +1,20 @@ +{ + "avail": "1.7.1", + "brief": [ + "This command retrieves all IPv6 leases with the specified hardware address." + ], + "cmd-syntax": [ + "{", + " \"command\": \"lease6-get-by-duid\",", + " \"arguments\": {", + " \"duid\": \"1a:1b:1c:1d:1e:1f:20:21:22:23:24\"", + " }", + "}" + ], + "description": "See ", + "hook": "lease_cmds", + "name": "lease6-get-by-duid", + "support": [ + "kea-dhcp6" + ] +} diff --git a/doc/sphinx/api/lease6-get-by-hostname.json b/doc/sphinx/api/lease6-get-by-hostname.json new file mode 100644 index 0000000000..2e894cfd77 --- /dev/null +++ b/doc/sphinx/api/lease6-get-by-hostname.json @@ -0,0 +1,20 @@ +{ + "avail": "1.7.1", + "brief": [ + "This command retrieves all IPv6 leases with the specified hostname." + ], + "cmd-syntax": [ + "{", + " \"command\": \"lease6-get-by-hostname\",", + " \"arguments\": {", + " \"hostname\": \"myhost.example.com.\"", + " }", + "}" + ], + "description": "See ", + "hook": "lease_cmds", + "name": "lease6-get-by-hostname", + "support": [ + "kea-dhcp6" + ] +} diff --git a/doc/sphinx/arm/hooks-lease-cmds.rst b/doc/sphinx/arm/hooks-lease-cmds.rst index 639388fae7..070f7e366c 100644 --- a/doc/sphinx/arm/hooks-lease-cmds.rst +++ b/doc/sphinx/arm/hooks-lease-cmds.rst @@ -59,6 +59,20 @@ This library provides the following commands: of all IPv6 leases in the database. By iterating through the pages it is possible to retrieve all the leases. +- ``lease4-get-by-hw-address`` - return all IPv4 leases with the specified + hardware address. + +- ``lease4-get-by-client-id`` - return all IPv4 leases with the specified + client id. + +- ``lease6-get-by-duid`` - returns all IPv6 leases with the specified duid. + +- ``lease4-get-by-hostname`` - return all IPv4 leases with the specified + hostname. + +- ``lease6-get-by-hostname`` - return all IPv6 leases with the specified + hostname. + - ``lease4-del`` - deletes an IPv4 lease with the specified parameters. - ``lease6-del`` - deletes an IPv6 lease with the specified parameters. @@ -686,6 +700,50 @@ The client may assume that it has reached the last page when the includes the case when the ``count`` is equal to 0, meaning that no leases were found. +.. _command-lease4-get-by-hw-address: + +.. _command-lease4-get-by-client-id: + +.. _command-lease6-get-by-duid: + +.. _command-lease4-get-by-hostname: + +.. _command-lease6-get-by-hostname: + +The lease4-get-by-*, lease6-get-by-* Commands +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +``leaseX-get-by-Y`` can be used to query the lease database and +retrieve all existing leases with a specified hardware address (IPv4 +only), client id IPv4 only), duid (IPv6 only) identifiers or hostname. + +An example ``lease4-get-by-hw-address`` command for getting IPv4 leases +with a given hardware address is: + +:: + + { + "command": "lease4-get-by-hw-address", + "arguments": { + "hw-address": "08:08:08:08:08:08" + } + } + +An example of the ``lease6-get-by-hostname`` is: + +:: + + { + "command": "lease6-get-by-hostname", + "arguments": { + "hostname": "myhost.example.org" + } + } + +The by key is the only parameter. The returned response contains a detailed +list of leases in the same format than ``leaseX-get-all``. This list can be +empty and usually is never large. + .. _command-lease4-del: .. _command-lease6-del: diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds.cc b/src/hooks/dhcp/lease_cmds/lease_cmds.cc index 7ded5be594..a2b5866340 100644 --- a/src/hooks/dhcp/lease_cmds/lease_cmds.cc +++ b/src/hooks/dhcp/lease_cmds/lease_cmds.cc @@ -800,9 +800,8 @@ LeaseCmdsImpl::leaseGetByHwAddressHandler(CalloutHandle& handle) { extractCommand(handle); // arguments must always be present - if (!cmd_args_) { - isc_throw(BadValue, "no parameters specified for the " << cmd_name_ - << " command"); + if (!cmd_args_ || (cmd_args_->getType() != Element::map)) { + isc_throw(BadValue, "Command arguments missing or a not a map."); } // the hw-address parameter is mandatory. @@ -851,9 +850,8 @@ LeaseCmdsImpl::leaseGetByClientIdHandler(CalloutHandle& handle) { extractCommand(handle); // arguments must always be present - if (!cmd_args_) { - isc_throw(BadValue, "no parameters specified for the " << cmd_name_ - << " command"); + if (!cmd_args_ || (cmd_args_->getType() != Element::map)) { + isc_throw(BadValue, "Command arguments missing or a not a map."); } // the client-id parameter is mandatory. @@ -902,9 +900,8 @@ LeaseCmdsImpl::leaseGetByDuidHandler(CalloutHandle& handle) { extractCommand(handle); // arguments must always be present - if (!cmd_args_) { - isc_throw(BadValue, "no parameters specified for the " << cmd_name_ - << " command"); + if (!cmd_args_ || (cmd_args_->getType() != Element::map)) { + isc_throw(BadValue, "Command arguments missing or a not a map."); } // the duid parameter is mandatory. @@ -955,9 +952,8 @@ LeaseCmdsImpl::leaseGetByHostnameHandler(CalloutHandle& handle) { v4 = (cmd_name_ == "lease4-get-by-hostname"); // arguments must always be present - if (!cmd_args_) { - isc_throw(BadValue, "no parameters specified for the " << cmd_name_ - << " command"); + if (!cmd_args_ || (cmd_args_->getType() != Element::map)) { + isc_throw(BadValue, "Command arguments missing or a not a map."); } // the hostname parameter is mandatory. -- GitLab