summaryrefslogtreecommitdiffstats
path: root/mgmtd/mgmt_vty.c
diff options
context:
space:
mode:
Diffstat (limited to 'mgmtd/mgmt_vty.c')
-rw-r--r--mgmtd/mgmt_vty.c196
1 files changed, 175 insertions, 21 deletions
diff --git a/mgmtd/mgmt_vty.c b/mgmtd/mgmt_vty.c
index b49bf80..bbc1077 100644
--- a/mgmtd/mgmt_vty.c
+++ b/mgmtd/mgmt_vty.c
@@ -8,10 +8,13 @@
#include <zebra.h>
+#include "affinitymap.h"
#include "command.h"
+#include "filter.h"
#include "json.h"
#include "network.h"
#include "northbound_cli.h"
+#include "routemap.h"
#include "mgmtd/mgmt.h"
#include "mgmtd/mgmt_be_adapter.h"
@@ -20,6 +23,10 @@
#include "mgmtd/mgmt_history.h"
#include "mgmtd/mgmt_vty_clippy.c"
+#include "ripd/rip_nb.h"
+#include "ripngd/ripng_nb.h"
+#include "staticd/static_vty.h"
+#include "zebra/zebra_cli.h"
extern struct frr_daemon_info *mgmt_daemon_info;
@@ -144,6 +151,23 @@ DEFPY(mgmt_commit,
return CMD_SUCCESS;
}
+DEFPY(mgmt_create_config_data, mgmt_create_config_data_cmd,
+ "mgmt create-config WORD$path VALUE",
+ MGMTD_STR
+ "Create configuration data\n"
+ "XPath expression specifying the YANG data path\n"
+ "Value of the data to create\n")
+{
+ strlcpy(vty->cfg_changes[0].xpath, path,
+ sizeof(vty->cfg_changes[0].xpath));
+ vty->cfg_changes[0].value = value;
+ vty->cfg_changes[0].operation = NB_OP_CREATE_EXCL;
+ vty->num_cfg_changes = 1;
+
+ vty_mgmt_send_config_data(vty, NULL, false);
+ return CMD_SUCCESS;
+}
+
DEFPY(mgmt_set_config_data, mgmt_set_config_data_cmd,
"mgmt set-config WORD$path VALUE",
MGMTD_STR
@@ -154,10 +178,10 @@ DEFPY(mgmt_set_config_data, mgmt_set_config_data_cmd,
strlcpy(vty->cfg_changes[0].xpath, path,
sizeof(vty->cfg_changes[0].xpath));
vty->cfg_changes[0].value = value;
- vty->cfg_changes[0].operation = NB_OP_CREATE;
+ vty->cfg_changes[0].operation = NB_OP_MODIFY;
vty->num_cfg_changes = 1;
- vty_mgmt_send_config_data(vty, false);
+ vty_mgmt_send_config_data(vty, NULL, false);
return CMD_SUCCESS;
}
@@ -171,10 +195,45 @@ DEFPY(mgmt_delete_config_data, mgmt_delete_config_data_cmd,
strlcpy(vty->cfg_changes[0].xpath, path,
sizeof(vty->cfg_changes[0].xpath));
vty->cfg_changes[0].value = NULL;
+ vty->cfg_changes[0].operation = NB_OP_DELETE;
+ vty->num_cfg_changes = 1;
+
+ vty_mgmt_send_config_data(vty, NULL, false);
+ return CMD_SUCCESS;
+}
+
+DEFPY(mgmt_remove_config_data, mgmt_remove_config_data_cmd,
+ "mgmt remove-config WORD$path",
+ MGMTD_STR
+ "Remove configuration data\n"
+ "XPath expression specifying the YANG data path\n")
+{
+
+ strlcpy(vty->cfg_changes[0].xpath, path,
+ sizeof(vty->cfg_changes[0].xpath));
+ vty->cfg_changes[0].value = NULL;
vty->cfg_changes[0].operation = NB_OP_DESTROY;
vty->num_cfg_changes = 1;
- vty_mgmt_send_config_data(vty, false);
+ vty_mgmt_send_config_data(vty, NULL, false);
+ return CMD_SUCCESS;
+}
+
+DEFPY(mgmt_replace_config_data, mgmt_replace_config_data_cmd,
+ "mgmt replace-config WORD$path VALUE",
+ MGMTD_STR
+ "Replace configuration data\n"
+ "XPath expression specifying the YANG data path\n"
+ "Value of the data to set\n")
+{
+
+ strlcpy(vty->cfg_changes[0].xpath, path,
+ sizeof(vty->cfg_changes[0].xpath));
+ vty->cfg_changes[0].value = value;
+ vty->cfg_changes[0].operation = NB_OP_REPLACE;
+ vty->num_cfg_changes = 1;
+
+ vty_mgmt_send_config_data(vty, NULL, false);
return CMD_SUCCESS;
}
@@ -199,22 +258,69 @@ DEFPY(show_mgmt_get_config, show_mgmt_get_config_cmd,
}
DEFPY(show_mgmt_get_data, show_mgmt_get_data_cmd,
- "show mgmt get-data [candidate|operational|running]$dsname WORD$path",
- SHOW_STR MGMTD_STR
- "Get data from a specific datastore\n"
+ "show mgmt get-data WORD$path [datastore <candidate|running|operational>$ds] [with-config|only-config]$content [exact]$exact [with-defaults <trim|all-tag|all>$wd] [json|xml]$fmt",
+ SHOW_STR
+ MGMTD_STR
+ "Get a data from the operational datastore\n"
+ "XPath expression specifying the YANG data root\n"
+ "Specify datastore to get data from (operational by default)\n"
"Candidate datastore\n"
- "Operational datastore (default)\n"
"Running datastore\n"
- "XPath expression specifying the YANG data path\n")
+ "Operational datastore\n"
+ "Include \"config true\" data\n"
+ "Get only \"config true\" data\n"
+ "Get exact node instead of the whole data tree\n"
+ "Configure 'with-defaults' mode per RFC 6243 (\"explicit\" mode by default)\n"
+ "Use \"trim\" mode\n"
+ "Use \"report-all-tagged\" mode\n"
+ "Use \"report-all\" mode\n"
+ "JSON output format\n"
+ "XML output format\n")
{
- const char *xpath_list[VTY_MAXCFGCHANGES] = {0};
- Mgmtd__DatastoreId datastore = MGMTD_DS_OPERATIONAL;
+ LYD_FORMAT format = (fmt && fmt[0] == 'x') ? LYD_XML : LYD_JSON;
+ int plen = strlen(path);
+ char *xpath = NULL;
+ uint8_t flags = content ? GET_DATA_FLAG_CONFIG : GET_DATA_FLAG_STATE;
+ uint8_t defaults = GET_DATA_DEFAULTS_EXPLICIT;
+ uint8_t datastore = MGMT_MSG_DATASTORE_OPERATIONAL;
+
+ if (content && content[0] == 'w')
+ flags |= GET_DATA_FLAG_STATE;
+
+ if (exact)
+ flags |= GET_DATA_FLAG_EXACT;
+
+ if (wd) {
+ if (wd[0] == 't')
+ defaults = GET_DATA_DEFAULTS_TRIM;
+ else if (wd[3] == '-')
+ defaults = GET_DATA_DEFAULTS_ALL_ADD_TAG;
+ else
+ defaults = GET_DATA_DEFAULTS_ALL;
+ }
- if (dsname)
- datastore = mgmt_ds_name2id(dsname);
+ if (ds) {
+ if (ds[0] == 'c')
+ datastore = MGMT_MSG_DATASTORE_CANDIDATE;
+ else if (ds[0] == 'r')
+ datastore = MGMT_MSG_DATASTORE_RUNNING;
+ }
+
+ /* get rid of extraneous trailing slash-* or single '/' unless root */
+ if (plen > 2 && ((path[plen - 2] == '/' && path[plen - 1] == '*') ||
+ (path[plen - 2] != '/' && path[plen - 1] == '/'))) {
+ plen = path[plen - 1] == '/' ? plen - 1 : plen - 2;
+ xpath = XSTRDUP(MTYPE_TMP, path);
+ xpath[plen] = 0;
+ path = xpath;
+ }
+
+ vty_mgmt_send_get_data_req(vty, datastore, format, flags, defaults,
+ path);
+
+ if (xpath)
+ XFREE(MTYPE_TMP, xpath);
- xpath_list[0] = path;
- vty_mgmt_send_get_req(vty, false, datastore, xpath_list, 1);
return CMD_SUCCESS;
}
@@ -273,7 +379,7 @@ DEFPY(show_mgmt_map_xpath,
"Get YANG Backend Subscription\n"
"XPath expression specifying the YANG data path\n")
{
- mgmt_be_xpath_subscr_info_write(vty, path);
+ mgmt_be_show_xpath_registries(vty, path);
return CMD_SUCCESS;
}
@@ -379,7 +485,7 @@ DEFPY(mgmt_rollback,
int config_write_mgmt_debug(struct vty *vty);
static struct cmd_node debug_node = {
- .name = "debug",
+ .name = "mgmt debug",
.node = DEBUG_NODE,
.prompt = "",
.config_write = config_write_mgmt_debug,
@@ -438,12 +544,18 @@ DEFPY(debug_mgmt, debug_mgmt_cmd,
{
uint32_t mode = DEBUG_NODE2MODE(vty->node);
- if (be)
+ if (be) {
DEBUG_MODE_SET(&mgmt_debug_be, mode, !no);
+ mgmt_be_adapter_toggle_client_debug(
+ DEBUG_MODE_CHECK(&mgmt_debug_be, DEBUG_MODE_ALL));
+ }
if (ds)
DEBUG_MODE_SET(&mgmt_debug_ds, mode, !no);
- if (fe)
+ if (fe) {
DEBUG_MODE_SET(&mgmt_debug_fe, mode, !no);
+ mgmt_fe_adapter_toggle_client_debug(
+ DEBUG_MODE_CHECK(&mgmt_debug_fe, DEBUG_MODE_ALL));
+ }
if (txn)
DEBUG_MODE_SET(&mgmt_debug_txn, mode, !no);
@@ -452,19 +564,57 @@ DEFPY(debug_mgmt, debug_mgmt_cmd,
static void mgmt_config_read_in(struct event *event)
{
- mgmt_vty_read_configs();
+ if (vty_mgmt_fe_enabled())
+ mgmt_vty_read_configs();
+ else {
+ zlog_warn("%s: no connection to front-end server, retry in 1s",
+ __func__);
+ event_add_timer(mm->master, mgmt_config_read_in, NULL, 1,
+ &mgmt_daemon_info->read_in);
+ }
+}
+
+static int mgmtd_config_write(struct vty *vty)
+{
+ struct lyd_node *root;
+
+ LY_LIST_FOR (running_config->dnode, root) {
+ nb_cli_show_dnode_cmds(vty, root, false);
+ }
+
+ return 1;
}
+static struct cmd_node mgmtd_node = {
+ .name = "mgmtd",
+ .node = MGMTD_NODE,
+ .prompt = "",
+ .config_write = mgmtd_config_write,
+};
+
void mgmt_vty_init(void)
{
/*
+ * Library based CLI handlers
+ */
+ filter_cli_init();
+ route_map_cli_init();
+ affinity_map_init();
+
+ /*
* Initialize command handling from VTYSH connection.
* Call command initialization routines defined by
* backend components that are moved to new MGMTD infra
* here one by one.
*/
-#if HAVE_STATICD
- extern void static_vty_init(void);
+ zebra_cli_init();
+#ifdef HAVE_RIPD
+ rip_cli_init();
+#endif
+#ifdef HAVE_RIPNGD
+ ripng_cli_init();
+#endif
+#ifdef HAVE_STATICD
static_vty_init();
#endif
@@ -472,6 +622,7 @@ void mgmt_vty_init(void)
&mgmt_daemon_info->read_in);
install_node(&debug_node);
+ install_node(&mgmtd_node);
install_element(VIEW_NODE, &show_mgmt_be_adapter_cmd);
install_element(VIEW_NODE, &show_mgmt_be_xpath_reg_cmd);
@@ -485,8 +636,11 @@ void mgmt_vty_init(void)
install_element(VIEW_NODE, &show_mgmt_cmt_hist_cmd);
install_element(CONFIG_NODE, &mgmt_commit_cmd);
+ install_element(CONFIG_NODE, &mgmt_create_config_data_cmd);
install_element(CONFIG_NODE, &mgmt_set_config_data_cmd);
install_element(CONFIG_NODE, &mgmt_delete_config_data_cmd);
+ install_element(CONFIG_NODE, &mgmt_remove_config_data_cmd);
+ install_element(CONFIG_NODE, &mgmt_replace_config_data_cmd);
install_element(CONFIG_NODE, &mgmt_load_config_cmd);
install_element(CONFIG_NODE, &mgmt_save_config_cmd);
install_element(CONFIG_NODE, &mgmt_rollback_cmd);