Kea 2.5.8
isc::yang::TranslatorLogger Class Reference

Logger translation between YANG and JSON. More...

#include <translator_logger.h>

+ Inheritance diagram for isc::yang::TranslatorLogger:

Public Member Functions

 TranslatorLogger (sysrepo::Session session, const std::string &model)
 Constructor.
 
virtual ~TranslatorLogger ()=default
 Destructor.
 
isc::data::ElementPtr getLogger (libyang::DataNode const &data_node)
 Translate a logger from YANG to JSON.
 
void setLogger (const std::string &xpath, isc::data::ConstElementPtr elem)
 Translate and set logger from JSON to YANG.
 
- Public Member Functions inherited from isc::yang::Translator
 Translator (sysrepo::Session session, const std::string &model)
 Constructor.
 
virtual ~Translator ()=default
 Destructor.
 
template<typename T >
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 {storage} with the {xpath} key.
 
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, converts it from string to JSON and stores it in the specified storage.
 
template<typename T >
void checkAndGetDiverging (isc::data::ElementPtr const &storage, libyang::DataNode const &data_node, std::string const &key, std::string const &xpath, T translate) const
 Calls {translate} for the element found at {xpath} relative to {data_node} and sets the result in {storage} with the {key} key.
 
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 stores it in the specified storage.
 
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 stores it in the specified storage.
 
