Kea 2.2.0
isc::yang::TranslatorDatabase Class Reference

Database access translation between YANG and JSON. More...

#include <translator_database.h>

+ Inheritance diagram for isc::yang::TranslatorDatabase:

Public Member Functions

 TranslatorDatabase (sysrepo::S_Session session, const std::string &model)
 Constructor. More...
 
virtual ~TranslatorDatabase ()
 Destructor. More...
 
isc::data::ElementPtr getDatabase (const std::string &xpath)
 Get and translate a database access from YANG to JSON. More...
 
void setDatabase (const std::string &xpath, isc::data::ConstElementPtr elem, bool skip=false)
 Translate and set database access from JSON to YANG. More...
 
- Public Member Functions inherited from isc::yang::TranslatorBasic
 TranslatorBasic (sysrepo::S_Session session, const std::string &model)
 Constructor. More...
 
virtual ~TranslatorBasic ()
 Destructor. More...
 
void checkAndGetLeaf (isc::data::ElementPtr &storage, const std::string &xpath, const std::string &name)
 Retrieves an item and stores it in the specified storage. More...
 
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. More...
 
void delItem (const std::string &xpath)
 Delete basic value from YANG. More...
 
template<typename functor_t >
void forAll (std::string const &xpath, functor_t f)
 Run a function for a node and all its children. More...
 
isc::data::ElementPtr getItem (const std::string &xpath)
 Get and translate basic value from YANG to JSON. More...
 
isc::data::ElementPtr getItems (const std::string &xpath)
 Get and translate a list of basic values from YANG to JSON. More...
 
template<typename T >
isc::data::ElementPtr getList (std::string const &xpath, T &t, isc::data::ElementPtr(T::*f)(std::string const &xpath))
 Retrieve a list as ElementPtr from sysrepo from a certain xpath. More...
 
sysrepo::S_Vals getValuesFromItems (std::string const &xpath)
 Get the values of all siblings at a certain xpath. More...
 
void setItem (const std::string &xpath, isc::data::ConstElementPtr elem, sr_type_t type)
 Translate and set basic value from JSON to YANG. More...
 

Protected Member Functions

isc::data::ElementPtr getDatabaseKea (const std::string &xpath)
 getDatabase JSON for kea-dhcp[46]-server models. More...
 
void setDatabaseKea (const std::string &xpath, isc::data::ConstElementPtr elem, bool skip)
 setDatabase for kea-dhcp[46]-server models. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from isc::yang::TranslatorBasic
static sysrepo::S_Val value (isc::data::ConstElementPtr elem, sr_type_t type)
 Translate basic value from JSON to YANG. More...
 
static isc::data::ElementPtr value (sysrepo::S_Val s_val)
 Translate basic value from YANG to JSON. More...
 
- Protected Attributes inherited from isc::yang::TranslatorBasic
std::string model_
 The model. More...
 
sysrepo::S_Session session_
 The sysrepo session. More...
 

Detailed Description

Database access translation between YANG and JSON.

JSON syntax for all Kea servers with database access is:

{
"type": <type>,
"user": <user>,
"password": <password>,
"host": <host>,
"name": <name>,
"persist": <persist flag>,
"port": <port>,
"lfc-interval": <lfc interval>,
"readonly": <readonly flag>,
"trust-anchor": <trust anchor>,
"cert-file": <cert file>,
"key-file": <key file>,
"cipher-list": <cipher list>,
"connect-timeout": <connect timeout>,
"max-reconnect-tries": <maximum reconnect tries>,
"reconnect-wait-time": <reconnect wait time>,
"max-row-errors": <maximum row errors>,
"user-context": { <json map> },
"comment": <comment>
}

YANG syntax for kea-dhcp[46] is using database-type as the list key:

+--rw database
+--rw database-type string
+--rw user? string
+--rw password? string
+--rw host? string
+--rw name? string
+--rw persist? boolean
+--rw port? uint16
+--rw lfc-interval? uint32
+--rw readonly? boolean
+--rw trust-anchor? string
+--rw cert-file? string
+--rw key-file? string
+--rw cipher-list? string
+--rw connect-timeout? uint32
+--rw max-reconnect-tries? uint32
+--rw reconnect-wait-time? uint32
+--rw max-row-errors? uint32
+--rw on-fail? string
+--rw user-context? user-context

