Kea: cfg_db_access.cc Source File

| Kea 1.5.0

cfg_db_access.cc
Go to the documentation of this file.
1 // Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7 #include <config.h>
8 #include <dhcpsrv/cfg_db_access.h>
9 #include <dhcpsrv/db_type.h>
10 #include <dhcpsrv/host_data_source_factory.h>
11 #include <dhcpsrv/host_mgr.h>
12 #include <dhcpsrv/lease_mgr_factory.h>
13 #include <boost/algorithm/string.hpp>
14 #include <boost/foreach.hpp>
15 #include <boost/lexical_cast.hpp>
16 #include <sstream>
17 #include <vector>
18
19 using namespace isc::data;
20
21 namespace isc {
22 namespace dhcp {
23
24 CfgDbAccess::CfgDbAccess()
25 : appended_parameters_(), lease_db_access_("type=memfile"),
26 host_db_access_() {
27 }
28
29 std::string
30 CfgDbAccess::getLeaseDbAccessString() const {
31 return (getAccessString(lease_db_access_));
32 }
33
34
35 std::string
36 CfgDbAccess::getHostDbAccessString() const {
37 if (host_db_access_.empty()) {
38 return ("");
39 } else {
40 return (getAccessString(host_db_access_.front()));
41 }
42 }
43
44 std::list<std::string>
45 CfgDbAccess::getHostDbAccessStringList() const {
46 std::list<std::string> ret;
47 for (const std::string& dbaccess : host_db_access_) {
48 if (!dbaccess.empty()) {
49 ret.push_back(getAccessString(dbaccess));
50 }
51 }
52 return (ret);
53 }
54
55 void
56 CfgDbAccess::createManagers() const {
57 // Recreate lease manager.
58 LeaseMgrFactory::destroy();
59 LeaseMgrFactory::create(getLeaseDbAccessString());
60
61 // Recreate host data source.
62 HostMgr::create();
63 std::list<std::string> host_db_access_list = getHostDbAccessStringList();
64 for (std::string& hds : host_db_access_list) {
65 HostMgr::addBackend(hds);
66 }
67
68 // Check for a host cache.
69 HostMgr::checkCacheBackend(true);
70 }
71
72 std::string
73 CfgDbAccess::getAccessString(const std::string& access_string) const {
74 std::ostringstream s;
75 s << access_string;
76 // Only append additional parameters if any parameters are specified
77 // in a configuration. For host database, no parameters mean that
78 // database access is disabled and thus we don't want to append any
79 // parameters.
80 if ((s.tellp() != std::streampos(0)) && (!appended_parameters_.empty())) {
81 s << " " << appended_parameters_;
82 }
83
84 return (s.str());
85 }
86
87 } // end of isc::dhcp namespace
88 } // end of isc namespace
isc::dhcp::HostMgr::checkCacheBackend
static bool checkCacheBackend(bool logging=false)
Check for the cache host backend.
Definition: host_mgr.cc:68
db_type.h
isc::dhcp::HostMgr::addBackend
static void addBackend(const std::string &access)
Add an alternate host backend (aka host data source).
Definition: host_mgr.cc:45
isc::dhcp::HostMgr::create
static void create()
Creates new instance of the HostMgr.
Definition: host_mgr.cc:40
lease_mgr_factory.h
isc::data
Definition: cfg_to_element.h:25
isc::dhcp::CfgDbAccess::getLeaseDbAccessString
std::string getLeaseDbAccessString() const
Retrieves lease database access string.
Definition: cfg_db_access.cc:30
isc::dhcp::LeaseMgrFactory::destroy
static void destroy()
Destroy lease manager.
Definition: lease_mgr_factory.cc:95
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::dhcp::CfgDbAccess::appended_parameters_
std::string appended_parameters_
Parameters to be appended to the database access strings.
Definition: cfg_db_access.h:90
isc::dhcp::CfgDbAccess::getHostDbAccessString
std::string getHostDbAccessString() const
Retrieves host database access string.
Definition: cfg_db_access.cc:36
isc::dhcp::CfgDbAccess::getHostDbAccessStringList
std::list< std::string > getHostDbAccessStringList() const
Retrieves host database access string.
Definition: cfg_db_access.cc:45
cfg_db_access.h
isc::dhcp::CfgDbAccess::host_db_access_
std::list< std::string > host_db_access_
Holds host database access strings.
Definition: cfg_db_access.h:96
isc::dhcp::LeaseMgrFactory::create
static void create(const std::string &dbaccess)
Create an instance of a lease manager.
Definition: lease_mgr_factory.cc:45
host_data_source_factory.h
isc::dhcp::CfgDbAccess::lease_db_access_
std::string lease_db_access_
Holds lease database access string.
Definition: cfg_db_access.h:93
isc::dhcp::CfgDbAccess::getAccessString
std::string getAccessString(const std::string &access_string) const
Returns lease or host database access string.
Definition: cfg_db_access.cc:73
host_mgr.h
isc::dhcp::CfgDbAccess::createManagers
void createManagers() const
Creates instance of lease manager and host data sources according to the configuration specified.
Definition: cfg_db_access.cc:56