Kea 2.2.0
bin/netconf/simple_parser.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2021 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
11#include <cc/data.h>
13#include <hooks/hooks_manager.h>
14#include <hooks/hooks_parser.h>
15#include <boost/foreach.hpp>
16
17using namespace isc::data;
18
19namespace isc {
20namespace netconf {
35
40 { "boot-update", Element::boolean, "true" },
41 { "subscribe-changes", Element::boolean, "true" },
42 { "validate-changes", Element::boolean, "true" }
43};
44
47 { "socket-type", Element::string, "stdout" },
48 { "socket-name", Element::string, "" },
49 { "socket-url" , Element::string, "http://127.0.0.1:8000/" }
50};
51
54 { "model", Element::string, "kea-dhcp4-server" }
55};
56
59 { "model", Element::string, "kea-dhcp6-server" }
60};
61
64 { "model", Element::string, "kea-dhcp-ddns" }
65};
66
69 { "model", Element::string, "kea-ctrl-agent" }
70};
71
79 "boot-update",
80 "subscribe-changes",
81 "validate-changes"
82};
83
85
89
91 size_t cnt = 0;
92
93 // Set global defaults first.
94 cnt = setDefaults(global, NETCONF_DEFAULTS);
95
96 ConstElementPtr servers = global->get("managed-servers");
97 if (servers) {
98 for (auto it : servers->mapValue()) {
99 cnt += setServerDefaults(it.first, it.second);
100 }
101 }
102
103 return (cnt);
104}
105
107 size_t cnt = 0;
108
109 // Now derive global parameters into managed-servers.
110 ConstElementPtr servers = global->get("managed-servers");
111 if (servers) {
112 for (auto it : servers->mapValue()) {
113 ElementPtr mutable_server =
114 boost::const_pointer_cast<Element>(it.second);
115 cnt += SimpleParser::deriveParams(global,
116 mutable_server,
118 }
119 }
120
121 return (cnt);
122}
123
124size_t
126 ConstElementPtr server) {
127 size_t cnt = 0;
128
129 ElementPtr mutable_server =
130 boost::const_pointer_cast<Element>(server);
131 if (name == "dhcp4") {
132 cnt += setDefaults(mutable_server, DHCP4_DEFAULTS);
133 } else if (name == "dhcp6") {
134 cnt += setDefaults(mutable_server, DHCP6_DEFAULTS);
135 } else if (name == "d2") {
136 cnt += setDefaults(mutable_server, D2_DEFAULTS);
137 } else if (name == "ca") {
138 cnt += setDefaults(mutable_server, CA_DEFAULTS);
139 }
140
141 ConstElementPtr ctrl_sock = server->get("control-socket");
142 if (!ctrl_sock) {
143 return (cnt);
144 }
145 ElementPtr mutable_ctrl_sock =
146 boost::const_pointer_cast<Element>(ctrl_sock);
147 cnt += setDefaults(mutable_ctrl_sock, CTRL_SOCK_DEFAULTS);
148
149 return (cnt);
150}
151
152void
154 const ConstElementPtr& config,
155 bool check_only) {
156
157 // User context can be done at anytime.
158 ConstElementPtr user_context = config->get("user-context");
159 if (user_context) {
160 ctx->setContext(user_context);
161 }
162
163 // get managed servers.
164 ConstElementPtr servers = config->get("managed-servers");
165 if (servers) {
166 for (auto it : servers->mapValue()) {
167 ServerConfigParser server_parser;
168 CfgServerPtr server = server_parser.parse(it.second);
169 ctx->getCfgServersMap()->insert(make_pair(it.first, server));
170 }
171 }
172
173 // Finally, let's get the hook libs!
174 using namespace isc::hooks;
175 HooksConfig& libraries = ctx->getHooksConfig();
176 ConstElementPtr hooks = config->get("hooks-libraries");
177 if (hooks) {
178 HooksLibrariesParser hooks_parser;
179 hooks_parser.parse(libraries, hooks);
180 libraries.verifyLibraries(hooks->getPosition());
181 }
182
183 if (!check_only) {
184 // This occurs last as if it succeeds, there is no easy way
185 // revert it. As a result, the failure to commit a subsequent
186 // change causes problems when trying to roll back.
187 HooksManager::prepareUnloadLibraries();
188 static_cast<void>(HooksManager::unloadLibraries());
189 libraries.loadLibraries();
190 }
191}
192
193} // namespace netconf
194} // namespace isc
static size_t setDefaults(isc::data::ElementPtr scope, const SimpleDefaults &default_values)
Sets the default values.
Wrapper class that holds hooks libraries configuration.
Definition: hooks_config.h:36
const isc::hooks::HookLibsCollection & get() const
Provides access to the configured hooks libraries.
Definition: hooks_config.h:54
void verifyLibraries(const isc::data::Element::Position &position) const
Verifies that libraries stored in libraries_ are valid.
Definition: hooks_config.cc:20
void loadLibraries() const
Commits hooks libraries configuration.
Definition: hooks_config.cc:55
Parser for hooks library list.
Definition: hooks_parser.h:21
void parse(HooksConfig &libraries, isc::data::ConstElementPtr value)
Parses parameters value.
Definition: hooks_parser.cc:28
static const isc::data::SimpleDefaults NETCONF_DEFAULTS
This table defines default values for global options.
static const isc::data::SimpleDefaults DHCP6_DEFAULTS
Supplies defaults for dhcp6 managed server.
static const isc::data::SimpleDefaults DHCP4_DEFAULTS
Supplies defaults for dhcp4 managed server.
static size_t setAllDefaults(const isc::data::ElementPtr &global)
Sets all defaults for Netconf configuration.
static const isc::data::SimpleDefaults CA_DEFAULTS
Supplies defaults for ca managed server.
static const isc::data::ParamsList INHERIT_TO_SERVERS
List of parameters that can be inherited to managed-servers scope.
void parse(const NetconfConfigPtr &ctx, const isc::data::ConstElementPtr &config, bool check_only)
Parses the netconf configuration.
static size_t setServerDefaults(const std::string name, isc::data::ConstElementPtr server)
Adds default values to a Managed server entry.
static size_t deriveParameters(isc::data::ConstElementPtr global)
Derives (inherits) all parameters from global to more specific scopes.
static const isc::data::SimpleDefaults CTRL_SOCK_DEFAULTS
Supplies defaults for control-socket elements.
static const isc::data::SimpleDefaults D2_DEFAULTS
Supplies defaults for d2 managed server.
CfgServerPtr parse(data::ConstElementPtr server_config)
Performs the actual parsing of the given value from the "managed-servers" map.
std::vector< std::string > ParamsList
This defines a list of all parameters that are derived (or inherited) between contexts.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
std::vector< SimpleDefault > SimpleDefaults
This specifies all default values in a given scope (e.g. a subnet).
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
boost::shared_ptr< NetconfConfig > NetconfConfigPtr
Pointer to a configuration context.
boost::shared_ptr< CfgServer > CfgServerPtr
Defines a pointer for CfgServer instances.
Defines the logger used by the top-level component of kea-lfc.
A collection of classes for housing and parsing the application configuration necessary for the Netco...