Kea 2.7.4
isc::yang::Translator Class Reference

Between YANG and JSON translator class for basic values. More...

#include <translator.h>

+ Inheritance diagram for isc::yang::Translator:

Public Member Functions

 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.
 

Static Public Member Functions

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

using Deserializer
 Maps YANG types to functions that transform a YANG type into an ElementPtr.
 
using Serializer
 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

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

std::string model_
 The model.
 
sysrepo::Session session_
 The sysrepo session.
 

Detailed Description

Between YANG and JSON translator class for basic values.

Definition at line 23 of file translator.h.

Member Typedef Documentation

◆ Deserializer

Initial value:
std::unordered_map<libyang::LeafBaseType,
std::function<isc::data::ElementPtr const(std::string const&)>>
boost::shared_ptr< Element > ElementPtr
Definition data.h:28

Maps YANG types to functions that transform a YANG type into an ElementPtr.

Definition at line 402 of file translator.h.

◆ Serializer

Initial value:
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().

Definition at line 413 of file translator.h.

Constructor & Destructor Documentation

◆ Translator()

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

Constructor.

Parameters
sessionSysrepo session.
modelModel name (used and shared by derived classes).

Definition at line 27 of file translator.cc.

◆ ~Translator()

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

Destructor.

Member Function Documentation

◆ checkAndGet()

template<typename T >
void isc::yang::Translator::checkAndGet ( isc::data::ElementPtr const & storage,
libyang::DataNode const & data_node,
std::string const & xpath,
T translate ) const
inline

Calls {translate} for the element found at {xpath} relative to {data_node} and sets the result in {storage} with the {xpath} key.

Template Parameters
Ttypename of the function to be called
Parameters
storageElementMap where result will be stored
data_nodeparent data node of container type
xpathrelative xpath to search by
translatefunction to be called to translate a data node to an element pointer

Definition at line 44 of file translator.h.

Referenced by isc::yang::TranslatorConfig::getServerKeaDhcp4(), isc::yang::TranslatorConfig::getServerKeaDhcpCommon(), isc::yang::TranslatorSharedNetwork::getSharedNetworkKea(), isc::yang::TranslatorSubnet::getSubnetIetf6(), and isc::yang::TranslatorSubnet::getSubnetKea().

◆ checkAndGetAndJsonifyLeaf()

void isc::yang::Translator::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.

Parameters
storageElementMap where result will be stored
data_nodeparent data node of container type
namethe name of the parameter to be set in storage

Definition at line 53 of file translator.cc.

References isc::data::Element::fromJSON(), and getItem().

Referenced by isc::yang::TranslatorClass::getClassKea(), isc::yang::TranslatorControlSocket::getControlSocketKea(), isc::yang::TranslatorDatabase::getDatabaseKea(), isc::yang::TranslatorConfig::getDdnsKea(), isc::yang::TranslatorConfig::getHook(), isc::yang::TranslatorHost::getHostKea(), isc::yang::TranslatorConfig::getInterfacesKea(), isc::yang::TranslatorLogger::getLoggerKea(), isc::yang::TranslatorOptionData::getOptionDataKea(), isc::yang::TranslatorOptionDef::getOptionDefKea(), isc::yang::TranslatorPdPool::getPdPoolKea(), isc::yang::TranslatorPool::getPoolKea(), isc::yang::TranslatorConfig::getServerKeaDhcp6(), isc::yang::TranslatorConfig::getServerKeaDhcpCommon(), isc::yang::TranslatorSharedNetwork::getSharedNetworkKea(), and isc::yang::TranslatorSubnet::getSubnetKea().

+ Here is the call graph for this function:

◆ checkAndGetDiverging()

template<typename T >
void isc::yang::Translator::checkAndGetDiverging ( isc::data::ElementPtr const & storage,
libyang::DataNode const & data_node,
std::string const & key,
std::string const & xpath,
T translate ) const
inline

Calls {translate} for the element found at {xpath} relative to {data_node} and sets the result in {storage} with the {key} key.

It's the counterpart for checkAndGet, but when the YANG xpath and the JSON key diverge.

Template Parameters
Ttypename of the function to be called
Parameters
storageElementMap where result will be stored
data_nodeparent data node of container type
keywhere to set the result in the {storage} map
xpathrelative xpath to search by
translatefunction to be called to translate a data node to an element pointer

Definition at line 71 of file translator.h.

Referenced by isc::yang::TranslatorConfig::getConfigIetf6(), and isc::yang::TranslatorSubnet::getSubnetIetf6().