An example in JSON and YANG formats:

[
{
"type": "mysql",
"name": "kea",
"user": "kea",
"password": "kea",
"host": "localhost",
"port": 3306
}
]
/kea-dhcp6-server:config (container)
/kea-dhcp6-server:config/
hosts-database[database-type='mysql'] (list instance)
/kea-dhcp6-server:config/
hosts-database[database-type='mysql']/type = mysql
/kea-dhcp6-server:config/
hosts-database[database-type='mysql']/name = kea
/kea-dhcp6-server:config/
hosts-database[database-type='mysql']/user = kea
/kea-dhcp6-server:config/
hosts-database[database-type='mysql']/password = kea
/kea-dhcp6-server:config/
hosts-database[database-type='mysql']/host = localhost
/kea-dhcp6-server:config/
hosts-database[database-type='mysql']/port = 3306

A translator class for converting a database access parameters between YANG and JSON.

Supports the following models:

  • kea-dhcp4-server
  • kea-dhcp6-server

Definition at line 104 of file translator_database.h.

Constructor & Destructor Documentation

◆ TranslatorDatabase()

isc::yang::TranslatorDatabase::TranslatorDatabase ( sysrepo::S_Session  session,
const std::string &  model 
)

Constructor.

Parameters
sessionSysrepo session.
modelModel name.

Definition at line 21 of file translator_database.cc.

◆ ~TranslatorDatabase()

isc::yang::TranslatorDatabase::~TranslatorDatabase ( )
virtual

Destructor.

Definition at line 25 of file translator_database.cc.

Member Function Documentation

◆ getDatabase()

ElementPtr isc::yang::TranslatorDatabase::getDatabase ( const std::string &  xpath)

Get and translate a database access from YANG to JSON.

Parameters
xpathThe xpath of the database.
Returns
JSON representation of the database.
Exceptions
SysrepoErrorwhen sysrepo raises an error.

Definition at line 29 of file translator_database.cc.

References getDatabaseKea(), isc_throw, isc::yang::TranslatorBasic::model_, and isc::Exception::what().

Referenced by isc::yang::TranslatorDatabases::getDatabasesKea(), and isc::yang::TranslatorConfig::getServerKeaDhcpCommon().

+ Here is the call graph for this function:

◆ getDatabaseKea()

ElementPtr isc::yang::TranslatorDatabase::getDatabaseKea ( const std::string &  xpath)
protected

getDatabase JSON for kea-dhcp[46]-server models.

Parameters
xpathThe xpath of the database.
Returns
JSON representation of the database or null if none.
Exceptions
SysrepoErrorwhen sysrepo raises an error.

Definition at line 45 of file translator_database.cc.

References isc::yang::TranslatorBasic::checkAndGetLeaf(), and isc::yang::TranslatorBasic::getItem().

Referenced by getDatabase().

+ Here is the call graph for this function:

◆ setDatabase()

void isc::yang::TranslatorDatabase::setDatabase ( const std::string &  xpath,
isc::data::ConstElementPtr  elem,
bool  skip = false 
)

Translate and set database access from JSON to YANG.

Null elem argument removes the database entry.

Parameters
xpathThe xpath of the database access.
elemThe JSON element.
skipThe skip type field flag.

Definition at line 77 of file translator_database.cc.

References isc_throw, isc::yang::TranslatorBasic::model_, setDatabaseKea(), and isc::Exception::what().

Referenced by isc::yang::TranslatorDatabases::setDatabasesKea(), and isc::yang::TranslatorConfig::setServerKeaDhcpCommon().

+ Here is the call graph for this function:

◆ setDatabaseKea()

void isc::yang::TranslatorDatabase::setDatabaseKea ( const std::string &  xpath,
isc::data::ConstElementPtr  elem,
bool  skip 
)
protected

setDatabase for kea-dhcp[46]-server models.

Parameters
xpathThe xpath of the database access.
elemThe JSON element.
skipThe skip type field flag.
Exceptions
BadValueon database without type,

Definition at line 96 of file translator_database.cc.

References isc::yang::TranslatorBasic::checkAndSetLeaf(), isc::yang::TranslatorBasic::delItem(), isc::yang::Adaptor::getContext(), isc_throw, and isc::yang::TranslatorBasic::setItem().

Referenced by setDatabase().

+ Here is the call graph for this function:

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