Library functions in clixon_cli_api.h (e.g cli_commit) is rewritten in new

for (eg cli_commitv). See clixon_cli_api.h for new names.
Use restconf format for internal xmldb keys. Eg /a/b=3,4
Changed example to use multiple cli callbacks
This commit is contained in:
Olof hagsand 2017-01-31 22:36:14 +01:00
parent c9f1ece53e
commit 7f0b9909b3
30 changed files with 1444 additions and 1054 deletions

View file

@ -5,7 +5,12 @@ Clixon yang routing example
------------------
cd example
make && sudo make install
# Start backend
clixon_backend -f /usr/local/etc/routing.conf -I
# Edit cli
clixon_cli -f /usr/local/etc/routing.conf
# Send netconf command
clixon_netconf -f /usr/local/etc/routing.conf
1. Setting data example using netconf
-------------------------------------

View file

@ -29,3 +29,8 @@ CLICON_XMLDB_ADDR 127.0.0.1
# xmldb tcp port (if CLICON_XMLDB_RPC)
CLICON_XMLDB_PORT 7878
# Set if you want to use old obsolete cligen callback variable syntax
# Migration: Set to 0 and change all user-defined cli callbacks in your cli spec files
# E.g cmd, callback("single arg"); -> cmd, callback("two" "args");
# And change predefined callbacks, eg cli_commit -> cli_commitv in all cli files
CLICON_CLIGEN_CALLBACK_SINGLE_ARG 0

View file

@ -68,7 +68,7 @@ plugin_init(clicon_handle h)
/*! Example cli function */
int
mycallback(clicon_handle h, cvec *cvv, cg_var *arg)
mycallback(clicon_handle h, cvec *cvv, cvec *argv)
{
int retval = -1;
cxobj *xt = NULL;
@ -77,12 +77,11 @@ mycallback(clicon_handle h, cvec *cvv, cg_var *arg)
/* Access cligen callback variables */
myvar = cvec_find(cvv, "var"); /* get a cligen variable from vector */
cli_output(stderr, "%s: %d\n", __FUNCTION__, cv_int32_get(myvar)); /* get int value */
cli_output(stderr, "arg = %s\n", cv_string_get(arg)); /* get string value */
cli_output(stderr, "arg = %s\n", cv_string_get(cvec_i(argv,0))); /* get string value */
/* Show eth0 interfaces config using XPATH */
if (xmldb_get(h, "candidate",
"/interfaces/interface[name=eth0]",
0,
&xt, NULL, NULL) < 0)
goto done;
xml_print(stdout, xt);

View file

@ -4,43 +4,41 @@ CLICON_PROMPT="%U@%H> ";
CLICON_PLUGIN="routing_cli";
# Note, when switching to PT, change datamodel to only @datamodel
#set @datamodel:ietf-routing, cli_merge();
#set @datamodel:ietf-ipv4-unicast-routing, cli_merge();
set @datamodel:ietf-ip, cli_merge();
set @datamodel:ietf-ip, cli_mergev();
#delete("Delete a configuration item") @datamodel:ietf-ipv4-unicast-routing, cli_del();
delete("Delete a configuration item") @datamodel:ietf-ip, cli_del();
delete("Delete a configuration item") @datamodel:ietf-ip, cli_delv();
validate("Validate changes"), cli_validate();
commit("Commit the changes"), cli_commit((int)0); # snapshot
quit("Quit Hello"), cli_quit();
delete("Delete a configuration item") all("Delete whole candidate configuration"), delete_all("candidate");
validate("Validate changes"), cli_validatev();
commit("Commit the changes"), cli_commitv((int32)0); # snapshot
quit("Quit Hello"), cli_quitv();
delete("Delete a configuration item") all("Delete whole candidate configuration"), delete_allv("candidate");
no("Negate or remove") debug("Debugging parts of the system"), cli_debug((int)0);
debug("Debugging parts of the system"), cli_debug((int)1);{
level("Set debug level: 1..n") <level:int32>("Set debug level (0..n)"), cli_debug();
no("Negate or remove") debug("Debugging parts of the system"), cli_debug_cliv((int32)0);
debug("Debugging parts of the system"), cli_debug_cliv((int32)1);{
level("Set debug level: 1..n") <level:int32>("Set debug level (0..n)"), cli_debug_cliv();
}
discard("Discard edits (rollback 0)"), discard_changes();
discard("Discard edits (rollback 0)"), discard_changesv();
show("Show a particular state of the system"){
xpath("Show configuration") <xpath:string>("XPATH expression"), show_conf_xpath("candidate");
compare("Compare candidate and running databases"), compare_dbs((int32)0);{
xml("Show comparison in xml"), compare_dbs((int32)0);
text("Show comparison in text"), compare_dbs((int32)1);
xpath("Show configuration") <xpath:string>("XPATH expression"), show_confv_xpath("candidate");
compare("Compare candidate and running databases"), compare_dbsv((int32)0);{
xml("Show comparison in xml"), compare_dbsv((int32)0);
text("Show comparison in text"), compare_dbsv((int32)1);
}
configuration("Show configuration"), show_conf_as_text("candidate /");{
xml("Show configuration as XML"), show_conf_as_xml("candidate /");
netconf("Show configuration as netconf edit-config operation"), show_conf_as_netconf("candidate /");
text("Show configuration as text"), show_conf_as_text("candidate /");
cli("Show configuration as cli commands"), show_conf_as_cli("candidate /");
json("Show configuration as cli commands"), show_conf_as_json("candidate /");
configuration("Show configuration"), show_confv_as_text("candidate","/");{
xml("Show configuration as XML"), show_confv_as_xml("candidate","/");
netconf("Show configuration as netconf edit-config operation"), show_confv_as_netconf("candidate","/");
text("Show configuration as text"), show_confv_as_text("candidate","/");
cli("Show configuration as cli commands"), show_confv_as_cli("candidate","/");
json("Show configuration as cli commands"), show_confv_as_json("candidate","/");
}
}
save("Save candidate configuration to XML file") <filename:string>("Filename (local filename)"), save_config_file("candidate filename");
load("Load configuration from XML file") <filename:string>("Filename (local filename)"),load_config_file("filename replace");{
replace("Replace candidate with file contents"), load_config_file("filename replace");
merge("Merge file with existent candidate"), load_config_file("filename merge");
save("Save candidate configuration to XML file") <filename:string>("Filename (local filename)"), save_config_filev("candidate","filename");
load("Load configuration from XML file") <filename:string>("Filename (local filename)"),load_config_filev("filename","replace");{
replace("Replace candidate with file contents"), load_config_filev("filename","replace");
merge("Merge file with existent candidate"), load_config_filev("filename","merge");
}
example("This is a comment") <var:int32>("Just a random number"), mycallback("myarg");
example("This is a comment") <var:int32>("Just a random number"), mycallback("myarg");