Kea 2.5.6
translator_control_socket.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2022 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
10#include <yang/yang_models.h>
11
12#include <sstream>
13
14using namespace std;
15using namespace isc::data;
16using namespace libyang;
17using namespace sysrepo;
18
19namespace isc {
20namespace yang {
21
23 const string& model)
24 : Translator(session, model) {
25}
26
29 try {
30 if ((model_ == KEA_DHCP4_SERVER) ||
31 (model_ == KEA_DHCP6_SERVER) ||
32 (model_ == KEA_DHCP_DDNS) ||
33 (model_ == KEA_CTRL_AGENT)) {
34 return (getControlSocketKea(data_node));
35 }
36 } catch (Error const& ex) {
38 "getting control socket: " << ex.what());
39 }
41 "getControlSocket not implemented for the model: " << model_);
42}
43
47 getMandatoryLeaf(result, data_node, "socket-name");
48 getMandatoryLeaf(result, data_node, "socket-type");
49 checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
50 return (result->empty() ? ElementPtr() : result);
51}
52
55 try {
56 return getControlSocket(findXPath(xpath));
57 } catch (NetconfError const&) {
58 return ElementPtr();
59 }
60}
61
62void
64 ConstElementPtr elem) {
65 try {
66 if ((model_ == KEA_DHCP4_SERVER) ||
67 (model_ == KEA_DHCP6_SERVER) ||
68 (model_ == KEA_DHCP_DDNS) ||
69 (model_ == KEA_CTRL_AGENT)) {
70 setControlSocketKea(xpath, elem);
71 } else {
73 "setControlSocket not implemented for the model: "
74 << model_);
75 }
76 } catch (Error const& ex) {
78 "setting control socket '" << elem->str()
79 << "' at '" << xpath << "': " << ex.what());
80 }
81}
82
83void
85 ConstElementPtr elem) {
86 if (!elem) {
87 deleteItem(xpath);
88 return;
89 }
90
91 setMandatoryLeaf(elem, xpath, "socket-name", LeafBaseType::String);
92 setMandatoryLeaf(elem, xpath, "socket-type", LeafBaseType::Enum);
93 checkAndSetUserContext(elem, xpath);
94}
95
96} // namespace yang
97} // namespace isc
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.
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:304
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 setControlSocketKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setControlSocket for kea models.
isc::data::ElementPtr getControlSocket(libyang::DataNode const &data_node)
Translate a control socket from YANG to JSON.
isc::data::ElementPtr getControlSocketKea(libyang::DataNode const &data_node)
getControlSocket JSON for kea models.
isc::data::ElementPtr getControlSocketFromAbsoluteXpath(std::string const &xpath)
Translate a control socket from YANG to JSON.
Between YANG and JSON translator class for basic values.
Definition: translator.h:23
void setMandatoryLeaf(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.
Definition: translator.cc:245
libyang::DataNode findXPath(std::string const &xpath) const
Retrieves a YANG data node by xpath.
Definition: translator.cc:132
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...
Definition: translator.cc:197
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.
Definition: translator.cc:99
void deleteItem(const std::string &xpath)
Delete basic value from YANG.
Definition: translator.cc:120
std::string model_
The model.
Definition: translator.h:427
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,...
Definition: translator.cc:53
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:29
boost::shared_ptr< Element > ElementPtr
Definition: data.h:28
Defines the logger used by the top-level component of kea-lfc.
Generic NETCONF error.
Definition: netconf_error.h:30