diff options
| author | Russ White <russ@riw.us> | 2021-01-19 07:17:03 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-19 07:17:03 -0500 |
| commit | c0b6ef23f74ef05f6a7550b78590e31605e7f90f (patch) | |
| tree | 42c8bfea591bb848a0ca4e6ff41116bb62277d34 /lib/command.c | |
| parent | 4168228f25e51d947a93fc09fe1d5866e3523a25 (diff) | |
| parent | 56df11cb85f05b035bb3234a14d9062a27b1f61d (diff) | |
Merge pull request #7639 from qlyoung/frr-lua
Scripting
Diffstat (limited to 'lib/command.c')
| -rw-r--r-- | lib/command.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/command.c b/lib/command.c index f40fe6e2c5..b9d607a101 100644 --- a/lib/command.c +++ b/lib/command.c @@ -49,6 +49,8 @@ #include "northbound_cli.h" #include "network.h" +#include "frrscript.h" + DEFINE_MTYPE_STATIC(LIB, HOST, "Host config") DEFINE_MTYPE(LIB, COMPLETION, "Completion item") @@ -2303,6 +2305,30 @@ done: return CMD_SUCCESS; } +#if defined(DEV_BUILD) && defined(HAVE_SCRIPTING) +DEFUN(script, + script_cmd, + "script SCRIPT", + "Test command - execute a script\n" + "Script name (same as filename in /etc/frr/scripts/\n") +{ + struct prefix p; + str2prefix("1.2.3.4/24", &p); + + struct frrscript *fs = frrscript_load(argv[1]->arg, NULL); + + if (fs == NULL) { + vty_out(vty, "Script '/etc/frr/scripts/%s.lua' not found\n", + argv[1]->arg); + } else { + int ret = frrscript_call(fs, NULL); + vty_out(vty, "Script result: %d\n", ret); + } + + return CMD_SUCCESS; +} +#endif + /* Set config filename. Called from vty.c */ void host_config_set(const char *filename) { @@ -2397,6 +2423,10 @@ void cmd_init(int terminal) install_element(VIEW_NODE, &echo_cmd); install_element(VIEW_NODE, &autocomplete_cmd); install_element(VIEW_NODE, &find_cmd); +#if defined(DEV_BUILD) && defined(HAVE_SCRIPTING) + install_element(VIEW_NODE, &script_cmd); +#endif + install_element(ENABLE_NODE, &config_end_cmd); install_element(ENABLE_NODE, &config_disable_cmd); |
