mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 14:35:29 +00:00
[3681_rebase] DatabaseConnection is used in MemfileLeaseMgr
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
#include <dhcpsrv/dhcpsrv_log.h>
|
#include <dhcpsrv/dhcpsrv_log.h>
|
||||||
#include <dhcpsrv/lease_file_loader.h>
|
#include <dhcpsrv/lease_file_loader.h>
|
||||||
#include <dhcpsrv/memfile_lease_mgr.h>
|
#include <dhcpsrv/memfile_lease_mgr.h>
|
||||||
|
#include <dhcpsrv/database_connection.h>
|
||||||
#include <exceptions/exceptions.h>
|
#include <exceptions/exceptions.h>
|
||||||
#include <util/pid_file.h>
|
#include <util/pid_file.h>
|
||||||
#include <util/process_spawn.h>
|
#include <util/process_spawn.h>
|
||||||
@@ -220,21 +221,13 @@ LFCSetup::getExitStatus() const {
|
|||||||
return (process_->getExitStatus(pid_));
|
return (process_->getExitStatus(pid_));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
Memfile_LeaseMgr::Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& parameters):
|
||||||
Memfile_LeaseMgr::getParameter(const std::string& name) const {
|
lfc_setup_(new LFCSetup(boost::bind(&Memfile_LeaseMgr::lfcCallback, this),
|
||||||
ParameterMap::const_iterator param = parameters_.find(name);
|
*getIOService())),
|
||||||
if (param == parameters_.end()) {
|
conn_(parameters)
|
||||||
isc_throw(BadValue, "Parameter " << name << " not found");
|
|
||||||
}
|
|
||||||
return (param->second);
|
|
||||||
}
|
|
||||||
|
|
||||||
Memfile_LeaseMgr::Memfile_LeaseMgr(const ParameterMap& parameters): parameters_(parameters),
|
|
||||||
lfc_setup_(new LFCSetup(boost::bind(&Memfile_LeaseMgr::lfcCallback, this),
|
|
||||||
*getIOService()))
|
|
||||||
{
|
{
|
||||||
// Check the universe and use v4 file or v6 file.
|
// Check the universe and use v4 file or v6 file.
|
||||||
std::string universe = getParameter("universe");
|
std::string universe = conn_.getParameter("universe");
|
||||||
if (universe == "4") {
|
if (universe == "4") {
|
||||||
std::string file4 = initLeaseFilePath(V4);
|
std::string file4 = initLeaseFilePath(V4);
|
||||||
if (!file4.empty()) {
|
if (!file4.empty()) {
|
||||||
@@ -696,7 +689,7 @@ std::string
|
|||||||
Memfile_LeaseMgr::initLeaseFilePath(Universe u) {
|
Memfile_LeaseMgr::initLeaseFilePath(Universe u) {
|
||||||
std::string persist_val;
|
std::string persist_val;
|
||||||
try {
|
try {
|
||||||
persist_val = getParameter("persist");
|
persist_val = conn_.getParameter("persist");
|
||||||
} catch (const Exception& ex) {
|
} catch (const Exception& ex) {
|
||||||
// If parameter persist hasn't been specified, we use a default value
|
// If parameter persist hasn't been specified, we use a default value
|
||||||
// 'yes'.
|
// 'yes'.
|
||||||
@@ -714,7 +707,7 @@ Memfile_LeaseMgr::initLeaseFilePath(Universe u) {
|
|||||||
|
|
||||||
std::string lease_file;
|
std::string lease_file;
|
||||||
try {
|
try {
|
||||||
lease_file = getParameter("name");
|
lease_file = conn_.getParameter("name");
|
||||||
} catch (const Exception& ex) {
|
} catch (const Exception& ex) {
|
||||||
lease_file = getDefaultLeaseFilePath(u);
|
lease_file = getDefaultLeaseFilePath(u);
|
||||||
}
|
}
|
||||||
@@ -800,7 +793,7 @@ void
|
|||||||
Memfile_LeaseMgr::lfcSetup() {
|
Memfile_LeaseMgr::lfcSetup() {
|
||||||
std::string lfc_interval_str = "0";
|
std::string lfc_interval_str = "0";
|
||||||
try {
|
try {
|
||||||
lfc_interval_str = getParameter("lfc-interval");
|
lfc_interval_str = conn_.getParameter("lfc-interval");
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
// Ignore and default to 0.
|
// Ignore and default to 0.
|
||||||
}
|
}
|
||||||
|
@@ -88,9 +88,6 @@ class LFCSetup;
|
|||||||
/// var/kea/kea-leases6.csv.
|
/// var/kea/kea-leases6.csv.
|
||||||
class Memfile_LeaseMgr : public LeaseMgr {
|
class Memfile_LeaseMgr : public LeaseMgr {
|
||||||
public:
|
public:
|
||||||
/// @brief Database configuration parameter map
|
|
||||||
typedef std::map<std::string, std::string> ParameterMap;
|
|
||||||
|
|
||||||
/// @defgroup versions Specified memfile backend version.
|
/// @defgroup versions Specified memfile backend version.
|
||||||
///
|
///
|
||||||
/// @brief Defines major version of the memfile backend.
|
/// @brief Defines major version of the memfile backend.
|
||||||
@@ -107,13 +104,6 @@ public:
|
|||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
/// @brief Returns value of a connection parameter.
|
|
||||||
///
|
|
||||||
/// @param name Name of the parameter which value should be returned.
|
|
||||||
/// @return Value of one of the connection parameters.
|
|
||||||
/// @throw BadValue if parameter is not found
|
|
||||||
std::string getParameter(const std::string& name) const;
|
|
||||||
|
|
||||||
/// @brief Specifies universe (V4, V6)
|
/// @brief Specifies universe (V4, V6)
|
||||||
///
|
///
|
||||||
/// This enumeration is used by various functions in Memfile %Lease Manager,
|
/// This enumeration is used by various functions in Memfile %Lease Manager,
|
||||||
@@ -138,7 +128,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// @param parameters A data structure relating keywords and values
|
/// @param parameters A data structure relating keywords and values
|
||||||
/// concerned with the database.
|
/// concerned with the database.
|
||||||
Memfile_LeaseMgr(const ParameterMap& parameters);
|
Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& parameters);
|
||||||
|
|
||||||
/// @brief Destructor (closes file)
|
/// @brief Destructor (closes file)
|
||||||
virtual ~Memfile_LeaseMgr();
|
virtual ~Memfile_LeaseMgr();
|
||||||
@@ -598,16 +588,14 @@ private:
|
|||||||
template<typename LeaseFileType>
|
template<typename LeaseFileType>
|
||||||
void lfcExecute(boost::shared_ptr<LeaseFileType>& lease_file);
|
void lfcExecute(boost::shared_ptr<LeaseFileType>& lease_file);
|
||||||
|
|
||||||
/// @brief List of parameters passed in dbconfig
|
|
||||||
///
|
|
||||||
/// That will be mostly used for storing database name, username,
|
|
||||||
/// password and other parameters required for DB access. It is not
|
|
||||||
/// intended to keep any DHCP-related parameters.
|
|
||||||
ParameterMap parameters_;
|
|
||||||
|
|
||||||
/// @brief A pointer to the Lease File Cleanup configuration.
|
/// @brief A pointer to the Lease File Cleanup configuration.
|
||||||
boost::scoped_ptr<LFCSetup> lfc_setup_;
|
boost::scoped_ptr<LFCSetup> lfc_setup_;
|
||||||
|
|
||||||
|
/// @brief Parameters storage
|
||||||
|
///
|
||||||
|
/// DatabaseConnection object is used only for storing, accessing and
|
||||||
|
/// printing parameter map.
|
||||||
|
DatabaseConnection conn_;
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user