2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 21:45:37 +00:00

[3681_rebase] DatabaseConnection is used in MemfileLeaseMgr

This commit is contained in:
Tomek Mrugalski
2015-10-09 22:35:14 +02:00
parent 5221b4f27f
commit 5fc3a5aa3f
2 changed files with 15 additions and 34 deletions

View File

@@ -17,6 +17,7 @@
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/lease_file_loader.h>
#include <dhcpsrv/memfile_lease_mgr.h>
#include <dhcpsrv/database_connection.h>
#include <exceptions/exceptions.h>
#include <util/pid_file.h>
#include <util/process_spawn.h>
@@ -220,21 +221,13 @@ LFCSetup::getExitStatus() const {
return (process_->getExitStatus(pid_));
}
std::string
Memfile_LeaseMgr::getParameter(const std::string& name) const {
ParameterMap::const_iterator param = parameters_.find(name);
if (param == parameters_.end()) {
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()))
Memfile_LeaseMgr::Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& parameters):
lfc_setup_(new LFCSetup(boost::bind(&Memfile_LeaseMgr::lfcCallback, this),
*getIOService())),
conn_(parameters)
{
// Check the universe and use v4 file or v6 file.
std::string universe = getParameter("universe");
std::string universe = conn_.getParameter("universe");
if (universe == "4") {
std::string file4 = initLeaseFilePath(V4);
if (!file4.empty()) {
@@ -696,7 +689,7 @@ std::string
Memfile_LeaseMgr::initLeaseFilePath(Universe u) {
std::string persist_val;
try {
persist_val = getParameter("persist");
persist_val = conn_.getParameter("persist");
} catch (const Exception& ex) {
// If parameter persist hasn't been specified, we use a default value
// 'yes'.
@@ -714,7 +707,7 @@ Memfile_LeaseMgr::initLeaseFilePath(Universe u) {
std::string lease_file;
try {
lease_file = getParameter("name");
lease_file = conn_.getParameter("name");
} catch (const Exception& ex) {
lease_file = getDefaultLeaseFilePath(u);
}
@@ -800,7 +793,7 @@ void
Memfile_LeaseMgr::lfcSetup() {
std::string lfc_interval_str = "0";
try {
lfc_interval_str = getParameter("lfc-interval");
lfc_interval_str = conn_.getParameter("lfc-interval");
} catch (const std::exception& ex) {
// Ignore and default to 0.
}

View File

@@ -88,9 +88,6 @@ class LFCSetup;
/// var/kea/kea-leases6.csv.
class Memfile_LeaseMgr : public LeaseMgr {
public:
/// @brief Database configuration parameter map
typedef std::map<std::string, std::string> ParameterMap;
/// @defgroup versions Specified memfile backend version.
///
/// @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)
///
/// 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
/// concerned with the database.
Memfile_LeaseMgr(const ParameterMap& parameters);
Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& parameters);
/// @brief Destructor (closes file)
virtual ~Memfile_LeaseMgr();
@@ -598,16 +588,14 @@ private:
template<typename LeaseFileType>
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.
boost::scoped_ptr<LFCSetup> lfc_setup_;
/// @brief Parameters storage
///
/// DatabaseConnection object is used only for storing, accessing and
/// printing parameter map.
DatabaseConnection conn_;
//@}
};