mech: Import basic autocli support from clixon's main example

This allows use the autogenerated CLI to modify the database.
This commit is contained in:
Tobias Waldekranz
2023-02-10 16:11:34 +01:00
parent e56348a916
commit 3235f00cd1
6 changed files with 113 additions and 16 deletions
+11 -5
View File
@@ -1,8 +1,14 @@
include $(top_srcdir)/common.am
cli_LTLIBRARIES += cli.la
clispec_DATA += cli.cli
clispec_DATA += core-cli.cli
cli_la_LDFLAGS = $(cli_ldflags)
cli_la_LIBADD = $(cli_libadd)
cli_la_SOURCES = cli.c
cli_LTLIBRARIES += core-cli.la
core_cli_la_LDFLAGS = $(cli_ldflags)
core_cli_la_LIBADD = $(cli_libadd)
core_cli_la_SOURCES = core-cli.c
backend_LTLIBRARIES += core-backend.la
core_backend_la_CFLAGS = $(backend_cflags)
core_backend_la_LDFLAGS = $(backend_ldflags)
core_backend_la_LIBADD = $(backend_libadd)
core_backend_la_SOURCES = core-backend.c
-9
View File
@@ -1,9 +0,0 @@
CLICON_MODE="exec";
CLICON_PROMPT="%U@%H> ";
CLICON_PLUGIN="cli";
exit("Exit"), cli_quit();
show("Show various system state and configuration") {
system-information("System information"), cli_sysinfo();
}
+25
View File
@@ -0,0 +1,25 @@
#include <cligen/cligen.h>
#include <clixon/clixon.h>
#include <clixon/clixon_backend.h>
#include <sys/syslog.h>
int core_commit_done(clicon_handle h, transaction_data td)
{
if (transaction_src(td) && system("initctl reload"))
clicon_log(LOG_CRIT, "Failed to reload services");
return 0;
}
static clixon_plugin_api core_api = {
.ca_name = "core",
.ca_init = clixon_plugin_init,
.ca_trans_commit_done = core_commit_done,
};
clixon_plugin_api *clixon_plugin_init(clicon_handle h)
{
return &core_api;
}
+74
View File
@@ -0,0 +1,74 @@
CLICON_MODE="exec";
CLICON_PROMPT="%U@%H:%w> ";
CLICON_PLUGIN="core-cli";
exit("Exit"), cli_quit();
# Autocli syntax tree operations, from clixon's "main" example
edit @datamodelmode, cli_auto_edit("basemodel");
up, cli_auto_up("basemodel");
top, cli_auto_top("basemodel");
set @datamodel, cli_auto_set();
merge @datamodel, cli_auto_merge();
create @datamodel, cli_auto_create();
delete("Delete a configuration item") {
@datamodel, cli_auto_del();
all("Delete whole candidate configuration"), delete_all("candidate");
}
validate("Validate changes"), cli_validate();
commit("Commit the changes"), cli_commit(); {
[persist-id("Specify the 'persist' value of a previous confirmed-commit") <persist-id-val:string show:"string">("The 'persist' value of the persistent confirmed-commit")], cli_commit(); {
<cancel:string keyword:cancel>("Cancel an ongoing confirmed-commit"), cli_commit();
<confirmed:string keyword:confirmed>("Require a confirming commit") {
[persist("Make this confirmed-commit persistent") <persist-val:string show:"string">("The value that must be provided as 'persist-id' in the confirming-commit or cancel-commit")]
[<timeout:uint32 range[1:4294967295] show:"1..4294967295">("The rollback timeout in seconds")], cli_commit();
}
}
}
copy("Copy and create a new object") {
running("Copy from running db") startup("Copy to startup config"), db_copy("running", "startup");
interface("Copy interface"){
(<name:string>|<name:string expand_dbvar("candidate","/ietf-interfaces:interfaces/interface=%s/name")>("name of interface to copy from")) to("Copy to interface") <toname:string>("Name of interface to copy to"), cli_copy_config("candidate","//interface[%s='%s']","urn:ietf:params:xml:ns:yang:ietf-interfaces","name","name","toname");
}
}
show("Show various system state and configuration") {
system-information("System information"), cli_sysinfo();
auto("Show expand x") {
xml @datamodelshow, cli_show_auto("candidate", "xml", true, false, "report-all");
text @datamodelshow, cli_show_auto("candidate", "text", true, false, "report-all");
json @datamodelshow, cli_show_auto("candidate", "json", true, false, "report-all");
netconf @datamodelshow, cli_show_auto("candidate", "netconf", true, false, "report-all");
cli @datamodelshow, cli_show_auto("candidate", "cli", true, false, "report-all", "set ");
}
configuration("Show configuration"), cli_show_auto_mode("candidate", "text", true, false); {
xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", true, false); {
default("With-default mode") {
report-all, cli_show_auto_mode("candidate", "xml", true, false, "report-all");
trim, cli_show_auto_mode("candidate", "xml", true, false, "trim");
explicit, cli_show_auto_mode("candidate", "xml", true, false, "explicit");
report-all-tagged, cli_show_auto_mode("candidate", "xml", true, false, "report-all-tagged");
report-all-tagged-default, cli_show_auto_mode("candidate", "xml", true, false, "report-all-tagged-default");
report-all-tagged-strip, cli_show_auto_mode("candidate", "xml", true, false, "report-all-tagged-strip");
}
}
cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", true, false, "explicit", "set ");
netconf("Show configuration as netconf edit-config operation"), cli_show_auto_mode("candidate", "netconf", true, false);
text("Show configuration as text"), cli_show_auto_mode("candidate", "text", true, false);
json("Show configuration as JSON"), cli_show_auto_mode("candidate", "json", true, false);
}
state("Show configuration and state"), cli_show_auto_mode("running", "text", true, true); {
xml("Show configuration and state as XML"), cli_show_auto_mode("running", "xml", true, true); {
default("With-default mode") {
report-all, cli_show_auto_mode("running", "xml", true, true, "report-all");
trim, cli_show_auto_mode("running", "xml", true, true, "trim");
explicit, cli_show_auto_mode("running", "xml", true, true, "explicit");
report-all-tagged, cli_show_auto_mode("running", "xml", true, true, "report-all-tagged");
report-all-tagged-default, cli_show_auto_mode("running", "xml", true, true, "report-all-tagged-default");
report-all-tagged-strip, cli_show_auto_mode("running", "xml", true, true, "report-all-tagged-strip");
}
}
}
}
+3 -2
View File
@@ -15,10 +15,11 @@ module infix {
import ietf-datastores {
prefix ds;
}
import clixon-autocli{
*/
import clixon-autocli {
prefix autocli;
}
*/
description
"Base model
";