void checkAndSetDivergingLeaf (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.
 
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 checkAndSetLeafList (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 as a leaf-list.
 
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 checkAndStringifyAndSetLeaf (isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name)
 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.
 
libyang::DataNode findXPath (std::string const &xpath) const
 Retrieves a YANG data node by xpath.
 
template<typename functor_t >
void forAll (std::string const &xpath, functor_t f) const
 Run a function for a node and all its children.
 
std::optional< libyang::DataNode > getData (std::string const &xpath) const
 Get a YANG data node found at the given absolute xpath.
 
isc::data::ElementPtr getItem (libyang::DataNode const &data_node, std::string const &xpath) const
 Translate a basic value from YANG to JSON for a given xpath that is relative to the given source node.
 
isc::data::ElementPtr getItemFromAbsoluteXpath (std::string const &xpath) const
 Translate a basic value from YANG to JSON for a given absolute xpath.
 
template<typename T >
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 getMandatoryDivergingLeaf (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 one name from the given parent YANG container node and stores it in the specified storage under a different name.
 
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 stores it in the specified storage.
 
bool schemaNodeExists (std::string const &xpath) const
 Checks whether a YANG node exists in the schema.
 
void setItem (const std::string &xpath, isc::data::ConstElementPtr const elem, libyang::LeafBaseType const type)
 Translate and set basic value from JSON to YANG.
 
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.
 
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.
 

Protected Member Functions

isc::data::ElementPtr getLoggerKea (libyang::DataNode const &data_node)
 getLogger JSON for loggers.
 
isc::data::ElementPtr getOutputOption (libyang::DataNode const &data_node)
 Translate an output option from YANG to JSON.
 
isc::data::ElementPtr getOutputOptions (libyang::DataNode const &data_node)
 Translate output options from YANG to JSON.
 
void setLoggerKea (const std::string &xpath, isc::data::ConstElementPtr elem)
 setLogger for loggers.
 
void setOutputOption (const std::string &xpath, isc::data::ConstElementPtr elem)
 Translate and set an output option from JSON to YANG.
 
void setOutputOptions (const std::string &xpath, isc::data::ConstElementPtr elem)
 Translate and set output options from JSON to YANG.
 

Additional Inherited Members

- Static Public Member Functions inherited from isc::yang::Translator
static isc::data::ElementPtr translateFromYang (std::optional< libyang::DataNode > data_node)
 Translate basic value from the given YANG data node to JSON element.
 
static std::optional< std::string > translateToYang (isc::data::ConstElementPtr const &elem, libyang::LeafBaseType const type)
 Translate basic value from JSON to YANG.
 
- Protected Types inherited from isc::yang::Translator
using Deserializer = std::unordered_map< libyang::LeafBaseType, std::function< isc::data::ElementPtr const (std::string const &)> >
 Maps YANG types to functions that transform a YANG type into an ElementPtr.
 
using Serializer = std::unordered_map< libyang::LeafBaseType, std::function< std::string const (std::string const &)> >
 Maps YANG types to functions that transform the string representation of an Element into a string that can be passed into Session::setItem().
 
- Static Protected Member Functions inherited from isc::yang::Translator
static std::string decode64 (std::string const &input)
 Decode a YANG element of binary type to a string that can be stored in an Element::string JSON.
 
static std::string encode64 (std::string const &input)
 Encode a string such that it can be stored in a YANG element of binary type.
 
static Deserializer initializeDeserializer ()
 Initializes the deserializer which is used to translate a YANG node to an ElementPtr.
 
static Serializer initializeSerializer ()
 Initializes the serializer which is used to translate the string value of an Element to a string that can be passed into Session::setItem().
 
- Protected Attributes inherited from isc::yang::Translator
std::string model_
 The model.
 
sysrepo::Session session_
 The sysrepo session.
 

Detailed Description

Logger translation between YANG and JSON.

JSON syntax for all Kea servers with loggers is:

{
"name": <name>,
"output-options": [ <output options> ],
"severity": <severity>,
"debuglevel": <debug level>,
"user-context": { <json map> },
"comment": <comment>
}

JSON syntax for all Kea server for output options is:

{
"output": <output, e.g. log file name>,
"maxver": <maximum file version>,
"maxsize": <maximum file size>,
"flush": <flush flag>,
"pattern": <custom layout>
}
int version()
returns Kea hooks version.

YANG syntax for loggers is:

+--rw logger* [name]
+--rw name string
+--rw output-option* [output]
| +--rw output string
| +--rw flush? boolean
| +--rw maxsize? uint32
| +--rw maxver? uint32
| +--rw pattern? string
+--rw debuglevel? uint8
+--rw severity? enumeration
+--rw user-context? user-context

An example in JSON and YANG formats:

[
{
"name": "foo",
"severity": "WARN",
"output-options":
[
{
"output": "/bar",
"maxver": 10
}
]
}
]
/kea-dhcp4-server:config (container)
/kea-dhcp4-server:config/...
/kea-dhcp4-server:config/logger[name='foo'] (list instance)
/kea-dhcp4-server:config/logger[name='foo']/name = foo
/kea-dhcp4-server:config/logger[name='foo']/
option[output='/bar'] (list instance)
/kea-dhcp4-server:config/logger[name='foo']/
option[output='/bar']/option = /bar
/kea-dhcp4-server:config/logger[name='foo']/
option[output='/bar']/maxver = 10
/kea-dhcp4-server:config/logger[name='foo']/severity = WARN

A translator class for converting a logger between YANG and JSON.

Currently supports all kea models:

  • kea-dhcp4-server
  • kea-dhcp6-server
  • kea-dhcp-ddns
  • kea-ctrl-agent

Definition at line 93 of file translator_logger.h.

Constructor & Destructor Documentation

◆ TranslatorLogger()

isc::yang::TranslatorLogger::TranslatorLogger ( sysrepo::Session  session,
const std::string &  model 
)

Constructor.

Parameters
sessionSysrepo session.
modelModel name.

Definition at line 22 of file translator_logger.cc.

◆ ~TranslatorLogger()

virtual isc::yang::TranslatorLogger::~TranslatorLogger ( )
virtualdefault

Destructor.

Member Function Documentation

◆ getLogger()

ElementPtr isc::yang::TranslatorLogger::getLogger ( libyang::DataNode const &  data_node)

Translate a logger from YANG to JSON.

Parameters
data_nodethe YANG node representing the logger configuration
Returns
JSON representation of the logger.
Exceptions
NetconfErrorwhen sysrepo raises an error.

Definition at line 27 of file translator_logger.cc.

References getLoggerKea(), isc_throw, isc::yang::Translator::model_, and isc::Exception::what().

Referenced by isc::yang::TranslatorLoggers::getLoggersKea().

+ Here is the call graph for this function:

◆ getLoggerKea()

ElementPtr isc::yang::TranslatorLogger::getLoggerKea ( libyang::DataNode const &  data_node)
protected

getLogger JSON for loggers.

Parameters
data_nodethe YANG node representing the logger configuration
Returns
JSON representation of the logger.
Exceptions
NetconfErrorwhen sysrepo raises an error.

Definition at line 44 of file translator_logger.cc.

References isc::yang::Translator::checkAndGetAndJsonifyLeaf(), isc::yang::Translator::checkAndGetLeaf(), isc::data::Element::createMap(), isc::yang::Translator::getMandatoryLeaf(), and getOutputOptions().

Referenced by getLogger().

+ Here is the call graph for this function:

◆ getOutputOption()

ElementPtr isc::yang::TranslatorLogger::getOutputOption ( libyang::DataNode const &  data_node)
protected

Translate an output option from YANG to JSON.

Parameters
data_nodethe YANG node representing the output option
Returns
JSON representation of the output option.
Exceptions
NetconfErrorwhen sysrepo raises an error.

Definition at line 63 of file translator_logger.cc.

References isc::yang::Translator::checkAndGetLeaf(), isc::data::Element::createMap(), and isc::yang::Translator::getMandatoryLeaf().

Referenced by getOutputOptions().

+ Here is the call graph for this function:

◆ getOutputOptions()

ElementPtr isc::yang::TranslatorLogger::getOutputOptions ( libyang::DataNode const &  data_node)
protected

Translate output options from YANG to JSON.

Parameters
data_nodethe YANG node representing output options
Returns
JSON representation of output options.
Exceptions
NetconfErrorwhen sysrepo raises an error.

Definition at line 77 of file translator_logger.cc.

References isc::yang::Translator::getList(), and getOutputOption().

Referenced by getLoggerKea().

+ Here is the call graph for this function:

◆ setLogger()

void isc::yang::TranslatorLogger::setLogger ( const std::string &  xpath,
isc::data::ConstElementPtr  elem 
)

Translate and set logger from JSON to YANG.

Parameters
xpathThe xpath of the logger.
elemThe JSON element.

Definition at line 83 of file translator_logger.cc.

References isc_throw, isc::yang::Translator::model_, setLoggerKea(), and isc::Exception::what().

Referenced by isc::yang::TranslatorLoggers::setLoggersKea().

+ Here is the call graph for this function:

◆ setLoggerKea()

void isc::yang::TranslatorLogger::setLoggerKea ( const std::string &  xpath,
isc::data::ConstElementPtr  elem 
)
protected

setLogger for loggers.

Parameters
xpathThe xpath of the logger.
elemThe JSON element.

Definition at line 102 of file translator_logger.cc.

References isc::yang::Translator::checkAndSetLeaf(), isc::yang::Translator::checkAndSetUserContext(), isc::yang::Translator::setItem(), and setOutputOptions().

Referenced by setLogger().

+ Here is the call graph for this function:

◆ setOutputOption()

void isc::yang::TranslatorLogger::setOutputOption ( const std::string &  xpath,
isc::data::ConstElementPtr  elem 
)
protected

Translate and set an output option from JSON to YANG.

Parameters
xpathThe xpath of the output option.
elemThe JSON element.

Definition at line 120 of file translator_logger.cc.

References isc::yang::Translator::checkAndSetLeaf(), and isc::yang::Translator::setItem().

Referenced by setOutputOptions().

+ Here is the call graph for this function:

◆ setOutputOptions()

void isc::yang::TranslatorLogger::setOutputOptions ( const std::string &  xpath,
isc::data::ConstElementPtr  elem 
)
protected

Translate and set output options from JSON to YANG.

Parameters
xpathThe xpath of the output options.
elemThe JSON element.
Exceptions
BadValueon an output option without output.

Definition at line 131 of file translator_logger.cc.

References isc_throw, and setOutputOption().

Referenced by setLoggerKea().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: