This commit is contained in:
Olof Hagsand 2019-07-25 11:39:17 +00:00
parent e7b60619da
commit 5f7d011654
9 changed files with 66 additions and 27 deletions

View file

@ -183,11 +183,11 @@ Restconf support is also supported, see (restc)[../../apps/restconf/README.md].
## RPC Operations
Clixon implements Yang RPC operations by an extension mechanism. The
extension mechanism enables you to add application-specific
operations. It works by adding user-defined callbacks for added
netconf operations. It is possible to use the extension mechanism
independent of the yang rpc construct, but it is recommended. The example includes an example:
Clixon implements Yang RPC operations by a mechanism that enables you
to add application-specific operations. It works by adding
user-defined callbacks for added netconf operations. It is possible to
use the extension mechanism independent of the yang rpc construct, but
not recommended . The example includes an example:
Example using CLI:
```
@ -273,14 +273,14 @@ The example contains some stubs for authorization according to [RFC8341(NACM)](h
## Extensions
Clixon supports Yang extensions, but you need to write plugin code.
Clixon supports Yang extensions by writing plugin callback code.
The example backend implements an "example:e4" Yang extension, as follows:
```
extension e4 {
description
"The first child of the ex:e4 (unknown) statement is replaced with its first
child. This means that 'uses bar;' in the ex:e4 statement below is a valid
data node";
"The first child of the ex:e4 (unknown) statement is inserted into
the module as a regular data statement. This means that 'uses bar;'
in the ex:e4 statement below is a valid data node";
argument arg;
}
ex:e4 arg1{
@ -295,8 +295,8 @@ The backend plugin code registers an extension callback in the init struct:
The callback then receives a callback on all "unknown" Yang statements
during yang parsing. If the extension matches "example:e4", it applies
the extension. In the example, it replaces the "ex:e4" statements with
its first child, making it a proper yang statement.
the extension. In the example, it copies the child of the "ex:e4" statement and
inserts in as a proper yang statement in the example module.
## Systemd

View file

@ -45,9 +45,9 @@ module clixon-example {
/* yang extension implemented by the example backend code. */
extension e4 {
description
"The first child of the ex:e4 (unknown) statement is replaced with its first
child. This means that 'uses bar;' in the ex:e4 statement below is a valid
data node";
"The first child of the ex:e4 (unknown) statement is inserted into
the module as a regular data statement. This means that 'uses bar;'
in the ex:e4 statement below is a valid data node";
argument arg;
}
grouping bar {

View file

@ -369,6 +369,7 @@ example_extension(clicon_handle h,
char *modname;
yang_stmt *ymod;
yang_stmt *yc;
yang_stmt *yn = NULL;
ymod = ys_module(yext);
modname = yang_argument_get(ymod);
@ -376,9 +377,11 @@ example_extension(clicon_handle h,
if (strcmp(modname, "example") != 0 || strcmp(extname, "e4") != 0)
goto ok;
clicon_debug(1, "%s Enabled extension:%s:%s", __FUNCTION__, modname, extname);
if ((yc = ys_prune(ys, 0)) == NULL)
if ((yc = yang_find(ys, 0, NULL)) == NULL)
goto ok;
if ((yn = ys_dup(yc)) == NULL)
goto done;
if (yn_insert(yang_parent_get(ys), yc) < 0)
if (yn_insert(yang_parent_get(ys), yn) < 0)
goto done;
ok:
retval = 0;