◆ checkAndGetDivergingLeaf()

void isc::yang::Translator::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.

It's the counterpart for checkAndGetLeaf, but when the YANG xpath and the JSON key diverge.

Parameters
storageElementMap where result will be stored
data_nodeparent data node of container type
namethe name of the parameter to be set in storage
yang_namethe name by which to find the parameter in the YANG data node

Definition at line 42 of file translator.cc.

References getItem().

Referenced by isc::yang::TranslatorPdPool::getPdPoolIetf6(), isc::yang::TranslatorPool::getPoolIetf6(), and isc::yang::TranslatorSubnet::getSubnetKea().

+ Here is the call graph for this function:

◆ checkAndGetLeaf()

void isc::yang::Translator::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.

Parameters
storageElementMap where result will be stored
data_nodeparent data node of container type
namethe name of the parameter to be set in storage

Definition at line 32 of file translator.cc.

References getItem().

Referenced by isc::yang::TranslatorClass::getClassKea(), isc::yang::TranslatorConfig::getConfigControlKea(), isc::yang::TranslatorDatabase::getDatabaseKea(), isc::yang::TranslatorConfig::getDdnsKea(), isc::yang::TranslatorConfig::getExpiredKea(), isc::yang::TranslatorConfig::getHook(), isc::yang::TranslatorHost::getHostKea(), isc::yang::TranslatorConfig::getInterfacesKea(), isc::yang::TranslatorLogger::getLoggerKea(), isc::yang::TranslatorOptionData::getOptionDataKea(), isc::yang::TranslatorOptionDef::getOptionDefKea(), isc::yang::TranslatorLogger::getOutputOption(), isc::yang::TranslatorPdPool::getPdPoolIetf6(), isc::yang::TranslatorPdPool::getPdPoolKea(), isc::yang::TranslatorPool::getPoolIetf6(), isc::yang::TranslatorPool::getPoolKea(), isc::yang::TranslatorConfig::getServerKeaDhcp4(), isc::yang::TranslatorConfig::getServerKeaDhcp6(), isc::yang::TranslatorConfig::getServerKeaDhcpCommon(), isc::yang::TranslatorSharedNetwork::getSharedNetworkKea(), and isc::yang::TranslatorSubnet::getSubnetKea().

+ Here is the call graph for this function:

◆ checkAndSetDivergingLeaf()

void isc::yang::Translator::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.

It's the counterpart for checkAndSetLeaf, but when the YANG xpath and the JSON key diverge.

Parameters
fromthe parent configuration node from which to take the value
xpaththe xpath to the YANG node without the last node
namethe key under which data is set in the MapElement {from}
yang_namethe name of the YANG node
typethe YANG node type

Definition at line 74 of file translator.cc.

References setItem().

Referenced by isc::yang::TranslatorPdPool::setPdPoolIetf6(), isc::yang::TranslatorPool::setPoolIetf6(), and isc::yang::TranslatorSubnet::setSubnetKea().

+ Here is the call graph for this function:

◆ checkAndSetLeaf()

void isc::yang::Translator::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.

Parameters
fromthe parent configuration node from which to take the value
xpaththe xpath to the YANG node without the last node
namethe name of the YANG node which should also match the key under which data is set in the MapElement {from}
typethe YANG node type

Definition at line 63 of file translator.cc.

References setItem().

Referenced by isc::yang::TranslatorClass::setClassKea(), isc::yang::TranslatorDatabase::setDatabaseKea(), isc::yang::TranslatorHost::setHostKea(), isc::yang::TranslatorLogger::setLoggerKea(), isc::yang::TranslatorOptionData::setOptionDataKea(), isc::yang::TranslatorOptionDef::setOptionDefKea(), isc::yang::TranslatorLogger::setOutputOption(), isc::yang::TranslatorPdPool::setPdPoolIetf6(), isc::yang::TranslatorPdPool::setPdPoolKea(), isc::yang::TranslatorPool::setPoolIetf6(), isc::yang::TranslatorPool::setPoolKea(), isc::yang::TranslatorConfig::setServerKeaDhcp4(), isc::yang::TranslatorConfig::setServerKeaDhcp6(), isc::yang::TranslatorConfig::setServerKeaDhcpCommon(), isc::yang::TranslatorSharedNetwork::setSharedNetworkKea(), and isc::yang::TranslatorSubnet::setSubnetKea().

+ Here is the call graph for this function:

◆ checkAndSetLeafList()

void isc::yang::Translator::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.

