Kea 2.7.5
isc::yang::Adaptor Class Reference

JSON adaptor between canonical Kea and YANG models. More...

#include <adaptor.h>

Public Member Functions

virtual ~Adaptor ()=default
 Destructor.
 

Static Public Member Functions

static void fromParent (const std::string &name, isc::data::ConstElementPtr parent, isc::data::ConstElementPtr list)
 Moves a parameter from parent to a list of children.
 
static isc::data::ConstElementPtr getContext (isc::data::ConstElementPtr parent)
 Get user context.
 
static void modify (isc::data::ConstElementPtr path, isc::data::ConstElementPtr actions, isc::data::ElementPtr config)
 Modify a configuration in its JSON element format.
 
static void toParent (const std::string &name, isc::data::ElementPtr parent, isc::data::ConstElementPtr list)
 Moves a parameter to a parent.
 

Detailed Description

JSON adaptor between canonical Kea and YANG models.

An adaptor slightly modifies a JSON configuration between canonical Kea what required or rendered by a YANG model, e.g. moving a parameter to/from a parent. The basic adaptor provides a set of tools.

Definition at line 22 of file adaptor.h.

Constructor & Destructor Documentation

◆ ~Adaptor()

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

Destructor.

Member Function Documentation

◆ fromParent()

void isc::yang::Adaptor::fromParent ( const std::string & name,
isc::data::ConstElementPtr parent,
isc::data::ConstElementPtr list )
static

Moves a parameter from parent to a list of children.

Move a parameter from the parent to each item in a list. If the parameter exists in a child, it is skipped for this particular child, not overridden.

Parameters
nameThe parameter name.
parentThe parent element.
listThe children list.

Definition at line 37 of file adaptor.cc.

Referenced by isc::yang::AdaptorPool::fromSubnetIetf6().

◆ getContext()

ConstElementPtr isc::yang::Adaptor::getContext ( isc::data::ConstElementPtr parent)
static

Get user context.

Get user-context and/or comment and return it with the comment if exists moved inside the user-context (without checking if there is already a comment as it should never be the case).

This behavior is used to handle comments. For historical purposes Kea allows to define comments in some scopes. Once the user-context has been introduced, the comment (as a separate text field) disappeared and was moved to comment key within user-context. Nevertheless, the old syntax is still supported.

Definition at line 20 of file adaptor.cc.

References isc::data::copy(), and isc::data::Element::createMap().

Referenced by isc::yang::Translator::checkAndSetUserContext().

+ Here is the call graph for this function:

◆ modify()

void isc::yang::Adaptor::modify ( isc::data::ConstElementPtr path,
isc::data::ConstElementPtr actions,
isc::data::ElementPtr config )
static

Modify a configuration in its JSON element format.

Apply recursively starting at the beginning of the path.

Smart merging tool, e.g. completing an ElementPtr received from YANG.

A modification is a path and actions:

  • path item can be:

    • a string: current scope is a map, go down following the string as a key.
    • a number: current scope is a list, go down the number as an index.
    • special value -1: current scope is a list, apply to all items.
    • map { "<key>":

    }: current scope is a list, go down to the item using the key / value pair.

  • an action can be: insert, replace or delete:
    • insert adds a value at a key: . in a map the key is the new entry key . in a list an integer key is the new element index . in a list a map key is the key / value pair the to-be-modified element contains
    • replace adds or replaces if it already exists a value at an entry key in a map.
    • delete removes a value designed by a key

For instance to add a control-socket entry in a configuration from a generic (vs Kea) model:

path := [ ]
actions := [ {
"action": "insert",
"key": "Dhcp4",
"value":
{
"control-socket":
{
"socket-type": "unix",
"socket-name": "/tmp/kea4-ctrl-socket"
}
}
}
Parameters
pathThe search list to follow down to the place to apply the action list.
actionsThe action list
configThe configuration (JSON map) to modify.
Note
modify does not throw but returns on unexpected conditions.

Definition at line 296 of file adaptor.cc.

◆ toParent()

void isc::yang::Adaptor::toParent ( const std::string & name,
isc::data::ElementPtr parent,
isc::data::ConstElementPtr list )
static

Moves a parameter to a parent.

Move a parameter from children to the parent. All children on the list must have the parameter specified and it has to have the same value.

Parameters
nameThe parameter name.
parentThe parent element.
listThe children list.

Definition at line 53 of file adaptor.cc.

References isc_throw.

Referenced by isc::yang::AdaptorPool::toSubnetIetf6().


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