21 TranslatorClass::TranslatorClass(S_Session session,
const string& model)
35 if ((
model_ == KEA_DHCP4_SERVER) ||
36 (
model_ == KEA_DHCP6_SERVER)) {
39 }
catch (
const sysrepo_exception& ex) {
41 "sysrepo error getting client class at '" << xpath
42 <<
"': " << ex.
what());
45 "getClass not implemented for the model: " <<
model_);
56 result->set(
"name", name);
59 result->set(
"test", test);
63 result->set(
"only-if-required", required);
66 if (options && (options->size() > 0)) {
67 result->set(
"option-data", options);
72 if (
model_ == KEA_DHCP4_SERVER) {
74 if (defs && (defs->size() > 0)) {
75 result->set(
"option-def", defs);
79 result->set(
"next-server", next);
83 result->set(
"server-hostname", hostname);
87 result->set(
"boot-file-name", boot);
89 }
else if (
model_ == KEA_DHCP6_SERVER) {
96 result->set(
"user-context", Element::fromJSON(context->stringValue()));
104 if ((
model_ == KEA_DHCP4_SERVER) ||
105 (
model_ == KEA_DHCP6_SERVER)) {
109 "setClass not implemented for the model: " <<
model_);
111 }
catch (
const sysrepo_exception& ex) {
113 "sysrepo error setting client class '" << elem->str()
114 <<
"' at '" << xpath <<
"': " << ex.
what());
120 bool created =
false;
124 setItem(xpath +
"/test", test, SR_STRING_T);
129 setItem(xpath +
"/only-if-required", required, SR_BOOL_T);
140 if (
model_ == KEA_DHCP4_SERVER) {
148 setItem(xpath +
"/next-server", next, SR_STRING_T);
153 setItem(xpath +
"/server-hostname", hostname, SR_STRING_T);
158 setItem(xpath +
"/boot-file-name", boot, SR_STRING_T);
161 }
else if (
model_ == KEA_DHCP6_SERVER) {
168 setItem(xpath +
"/user-context", Element::create(context->str()),
175 setItem(xpath, list, SR_LIST_T);
194 if ((
model_ == KEA_DHCP4_SERVER) ||
195 (
model_ == KEA_DHCP6_SERVER)) {
198 }
catch (
const sysrepo_exception& ex) {
200 "sysrepo error getting client classes at '" << xpath
201 <<
"': " << ex.
what());
204 "getClasses not implemented for the model: " <<
model_);
209 return getList<TranslatorClass>(xpath +
"/client-class", *
this,
216 if ((
model_ == KEA_DHCP4_SERVER) ||
217 (
model_ == KEA_DHCP6_SERVER)) {
221 "setClasses not implemented for the model: " <<
model_);
223 }
catch (
const sysrepo_exception& ex) {
225 "sysrepo error setting client classes '" << elem->str()
226 <<
"' at '" << xpath <<
"': " << ex.
what());
232 for (
size_t i = 0; i < elem->size(); ++i) {
234 if (!cclass->contains(
"name")) {
237 string name = cclass->get(
"name")->stringValue();
239 key << xpath <<
"/client-class[name='" << name <<
"']";
void checkAndSetLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, sr_type_t const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
A generic exception that is thrown when a function is not implemented.
isc::data::ElementPtr getClassKea(const std::string &xpath)
getClass JSON for kea-dhcp[46].
Between YANG and JSON translator class for basic values.
Currently supports kea-dhcp[46]-server models.
boost::shared_ptr< Element > ElementPtr
isc::data::ConstElementPtr getOptionDefList(const std::string &xpath)
Get and translate option definition list from YANG to JSON.
virtual ~TranslatorClasses()
Destructor.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void setClasses(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set client classes from JSON to YANG.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Client class translation between YANG and JSON.
TranslatorClasses(sysrepo::S_Session session, const std::string &model)
Constructor.
void setItem(const std::string &xpath, isc::data::ConstElementPtr elem, sr_type_t type)
Translate and set basic value from JSON to YANG.
A translator class for converting an option data list between YANG and JSON.
A generic exception that is thrown when an unexpected error condition occurs.
void setClassKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setClass for kea-dhcp[46].
std::string model_
The model.
virtual ~TranslatorClass()
Destructor.
boost::shared_ptr< const Element > ConstElementPtr
void setClassesKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setClasses for kea-dhcp[46].
static isc::data::ConstElementPtr getContext(isc::data::ConstElementPtr parent)
Get user context.
isc::data::ConstElementPtr getClasses(const std::string &xpath)
Get and translate client classes from YANG to JSON.
void setOptionDefList(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set option definition list from JSON to YANG.
Defines the logger used by the top-level component of kea-lfc.
isc::data::ConstElementPtr getOptionDataList(const std::string &xpath)
Get and translate option data list from YANG to JSON.
void setClass(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set client class from JSON to YANG.
isc::data::ElementPtr getItem(const std::string &xpath)
Get and translate basic value from YANG to JSON.
isc::data::ElementPtr getClass(const std::string &xpath)
Get and translate a client class from YANG to JSON.
void checkAndGetLeaf(isc::data::ElementPtr &storage, const std::string &xpath, const std::string &name)
Retrieves an item and stores it in the specified storage.
isc::data::ElementPtr getClassesKea(const std::string &xpath)
getClasses JSON for kea-dhcp[46].
Option data translation between YANG and JSON.
void setOptionDataList(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set option data list from JSON to YANG.
Option definition translation between YANG and JSON.