Parameters
fromthe parent configuration node from which to take the values
xpaththe xpath to the YANG node without the last node
namethe name of the YANG node which should also match the key under which data is set in the MapElement {from}
typethe YANG node type of the underlying leaf-list nodes

Definition at line 86 of file translator.cc.

References setItem().

Referenced by isc::yang::TranslatorHost::setHostKea(), isc::yang::TranslatorPdPool::setPdPoolKea(), isc::yang::TranslatorPool::setPoolKea(), isc::yang::TranslatorConfig::setServerKeaDhcp4(), isc::yang::TranslatorConfig::setServerKeaDhcp6(), isc::yang::TranslatorConfig::setServerKeaDhcpCommon(), isc::yang::TranslatorSharedNetwork::setSharedNetworkKea(), and isc::yang::TranslatorSubnet::setSubnetKea().

+ Here is the call graph for this function:

◆ checkAndSetUserContext()

void isc::yang::Translator::checkAndSetUserContext ( isc::data::ConstElementPtr const & from,
std::string const & xpath )

◆ checkAndStringifyAndSetLeaf()

void isc::yang::Translator::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.

Parameters
fromthe parent configuration node from which to take the value
xpaththe xpath to the YANG node without the last node
namethe name of the YANG node which should also match the key under which data is set in the MapElement {from}

Definition at line 109 of file translator.cc.

References isc::data::Element::create(), and setItem().

Referenced by isc::yang::TranslatorConfig::setServerKeaDhcpCommon().

+ Here is the call graph for this function:

◆ decode64()

string isc::yang::Translator::decode64 ( std::string const & input)
staticprotected

Decode a YANG element of binary type to a string that can be stored in an Element::string JSON.

Parameters
inputstring to be decoded
Returns
the decoded string

Definition at line 313 of file translator.cc.

References isc::util::encode::decodeBase64().

Referenced by initializeDeserializer().

+ Here is the call graph for this function:

◆ deleteItem()

void isc::yang::Translator::deleteItem ( const std::string & xpath)

Delete basic value from YANG.

Parameters
xpathThe xpath of the basic value.

Definition at line 120 of file translator.cc.

References isc_throw, session_, and isc::Exception::what().

Referenced by isc::yang::TranslatorConfig::delConfigIetf6(), isc::yang::TranslatorConfig::delConfigKea(), isc::yang::TranslatorControlSocket::setControlSocketKea(), isc::yang::TranslatorDatabase::setDatabaseKea(), and isc::yang::TranslatorDatabases::setDatabasesKea().

+ Here is the call graph for this function:

◆ encode64()

string isc::yang::Translator::encode64 ( std::string const & input)
staticprotected

Encode a string such that it can be stored in a YANG element of binary type.

Parameters
inputstring to be encoded
Returns
the encoded string

Definition at line 323 of file translator.cc.

References isc::util::encode::encodeBase64().

Referenced by initializeSerializer().

+ Here is the call graph for this function:

◆ findXPath()

DataNode isc::yang::Translator::findXPath ( std::string const & xpath) const

Retrieves a YANG data node by xpath.

Note
This is a computationally expensive operation that makes a lookup in the sysrepo datastore by calling Session::getData(). It should be used sparingly in production code, mainly to get an initial data node to work with. It may be used at will in unit tests.
Parameters
xpaththe xpath of the requested node
Returns
the requested YANG data node
Exceptions
NetconfErrorif no YANG data node was found

Definition at line 132 of file translator.cc.

References getData(), and isc_throw.

Referenced by isc::yang::TranslatorClasses::getClassesFromAbsoluteXpath(), isc::yang::TranslatorClass::getClassFromAbsoluteXpath(), isc::yang::TranslatorConfig::getConfigIetf6(), isc::yang::TranslatorControlSocket::getControlSocketFromAbsoluteXpath(), isc::yang::TranslatorDatabase::getDatabaseFromAbsoluteXpath(), isc::yang::TranslatorDatabases::getDatabasesFromAbsoluteXpath(), isc::yang::TranslatorHost::getHostFromAbsoluteXpath(), isc::yang::TranslatorHosts::getHostsFromAbsoluteXpath(), isc::yang::TranslatorLoggers::getLoggersFromAbsoluteXpath(), isc::yang::TranslatorOptionData::getOptionDataFromAbsoluteXpath(), isc::yang::TranslatorOptionDataList::getOptionDataListFromAbsoluteXpath(), isc::yang::TranslatorOptionDef::getOptionDefFromAbsoluteXpath(), isc::yang::TranslatorOptionDefList::getOptionDefListFromAbsoluteXpath(), isc::yang::TranslatorPdPool::getPdPoolFromAbsoluteXpath(), isc::yang::TranslatorPdPools::getPdPoolsFromAbsoluteXpath(), isc::yang::TranslatorPool::getPoolFromAbsoluteXpath(), isc::yang::TranslatorPools::getPoolsFromAbsoluteXpath(), isc::yang::TranslatorConfig::getServerKeaDhcp4(), isc::yang::TranslatorConfig::getServerKeaDhcp6(), isc::yang::TranslatorSharedNetwork::getSharedNetworkFromAbsoluteXpath(), isc::yang::TranslatorSharedNetworks::getSharedNetworksFromAbsoluteXpath(), isc::yang::TranslatorSubnet::getSubnetFromAbsoluteXpath(), and isc::yang::TranslatorSubnets::getSubnetsFromAbsoluteXpath().

