Kea 1.5.0
bin/netconf/simple_parser.cc
Go to the documentation of this file.
1// Copyright (C) 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
11#include <cc/data.h>
13#include <hooks/hooks_parser.h>
14#include <boost/foreach.hpp>
15
16using namespace isc::data;
17
18namespace isc {
19namespace netconf {
34
39 { "boot-update", Element::boolean, "true" },
40 { "subscribe-changes", Element::boolean, "true" },
41 { "validate-changes", Element::boolean, "true" }
42};
43
46 { "socket-type", Element::string, "stdout" },
47 { "socket-name", Element::string, "" },
48 { "socket-url" , Element::string, "http://127.0.0.1:8000/" }
49};
50
53 { "model", Element::string, "kea-dhcp4-server" }
54};
55
58 { "model", Element::string, "kea-dhcp6-server" }
59};
60
63 { "model", Element::string, "kea-dhcp-ddns" }
64};
65
68 { "model", Element::string, "kea-ctrl-agent" }
69};
70
78 "boot-update",
79 "subscribe-changes",
80 "validate-changes"
81};
82
84
88
90 size_t cnt = 0;
91
92 // Set global defaults first.
93 cnt = setDefaults(global, NETCONF_DEFAULTS);
94
95 ConstElementPtr servers = global->get("managed-servers");
96 if (servers) {
97 for (auto it : servers->mapValue()) {
98 cnt += setServerDefaults(it.first, it.second);
99 }
100 }
101
102 return (cnt);
103}
104
106 size_t cnt = 0;
107
108 // Now derive global parameters into managed-servers.
109 ConstElementPtr servers = global->get("managed-servers");
110 if (servers) {
111 for (auto it : servers->mapValue()) {
112 ElementPtr mutable_server =
113 boost::const_pointer_cast<Element>(it.second);
114 cnt += SimpleParser::deriveParams(global,
115 mutable_server,
117 }
118 }
119
120 return (cnt);
121}
122
123size_t
125 ConstElementPtr server) {
126 size_t cnt = 0;
127
128 ElementPtr mutable_server =
129 boost::const_pointer_cast<Element>(server);
130 if (name == "dhcp4") {
131 cnt += setDefaults(mutable_server, DHCP4_DEFAULTS);
132 } else if (name == "dhcp6") {
133 cnt += setDefaults(mutable_server, DHCP6_DEFAULTS);
134 } else if (name == "d2") {
135 cnt += setDefaults(mutable_server, D2_DEFAULTS);
136 } else if (name == "ca") {
137 cnt += setDefaults(mutable_server, CA_DEFAULTS);
138 }
139
140 ConstElementPtr ctrl_sock = server->get("control-socket");
141 if (!ctrl_sock) {
142 return (cnt);
143 }
144 ElementPtr mutable_ctrl_sock =
145 boost::const_pointer_cast<Element>(ctrl_sock);
146 cnt += setDefaults(mutable_ctrl_sock, CTRL_SOCK_DEFAULTS);
147
148 return (cnt);
149}
150
151void
153 const ConstElementPtr& config,
154 bool check_only) {
155
156 // User context can be done at anytime.
157 ConstElementPtr user_context = config->get("user-context");
158 if (user_context) {
159 ctx->setContext(user_context);
160 }
161
162 // get managed servers.
163 ConstElementPtr servers = config->get("managed-servers");
164 if (servers) {
165 for (auto it : servers->mapValue()) {
166 ServerConfigParser server_parser;
167 CfgServerPtr server = server_parser.parse(it.second);
168 ctx->getCfgServersMap()->insert(make_pair(it.first, server));
169 }
170 }
171
172 // Finally, let's get the hook libs!
173 using namespace isc::hooks;
174 HooksConfig& libraries = ctx->getHooksConfig();
175 ConstElementPtr hooks = config->get("hooks-libraries");
176 if (hooks) {
177 HooksLibrariesParser hooks_parser;
178 hooks_parser.parse(libraries, hooks);
179 libraries.verifyLibraries(hooks->getPosition());
180 }
181
182 if (!check_only) {
183 // This occurs last as if it succeeds, there is no easy way
184 // revert it. As a result, the failure to commit a subsequent
185 // change causes problems when trying to roll back.
186 libraries.loadLibraries();
187 }
188}
189
190};
191};
static size_t deriveParams(isc::data::ConstElementPtr parent, isc::data::ElementPtr child, const ParamsList &params)
Derives (inherits) parameters from parent scope to a child.
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:23
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:22
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-dhcp-ddns.
A collection of classes for housing and parsing the application configuration necessary for the Netco...