kea-custom-hooks
FeM custom hooks libraries for Kea DHCP
|
Client for interaction with a single AdminDB server. More...
#include <AdminDBClient.hpp>
Classes | |
struct | HostUpdate |
A single host update. More... | |
Public Types | |
using | dhcp_update_callback_t = std::function< void()> |
Public Member Functions | |
AdminDBClient (std::string_view host, std::string_view port, std::string_view user, std::string_view password, std::string_view database, size_t last_processed_host_update_id=0) | |
Create the client and connect to the AdminDB server with the given connection settings. More... | |
AdminDBClient (const AdminDBClient &)=delete | |
AdminDBClient & | operator= (const AdminDBClient &)=delete |
AdminDBClient (AdminDBClient &&)=delete | |
AdminDBClient & | operator= (AdminDBClient &&)=delete |
TEST_VIRTUAL | ~AdminDBClient () |
TEST_VIRTUAL void | handle_notifications (const dhcp_update_callback_t &cb) |
Handle notifications for the DHCP server by invoking the given function. More... | |
Database queries | |
TEST_VIRTUAL void | prune_old_host_updates (std::chrono::days prune_before=DEFAULT_PRUNE_BEFORE) |
Prune old host updates from the AdminDB host update table. More... | |
TEST_VIRTUAL std::vector< HostUpdate > | fetch_all_host_reservations () |
Fetch a complete set of all host reservations from the AdminDB server. More... | |
TEST_VIRTUAL std::vector< HostUpdate > | fetch_pending_host_updates () |
Fetch all not-yet-processed host updates. More... | |
TEST_VIRTUAL size_t | fetch_latest_available_update_id () |
Fetch the maximum available incremental update identifier. More... | |
Static Public Member Functions | |
static HostUpdate | make_host_update (HostUpdate::Type type, const std::string &mac, const std::string &ipv4, size_t incremental_update_id, size_t subnet_id=0) |
Construct a host update from the inputs. More... | |
static HostUpdate::Type | host_update_type_from_string (std::string_view type_str) |
Static Public Attributes | |
static constexpr const char * | NOTIFICATION_CHANNEL_NAME {"dhcp"} |
static constexpr const size_t | BELOW_LOWEST_INCREMENTAL_UPDATE_ID {0} |
static constexpr const size_t | UNDEFINED_SUBNET_ID {0} |
Subnet ID for an entry where the subnet ID is NULL. More... | |
static constexpr const std::chrono::days | DEFAULT_PRUNE_BEFORE {7} |
static constexpr const std::chrono::seconds | NOTIFICATION_RECEIVER_TIMEOUT {1} |
static constexpr const std::chrono::milliseconds | NOTIFICATION_RECEIVER_SLEEP {500} |
Client for interaction with a single AdminDB server.
This class implements all methods for interacting with an AdminDB server.
Notification handling happens in a separate thread which is spawned after the notification handler is registered.
Definition at line 27 of file AdminDBClient.hpp.
using ahri::AdminDBClient::dhcp_update_callback_t = std::function<void()> |
Definition at line 30 of file AdminDBClient.hpp.
ahri::AdminDBClient::AdminDBClient | ( | std::string_view | host, |
std::string_view | port, | ||
std::string_view | user, | ||
std::string_view | password, | ||
std::string_view | database, | ||
size_t | last_processed_host_update_id = 0 |
||
) |
Create the client and connect to the AdminDB server with the given connection settings.
Definition at line 197 of file AdminDBClient.cpp.
|
delete |
|
delete |
ahri::AdminDBClient::~AdminDBClient | ( | ) |
Definition at line 207 of file AdminDBClient.cpp.
std::vector< AdminDBClient::HostUpdate > ahri::AdminDBClient::fetch_all_host_reservations | ( | ) |
Fetch a complete set of all host reservations from the AdminDB server.
This method ignores the incremental update procedure and returns the complete set of host reservations. The result's type is always set to ALL and the incremental_update_id is set to its default value. The result can be used to seed a host reservation database, prior to inserting the list into an actual host reservation table, the table contents shall be cleared.
It is advised that before/after invoking this method, fetch_latest_available_update_id()
shall be called to avoid processing incremental updates which are already part of the complete set of host reservations returned by this method.
Definition at line 236 of file AdminDBClient.cpp.
size_t ahri::AdminDBClient::fetch_latest_available_update_id | ( | ) |
Fetch the maximum available incremental update identifier.
This method fetches the hightest update identifier from the AdminDB server, stores it internally and returns it. It is useful for initializing the update identifier after a full host reservation import using fetch_all_host_reservations()
.
Definition at line 314 of file AdminDBClient.cpp.
std::vector< AdminDBClient::HostUpdate > ahri::AdminDBClient::fetch_pending_host_updates | ( | ) |
Fetch all not-yet-processed host updates.
This method takes the internally stored update identifier and returns all host updates which have a higher update identifier, thus returning all updates which haven't already been applied to the local host reservation database. It automatically updates the internal incremental update identifier, so the same set of incremental updates won't be returned twice.
Definition at line 276 of file AdminDBClient.cpp.
void ahri::AdminDBClient::handle_notifications | ( | const dhcp_update_callback_t & | cb | ) |
Handle notifications for the DHCP server by invoking the given function.
This method sets the callback for database notifications and (if needed) starts a worker thread which constantly waits for notifications to arrive. There can be only a single notification handler at a time, so setting a second notification handler means that the first notification handler won't be invoked.
Definition at line 212 of file AdminDBClient.cpp.
|
inlinestatic |
Definition at line 174 of file AdminDBClient.hpp.
|
inlinestatic |
Construct a host update from the inputs.
This is a convenience function to easily make host updates from string representations of addresses.
Definition at line 163 of file AdminDBClient.hpp.
|
delete |
|
delete |
void ahri::AdminDBClient::prune_old_host_updates | ( | std::chrono::days | prune_before = DEFAULT_PRUNE_BEFORE | ) |
Prune old host updates from the AdminDB host update table.
This method shall be called from at least one AHRI node regularly. It cleans up old host updates from the AdminDB host update table, which are long enough in the database to have been processed by all running AHRI nodes.
Definition at line 218 of file AdminDBClient.cpp.
|
staticconstexpr |
Definition at line 74 of file AdminDBClient.hpp.
|
staticconstexpr |
Definition at line 77 of file AdminDBClient.hpp.
|
staticconstexpr |
Definition at line 73 of file AdminDBClient.hpp.
|
staticconstexpr |
Definition at line 81 of file AdminDBClient.hpp.
|
staticconstexpr |
Definition at line 79 of file AdminDBClient.hpp.
|
staticconstexpr |
Subnet ID for an entry where the subnet ID is NULL.
Definition at line 76 of file AdminDBClient.hpp.