+ Here is the call graph for this function:

◆ forAll()

template<typename functor_t >
void isc::yang::Translator::forAll ( std::string const & xpath,
functor_t f ) const
inline

Run a function for a node and all its children.

Template Parameters
functor_ttypename of the function to be called
Note
This is a computationally expensive operation that makes a lookup in the sysrepo datastore by calling Session::getData(). It should be used sparingly in production code. It is primarily meant for unit tests.
Parameters
xpaththe xpath of the root node belonging to the tree being traversed
fthe function to be called on the node itself and each descendant

Definition at line 211 of file translator.h.

References session_.

◆ getData()

optional< DataNode > isc::yang::Translator::getData ( std::string const & xpath) const

Get a YANG data node found at the given absolute xpath.

Note
This is a computationally expensive operation that makes a lookup in the sysrepo datastore by calling Session::getData(). It should be used sparingly in production code, mainly to get an initial data node to work with. It may be used at will in unit tests.
Parameters
xpaththe xpath at which the YANG data node is to be found
Returns
a DataNode if found, or nullopt otherwise
Exceptions
NetconfErrorwhen the used sysrepo API throws an error

Definition at line 145 of file translator.cc.

References isc_throw, session_, and isc::Exception::what().

Referenced by findXPath(), and getItemFromAbsoluteXpath().

+ Here is the call graph for this function:

◆ getItem()

ElementPtr isc::yang::Translator::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.

Parameters
data_nodethe source data node
xpaththe relative xpath
Returns
The Element representing the item at xpath or null when not found.
Exceptions
NetconfErrorwhen sysrepo raises an error.

Definition at line 157 of file translator.cc.

References isc::data::Element::createList(), isc_throw, translateFromYang(), and isc::Exception::what().

Referenced by checkAndGetAndJsonifyLeaf(), checkAndGetDivergingLeaf(), checkAndGetLeaf(), isc::yang::TranslatorHost::getHostKea(), getItemFromAbsoluteXpath(), getMandatoryDivergingLeaf(), getMandatoryLeaf(), isc::yang::TranslatorOptionData::getOptionDataKea(), isc::yang::TranslatorPdPool::getPdPoolIetf6(), isc::yang::TranslatorPdPool::getPdPoolKea(), isc::yang::TranslatorPool::getPoolKea(), and isc::yang::TranslatorSubnet::getSubnetIetf6().

+ Here is the call graph for this function:

◆ getItemFromAbsoluteXpath()

ElementPtr isc::yang::Translator::getItemFromAbsoluteXpath ( std::string const & xpath) const

Translate a basic value from YANG to JSON for a given absolute xpath.

Note
This is a computationally expensive operation that makes a lookup in the sysrepo datastore by calling Session::getData(). It should be used sparingly in production code, mainly to get an initial data node to work with. It may be used at will in unit tests.
Parameters
xpathThe xpath of the basic value.
Returns
The Element representing the item at xpath or null when not found.
Exceptions
NetconfErrorwhen sysrepo raises an error.

Definition at line 188 of file translator.cc.

References getData(), and getItem().

+ Here is the call graph for this function:

◆ getList()

template<typename T >
isc::data::ElementPtr isc::yang::Translator::getList ( libyang::DataNode const & data_node,
std::string const & xpath,
T & t,
isc::data::ElementPtr(T::*)(libyang::DataNode const &) f ) const
inline

Retrieve a list as ElementPtr from sysrepo from a certain xpath.

