* CLIspec functions have added namespace parameter:
* `cli_show_config <db> <format> <xpath>` --> `cli_show_config <db> <format> <xpath> <namespace>`
* `cli_copy_config <db> <xpath> ...` --> `cli_copy_config <db> <xpath> <namespace> ...`
* Xpath API
* `xpath_first(x, format, ...)` --> `xpath_first(x, nsc, format, ...)`
* `xpath_vec(x, format, vec, veclen, ...)` --> `xpath_vec(x, nsc, format, vec, veclen, ...)`
* `xpath_vec_flag(x, format, flags, vec, veclen, ...)` --> `xpath_vec_flag(x, format, flags, vec, veclen, ...)`
* `xpath_vec_bool(x, format, ...)` --> `xpath_vec_bool(x, nsc, format, ...)`
* `xpath_vec_ctx(x, xpath, xp)` --> `xpath_vec_ctx(x, nsc, xpath, xp)`
* xmldb_get0 has an added `nsc` parameter:
* `xmldb_get0(h, db, xpath, copy, xret, msd)` --> `xmldb_get0(h, db, nsc, xpath, copy, xret, msd)`
* The plugin statedata callback (ca_statedata) has been extended with an nsc parameter:
* `int example_statedata(clicon_handle h, cvec *nsc, char *xpath, cxobj *xstate);`
* rpc get and get-config api function has an added namespace argument:
* `clicon_rpc_get_config(clicon_handle h, char *db, char *xpath, char *namespace, cxobj **xt);`
* `int clicon_rpc_get(clicon_handle h, char *xpath, char *namespace, cxobj **xt);`
|
||
|---|---|---|
| .. | ||
| clixon-hello@2019-04-17.yang | ||
| hello.xml | ||
| hello_cli.cli | ||
| Makefile.in | ||
| README.md | ||
Clixon hello world example
Content
This directory contains a Clixon example which includes a simple example. It contains the following files:
hello.xmlThe configuration file. See yang/clixon-config@.yang for the documentation of all available fields.clixon-hello@2019-04-17.yangThe yang spec of the example.hello_cli.cliCLIgen specification.Makefile.inExample makefile where plugins are built and installedREADME.mdThis file
Compile and run
Before you start,
- Make group setup
make && sudo make install
Start backend in the background:
sudo clixon_backend
Start cli:
clixon_cli
Using the CLI
The example CLI allows you to modify and view the data model using set, delete and show via generated code.
The following example shows how to add a very simple configuration hello world using the generated CLI. The config is added to the candidate database, shown, committed to running, and then deleted.
olof@vandal> clixon_cli
cli> set <?>
hello
cli> set hello world
cli> show configuration
hello world;
cli> commit
cli> delete <?>
all Delete whole candidate configuration
hello
cli> delete hello
cli> show configuration
cli> commit
cli> quit
olof@vandal>
Netconf
Clixon also provides a Netconf interface. The following example starts a netconf client form the shell, adds the hello world config, commits it, and shows it:
olof@vandal> clixon_netconf -q
<rpc><edit-config><target><candidate/></target><config><hello xmlns="urn:example:hello"><world/></hello></config></edit-config></rpc>]]>]]>
<rpc-reply><ok/></rpc-reply>]]>]]>
<rpc><commit/></rpc>]]>]]>
<rpc-reply><ok/></rpc-reply>]]>]]>
<rpc><get-config><source><running/></source></get-config></rpc>]]>]]>
<rpc-reply><data><hello xmlns="urn:example:hello"><world/></hello></data></rpc-reply>]]>]]>
olof@vandal>
Restconf
Clixon also provides a Restconf interface. A reverse proxy needs to be configured. There are instructions how to setup Nginx for Clixon.
Start restconf daemon
sudo su -c "/www-data/clixon_restconf" -s /bin/sh www-data &
Start sending restconf commands (using Curl):
olof@vandal> curl -X POST http://localhost/restconf/data -d '{"clixon-hello:hello":{"world":null}}'
olof@vandal> curl -X GET http://localhost/restconf/data
{
"data": {
"clixon-hello:hello": {
"world": null
}
}
}
Next steps
The hello world example only has a Yang spec and a template CLI spec. For more advanced applications, customized backend, cli, netconf and restconf code callbacks becomes necessary.
Further, you may want to add upgrade, RPC:s, state data, notification streams, authentication and authorization. The main example contains examples for such capabilities.
There are also container examples and lots more.