diff --git a/src/mech/src/core/Makefile.am b/src/mech/src/core/Makefile.am index 034b7599..080a0b71 100644 --- a/src/mech/src/core/Makefile.am +++ b/src/mech/src/core/Makefile.am @@ -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 diff --git a/src/mech/src/core/cli.cli b/src/mech/src/core/cli.cli deleted file mode 100644 index 3aafb7ba..00000000 --- a/src/mech/src/core/cli.cli +++ /dev/null @@ -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(); -} diff --git a/src/mech/src/core/core-backend.c b/src/mech/src/core/core-backend.c new file mode 100644 index 00000000..25770620 --- /dev/null +++ b/src/mech/src/core/core-backend.c @@ -0,0 +1,25 @@ +#include +#include +#include + +#include + +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; +} diff --git a/src/mech/src/core/cli.c b/src/mech/src/core/core-cli.c similarity index 100% rename from src/mech/src/core/cli.c rename to src/mech/src/core/core-cli.c diff --git a/src/mech/src/core/core-cli.cli b/src/mech/src/core/core-cli.cli new file mode 100644 index 00000000..110f54fe --- /dev/null +++ b/src/mech/src/core/core-cli.cli @@ -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") ("The 'persist' value of the persistent confirmed-commit")], cli_commit(); { + ("Cancel an ongoing confirmed-commit"), cli_commit(); + ("Require a confirming commit") { + [persist("Make this confirmed-commit persistent") ("The value that must be provided as 'persist-id' in the confirming-commit or cancel-commit")] + [("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 of interface to copy from")) to("Copy to interface") ("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"); + } + } + } +} diff --git a/src/mech/yang/infix.yang b/src/mech/yang/infix.yang index 31bc8a2c..5d9bb3a0 100644 --- a/src/mech/yang/infix.yang +++ b/src/mech/yang/infix.yang @@ -15,10 +15,11 @@ module infix { import ietf-datastores { prefix ds; } - import clixon-autocli{ +*/ + import clixon-autocli { prefix autocli; } -*/ + description "Base model ";