Template Parameters
Ttypename of the translator that holds the function that will be called on the xpath of each child from the list
Parameters
data_nodethe YANG data node to retrieve data from
xpaththe xpath to the element to be retrieved from, relative to {data_node}
taddress of a translator instance that holds the function that will be called on the xpath of each child from the list
fthe function that will be called on the xpath of each child from the list

Definition at line 274 of file translator.h.

Referenced by isc::yang::TranslatorConfig::getHooksKea(), and isc::yang::TranslatorLogger::getOutputOptions().

◆ getMandatoryDivergingLeaf()

void isc::yang::Translator::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.

Unlike checkAndGetLeaf, the leaf is expected to be present.

Parameters
storageElementMap where result will be stored
data_nodeparent data node of container type
namethe map key in the JSON configuration
yang_namethe name by which to find the parameter in the YANG data node
Exceptions
MissingNodeif leaf is not found

Definition at line 208 of file translator.cc.

References getItem(), and isc_throw.

Referenced by isc::yang::TranslatorDatabase::getDatabaseKea(), isc::yang::TranslatorPdPool::getPdPoolIetf6(), isc::yang::TranslatorPool::getPoolIetf6(), and isc::yang::TranslatorSubnet::getSubnetIetf6().

+ Here is the call graph for this function:

◆ getMandatoryLeaf()

void isc::yang::Translator::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.

Unlike checkAndGetLeaf, the leaf is expected to be present.

Parameters
storageElementMap where result will be stored
data_nodeparent data node of container type
namethe name of the YANG node which should also match the map key in the JSON configuration
Exceptions
MissingNodeif leaf is not found

Definition at line 197 of file translator.cc.

References getItem(), and isc_throw.

Referenced by isc::yang::TranslatorClass::getClassKea(), isc::yang::TranslatorControlSocket::getControlSocketKea(), isc::yang::TranslatorLogger::getLoggerKea(), isc::yang::TranslatorOptionData::getOptionDataKea(), isc::yang::TranslatorOptionDef::getOptionDefKea(), isc::yang::TranslatorLogger::getOutputOption(), isc::yang::TranslatorSharedNetwork::getSharedNetworkKea(), and isc::yang::TranslatorSubnet::getSubnetKea().

+ Here is the call graph for this function:

◆ initializeDeserializer()

Translator::Deserializer isc::yang::Translator::initializeDeserializer ( )
staticprotected

Initializes the deserializer which is used to translate a YANG node to an ElementPtr.

Returns
a copy of the deserializer

Definition at line 331 of file translator.cc.

References isc::data::Element::create(), decode64(), and isc::data::Element::fromJSON().

Referenced by translateFromYang().

+ Here is the call graph for this function:

◆ initializeSerializer()

Translator::Serializer isc::yang::Translator::initializeSerializer ( )
staticprotected

Initializes the serializer which is used to translate the string value of an Element to a string that can be passed into Session::setItem().

Returns
a copy of the serializer

Definition at line 361 of file translator.cc.

References encode64().

Referenced by translateToYang().

+ Here is the call graph for this function:

◆ schemaNodeExists()

bool isc::yang::Translator::schemaNodeExists ( std::string const & xpath) const

Checks whether a YANG node exists in the schema.

Parameters
xpaththe xpath to be checked
Returns
true if the YANG node exists in the schema, false otherwise

Definition at line 220 of file translator.cc.

References session_.

◆ setItem()

◆ setMandatoryDivergingLeaf()

void isc::yang::Translator::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.

Parameters
fromthe parent configuration node from which to take the value
xpaththe xpath to the YANG node without the last node
namethe map key in the JSON configuration
yang_namethe name by which to find the parameter in the YANG data node
typethe YANG node type

Definition at line 257 of file translator.cc.

References isc_throw, and setItem().

Referenced by isc::yang::TranslatorDatabase::setDatabaseKea(), and isc::yang::TranslatorSubnet::setSubnetIetf6().

+ Here is the call graph for this function:

◆ setMandatoryLeaf()

void isc::yang::Translator::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.

Parameters
fromthe parent configuration node from which to take the value
xpaththe xpath to the YANG node without the last node
namethe name of the YANG node which should also match the map key in the JSON configuration
typethe YANG node type

Definition at line 245 of file translator.cc.

References isc_throw, and setItem().

Referenced by isc::yang::TranslatorControlSocket::setControlSocketKea(), and isc::yang::TranslatorOptionDef::setOptionDefKea().

+ Here is the call graph for this function:

◆ translateFromYang()

ElementPtr isc::yang::Translator::translateFromYang ( std::optional< libyang::DataNode > data_node)
static

