diff options
| author | Renato Westphal <renato@opensourcerouting.org> | 2017-12-07 17:31:48 -0200 |
|---|---|---|
| committer | Renato Westphal <renato@opensourcerouting.org> | 2018-10-27 16:16:12 -0200 |
| commit | 1c2facd12df7bc27758d7ea674b1e57e401fc234 (patch) | |
| tree | b82aeb06586c2c7b380420ddd484964af915aee1 /lib/command.c | |
| parent | 75082dafb5a929b99d89c8f55e6b2da3f4d90100 (diff) | |
lib: introduce new northbound API
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/command.c')
| -rw-r--r-- | lib/command.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/lib/command.c b/lib/command.c index 127e1a0a0a..bd000c3746 100644 --- a/lib/command.c +++ b/lib/command.c @@ -46,6 +46,7 @@ #include "jhash.h" #include "hook.h" #include "lib_errors.h" +#include "northbound_cli.h" DEFINE_MTYPE(LIB, HOST, "Host config") DEFINE_MTYPE(LIB, COMPLETION, "Completion item") @@ -81,6 +82,7 @@ const char *node_names[] = { "config", // CONFIG_NODE, "debug", // DEBUG_NODE, "vrf debug", // VRF_DEBUG_NODE, + "northbound debug", // NORTHBOUND_DEBUG_NODE, "vnc debug", // DEBUG_VNC_NODE, "aaa", // AAA_NODE, "keychain", // KEYCHAIN_NODE, @@ -718,11 +720,14 @@ vector cmd_describe_command(vector vline, struct vty *vty, int *status) if (cmd_try_do_shortcut(vty->node, vector_slot(vline, 0))) { enum node_type onode; + int orig_xpath_index; vector shifted_vline; unsigned int index; onode = vty->node; + orig_xpath_index = vty->xpath_index; vty->node = ENABLE_NODE; + vty->xpath_index = 0; /* We can try it on enable node, cos' the vty is authenticated */ @@ -737,6 +742,7 @@ vector cmd_describe_command(vector vline, struct vty *vty, int *status) vector_free(shifted_vline); vty->node = onode; + vty->xpath_index = orig_xpath_index; return ret; } @@ -1075,14 +1081,17 @@ int cmd_execute_command(vector vline, struct vty *vty, { int ret, saved_ret = 0; enum node_type onode, try_node; + int orig_xpath_index; onode = try_node = vty->node; + orig_xpath_index = vty->xpath_index; if (cmd_try_do_shortcut(vty->node, vector_slot(vline, 0))) { vector shifted_vline; unsigned int index; vty->node = ENABLE_NODE; + vty->xpath_index = 0; /* We can try it on enable node, cos' the vty is authenticated */ @@ -1097,6 +1106,7 @@ int cmd_execute_command(vector vline, struct vty *vty, vector_free(shifted_vline); vty->node = onode; + vty->xpath_index = orig_xpath_index; return ret; } @@ -1113,6 +1123,8 @@ int cmd_execute_command(vector vline, struct vty *vty, while (vty->node > CONFIG_NODE) { try_node = node_parent(try_node); vty->node = try_node; + if (vty->xpath_index > 0) + vty->xpath_index--; ret = cmd_execute_command_real(vline, FILTER_RELAXED, vty, cmd); if (ret == CMD_SUCCESS || ret == CMD_WARNING @@ -1122,6 +1134,7 @@ int cmd_execute_command(vector vline, struct vty *vty, } /* no command succeeded, reset the vty to the original node */ vty->node = onode; + vty->xpath_index = orig_xpath_index; } /* return command status for original node */ @@ -1285,7 +1298,6 @@ int command_config_read_one_line(struct vty *vty, uint32_t line_num, int use_daemon) { vector vline; - int saved_node; int ret; vline = cmd_make_strvec(vty->buf); @@ -1303,14 +1315,16 @@ int command_config_read_one_line(struct vty *vty, && ret != CMD_SUCCESS && ret != CMD_WARNING && ret != CMD_NOT_MY_INSTANCE && ret != CMD_WARNING_CONFIG_FAILED && vty->node != CONFIG_NODE) { - - saved_node = vty->node; + int saved_node = vty->node; + int saved_xpath_index = vty->xpath_index; while (!(use_daemon && ret == CMD_SUCCESS_DAEMON) && !(!use_daemon && ret == CMD_ERR_NOTHING_TODO) && ret != CMD_SUCCESS && ret != CMD_WARNING && vty->node > CONFIG_NODE) { vty->node = node_parent(vty->node); + if (vty->xpath_index > 0) + vty->xpath_index--; ret = cmd_execute_command_strict(vline, vty, cmd); } @@ -1320,6 +1334,7 @@ int command_config_read_one_line(struct vty *vty, && !(!use_daemon && ret == CMD_ERR_NOTHING_TODO) && ret != CMD_SUCCESS && ret != CMD_WARNING) { vty->node = saved_node; + vty->xpath_index = saved_xpath_index; } } @@ -1377,6 +1392,12 @@ DEFUN (config_terminal, vty_out(vty, "VTY configuration is locked by other VTY\n"); return CMD_WARNING_CONFIG_FAILED; } + + vty->private_config = false; + vty->candidate_config = vty_shared_candidate_config; + if (frr_get_cli_mode() == FRR_CLI_TRANSACTIONAL) + vty->candidate_config_base = nb_config_dup(running_config); + return CMD_SUCCESS; } @@ -1500,6 +1521,9 @@ void cmd_exit(struct vty *vty) default: break; } + + if (vty->xpath_index > 0) + vty->xpath_index--; } /* ALIAS_FIXME */ @@ -1576,6 +1600,9 @@ DEFUN (config_end, default: break; } + + vty->xpath_index = 0; + return CMD_SUCCESS; } @@ -2785,6 +2812,8 @@ void install_default(enum node_type node) install_element(node, &show_running_config_cmd); install_element(node, &autocomplete_cmd); + + nb_cli_install_default(node); } /* Initialize command interface. Install basic nodes and commands. |
