16using namespace libyang;
17using namespace sysrepo;
29 if ((
model_ == KEA_DHCP4_SERVER) ||
30 (
model_ == KEA_DHCP6_SERVER) ||
31 (
model_ == KEA_DHCP_DDNS)) {
34 }
catch (Error
const& ex) {
36 "getting control socket: " << ex.
what());
39 "getControlSocket not implemented for the model: " <<
model_);
45 if ((
model_ == KEA_DHCP4_SERVER) ||
46 (
model_ == KEA_DHCP6_SERVER) ||
47 (
model_ == KEA_DHCP_DDNS)) {
50 }
catch (Error
const& ex) {
52 "getting control socket: " << ex.
what());
55 "getControlSocket not implemented for the model: " <<
model_);
75 [&](DataNode
const& node) ->
ElementPtr const {
79 if (const_authentication) {
80 authentication =
copy(const_authentication);
91 authentication->set(
"clients", clients);
93 return (authentication);
96 if (headers && !headers->empty()) {
97 result->set(
"http-headers", headers);
100 return (result->empty() ?
ElementPtr() : result);
105 return getList(data_node,
"http-headers", *
this,
115 return (result->empty() ?
ElementPtr() : result);
120 return getList(data_node,
"clients", *
this,
132 if (result->get(
"user") && result->get(
"user")->stringValue().empty()) {
133 result->remove(
"user");
135 if (result->get(
"password") && result->get(
"password")->stringValue().empty()) {
136 result->remove(
"password");
138 if (result->get(
"user-file") && result->get(
"user-file")->stringValue().empty()) {
139 result->remove(
"user-file");
141 if (result->get(
"password-file") && result->get(
"password-file")->stringValue().empty()) {
142 result->remove(
"password-file");
144 return (result->empty() ?
ElementPtr() : result);
160 if ((
model_ == KEA_DHCP4_SERVER) ||
161 (
model_ == KEA_DHCP6_SERVER) ||
162 (
model_ == KEA_DHCP_DDNS)) {
166 "setControlSocket not implemented for the model: "
169 }
catch (Error
const& ex) {
171 "setting control socket '" << elem->str()
172 <<
"' at '" << xpath <<
"': " << ex.what());
180 if ((
model_ == KEA_DHCP4_SERVER) ||
181 (
model_ == KEA_DHCP6_SERVER) ||
182 (
model_ == KEA_DHCP_DDNS)) {
186 "setControlSocket not implemented for the model: "
189 }
catch (Error
const& ex) {
191 "setting control socket '" << elem->str()
192 <<
"' at '" << xpath <<
"': " << ex.what());
203 for (
size_t i = 0; i < elem->size(); ++i) {
204 ElementPtr control_socket = elem->getNonConst(i);
205 if (!control_socket->contains(
"socket-type")) {
206 isc_throw(
BadValue,
"control-socket without socket-type: " << control_socket->str());
208 string type = control_socket->get(
"socket-type")->stringValue();
210 key << xpath <<
"[socket-type='" << type <<
"']";
218 bool has_mandatory_key) {
224 if (has_mandatory_key) {
239 if (authentication && !authentication->empty()) {
241 checkAndSetLeaf(authentication, xpath +
"/authentication",
"realm", LeafBaseType::String);
242 checkAndSetLeaf(authentication, xpath +
"/authentication",
"directory", LeafBaseType::String);
248 if (http_headers && !http_headers->empty()) {
261 for (
size_t i = 0; i < elem->size(); ++i) {
263 auto user = client->get(
"user");
266 user_str = user->stringValue();
268 auto password = client->get(
"password");
271 password_str = password->stringValue();
273 auto user_file = client->get(
"user-file");
274 string user_file_str;
276 user_file_str = user_file->stringValue();
278 auto password_file = client->get(
"password-file");
279 string password_file_str;
281 password_file_str = password_file->stringValue();
284 key << xpath <<
"[user='" << user_str <<
"'][password='" << password_str
285 <<
"'][user-file='" << user_file_str <<
"'][password-file='"
286 << password_file_str <<
"']";
311 key << xpath <<
"[name='" << name->stringValue() <<
"']";
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
void setControlSocket(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set control socket from JSON to YANG.
TranslatorControlSocket(sysrepo::Session session, const std::string &model)
Constructor.
void setControlSockets(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set control sockets from JSON to YANG.
isc::data::ElementPtr getControlSocketAuthenticationClients(libyang::DataNode const &data_node)
getControlSocketsAuthenticationClients JSON for kea models.
isc::data::ElementPtr getControlSocket(libyang::DataNode const &data_node)
Translate a control socket from YANG to JSON.
isc::data::ElementPtr getControlSocketAuthenticationClient(libyang::DataNode const &data_node)
getControlSocketsAuthenticationClients JSON for kea models.
isc::data::ElementPtr getControlSocketKea(libyang::DataNode const &data_node)
getControlSocket JSON for kea models.
isc::data::ElementPtr getControlSockets(libyang::DataNode const &data_node)
Translate a control socket from YANG to JSON.
isc::data::ElementPtr getControlSocketFromAbsoluteXpath(std::string const &xpath)
Translate a control socket from YANG to JSON.
isc::data::ElementPtr getControlSocketsKea(libyang::DataNode const &data_node)
getControlSocket JSON for kea models.
void setControlSocketHttpHeader(const std::string &xpath, isc::data::ConstElementPtr elem)
setControlSocketHttpHeader for kea models.
void setControlSocketAuthenticationClients(const std::string &xpath, isc::data::ConstElementPtr elem)
setControlSocketAuthenticationClients for kea models.
void setControlSocketKea(const std::string &xpath, isc::data::ConstElementPtr elem, bool has_mandatory_key)
setControlSocket for kea models.
isc::data::ElementPtr getControlSocketHttpHeader(libyang::DataNode const &data_node)
getControlSocketsAuthenticationClients JSON for kea models.
isc::data::ElementPtr getControlSocketHttpHeaders(libyang::DataNode const &data_node)
getControlSocketsAuthenticationClients JSON for kea models.
void setControlSocketsKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setControlSocket for kea models.
void setControlSocketAuthenticationClient(const std::string &xpath, isc::data::ConstElementPtr elem)
setControlSocketAuthenticationClient for kea models.
void setControlSocketHttpHeaders(const std::string &xpath, isc::data::ConstElementPtr elem)
setControlSocketHttpHeaders for kea models.
isc::data::ElementPtr getList(libyang::DataNode const &data_node, std::string const &xpath, T &t, isc::data::ElementPtr(T::*f)(libyang::DataNode const &)) const
Retrieve a list as ElementPtr from sysrepo from a certain xpath.
void checkAndSetLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, libyang::LeafBaseType const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void checkAndGet(isc::data::ElementPtr const &storage, libyang::DataNode const &data_node, std::string const &xpath, T translate) const
Calls {translate} for the element found at {xpath} relative to {data_node} and sets the result in {st...
void setMandatoryDivergingLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, std::string const &yang_name, libyang::LeafBaseType const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
libyang::DataNode findXPath(std::string const &xpath) const
Retrieves a YANG data node by xpath.
void getMandatoryLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node and sto...
void checkAndGetLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node and sto...
void checkAndSetUserContext(isc::data::ConstElementPtr const &from, std::string const &xpath)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void deleteItem(const std::string &xpath)
Delete basic value from YANG.
void checkAndGetDivergingLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name, std::string const &yang_name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node and sto...
void setItem(const std::string &xpath, isc::data::ConstElementPtr const elem, libyang::LeafBaseType const type)
Translate and set basic value from JSON to YANG.
std::string model_
The model.
void checkAndGetAndJsonifyLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, const std::string &name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node,...
Translator(sysrepo::Session session, const std::string &model)
Constructor.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
ElementPtr copy(ConstElementPtr from, unsigned level)
Copy the data up to a nesting level.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
Defines the logger used by the top-level component of kea-lfc.