Translate basic value from the given YANG data node to JSON element.

Parameters
data_nodethe YANG data node
Returns
the translated JSON element

Definition at line 270 of file translator.cc.

References initializeDeserializer().

Referenced by getItem(), and isc::netconf::NetconfAgent::logChanges().

+ Here is the call graph for this function:

◆ translateToYang()

optional< string > isc::yang::Translator::translateToYang ( isc::data::ConstElementPtr const & elem,
libyang::LeafBaseType const type )
static

Translate basic value from JSON to YANG.

Parameters
elemThe JSON element.
typeThe sysrepo type.
Returns
string representation of {elem}, or nullopt if {elem} is null

Definition at line 288 of file translator.cc.

References initializeSerializer(), isc_throw, isc::data::Element::list, isc::data::Element::map, and isc::data::Element::string.

Referenced by isc::netconf::NetconfAgent::logChanges(), and setItem().

+ Here is the call graph for this function:

Member Data Documentation

◆ model_

std::string isc::yang::Translator::model_
protected

The model.

Definition at line 427 of file translator.h.

Referenced by isc::yang::TranslatorConfig::delConfigIetf6(), isc::yang::TranslatorConfig::delConfigKea(), isc::yang::TranslatorClass::getClass(), isc::yang::TranslatorClasses::getClasses(), isc::yang::TranslatorClass::getClassKea(), isc::yang::TranslatorConfig::getConfig(), isc::yang::TranslatorControlSocket::getControlSocket(), isc::yang::TranslatorDatabase::getDatabase(), isc::yang::TranslatorDatabases::getDatabases(), isc::yang::TranslatorHost::getHost(), isc::yang::TranslatorHost::getHostKea(), isc::yang::TranslatorLogger::getLogger(), isc::yang::TranslatorLoggers::getLoggers(), isc::yang::TranslatorOptionData::getOptionData(), isc::yang::TranslatorOptionDataList::getOptionDataList(), isc::yang::TranslatorOptionDef::getOptionDef(), isc::yang::TranslatorOptionDefList::getOptionDefList(), isc::yang::TranslatorPdPool::getPdPool(), isc::yang::TranslatorPdPools::getPdPools(), isc::yang::TranslatorPool::getPool(), isc::yang::TranslatorPools::getPools(), isc::yang::TranslatorSharedNetwork::getSharedNetwork(), isc::yang::TranslatorSubnet::getSubnet(), isc::yang::TranslatorSubnet::getSubnetIetf6(), isc::yang::TranslatorSubnet::getSubnetKea(), isc::yang::TranslatorSubnets::getSubnets(), isc::yang::TranslatorClass::setClass(), isc::yang::TranslatorClasses::setClasses(), isc::yang::TranslatorClass::setClassKea(), isc::yang::TranslatorConfig::setConfig(), isc::yang::TranslatorConfig::setConfigIetf6(), isc::yang::TranslatorControlSocket::setControlSocket(), isc::yang::TranslatorDatabase::setDatabase(), isc::yang::TranslatorDatabases::setDatabases(), isc::yang::TranslatorHost::setHost(), isc::yang::TranslatorHost::setHostKea(), isc::yang::TranslatorHosts::setHosts(), isc::yang::TranslatorHosts::setHostsKea(), isc::yang::TranslatorLogger::setLogger(), isc::yang::TranslatorLoggers::setLoggers(), isc::yang::TranslatorOptionData::setOptionData(), isc::yang::TranslatorOptionDataList::setOptionDataList(), isc::yang::TranslatorOptionDef::setOptionDef(), isc::yang::TranslatorOptionDefList::setOptionDefList(), isc::yang::TranslatorPdPool::setPdPool(), isc::yang::TranslatorPdPools::setPdPools(), isc::yang::TranslatorPool::setPool(), isc::yang::TranslatorPools::setPools(), isc::yang::TranslatorSharedNetwork::setSharedNetwork(), isc::yang::TranslatorSharedNetworks::setSharedNetworks(), isc::yang::TranslatorSubnet::setSubnet(), isc::yang::TranslatorSubnet::setSubnetIetf6(), isc::yang::TranslatorSubnet::setSubnetKea(), and isc::yang::TranslatorSubnets::setSubnets().

◆ session_

sysrepo::Session isc::yang::Translator::session_
protected

The sysrepo session.

Definition at line 424 of file translator.h.

Referenced by deleteItem(), forAll(), getData(), schemaNodeExists(), and setItem().


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