summaryrefslogtreecommitdiffstats
path: root/lib/northbound_cli.h
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2018-11-26 18:30:14 +0100
committerRenato Westphal <renato@opensourcerouting.org>2018-11-26 18:57:23 +0100
commita6233bfcb3b0678d24221e77cabea5c3ff859eda (patch)
treeb573f9054dd01c848f21c52d4bbd90a7606d9e9f /lib/northbound_cli.h
parentripd: fix display of the "distance" command (diff)
downloadfrr-a6233bfcb3b0678d24221e77cabea5c3ff859eda.tar.xz
frr-a6233bfcb3b0678d24221e77cabea5c3ff859eda.zip
lib, ripd: rework API for converted CLI commands
When editing the candidate configuration, the northbound must ensure that either all changes made by a command are accepted or none are. This is done to prevent inconsistent states where only parts of a command are applied in the event any error happens. The previous API for converted commands, the nb_cli_cfg_change() function, required callers to pass an array containing all changes that needed to be applied in the candidate configuration. The problem with this API is that it was very inconvenient for complex commands, which change different configuration options depending on several factors. This required users to manipulate the array of configuration changes using low-level primitives, making it complicated to implement some commands. To solve this problem, introduce a new API based on the two following functions: - nb_cli_enqueue_change() - nb_cli_apply_changes() The first function is used to enqueue configuration changes, one at time. Then the nb_cli_apply_changes() function is used to apply all the enqueued configuration changes. To implement this, a static-sized array was allocated in the "vty" structure, along with a counter of enqueued changes. This eliminates the need to declare an array of configuration changes in every converted CLI command, simplifying things quite considerably. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/northbound_cli.h')
-rw-r--r--lib/northbound_cli.h94
1 files changed, 70 insertions, 24 deletions
diff --git a/lib/northbound_cli.h b/lib/northbound_cli.h
index 7f4a64c01..febcbd86f 100644
--- a/lib/northbound_cli.h
+++ b/lib/northbound_cli.h
@@ -22,27 +22,6 @@
#include "northbound.h"
-struct cli_config_change {
- /*
- * XPath (absolute or relative) of the configuration option being
- * edited.
- */
- char xpath[XPATH_MAXLEN];
-
- /*
- * Operation to apply (either NB_OP_CREATE, NB_OP_MODIFY or
- * NB_OP_DELETE).
- */
- enum nb_operation operation;
-
- /*
- * New value of the configuration option. Should be NULL for typeless
- * YANG data (e.g. presence-containers). For convenience, NULL can also
- * be used to restore a leaf to its default value.
- */
- const char *value;
-};
-
/* Possible formats in which a configuration can be displayed. */
enum nb_cfg_format {
NB_CFG_FMT_CMDS = 0,
@@ -52,13 +31,80 @@ enum nb_cfg_format {
extern struct nb_config *vty_shared_candidate_config;
-/* Prototypes. */
-extern int nb_cli_cfg_change(struct vty *vty, char *xpath_list,
- struct cli_config_change changes[], size_t size);
+/*
+ * Enqueue change to be applied in the candidate configuration.
+ *
+ * vty
+ * The vty context.
+ *
+ * xpath
+ * XPath (absolute or relative) of the configuration option being edited.
+ *
+ * operation
+ * Operation to apply (either NB_OP_CREATE, NB_OP_MODIFY or NB_OP_DELETE).
+ *
+ * value
+ * New value of the configuration option. Should be NULL for typeless YANG
+ * data (e.g. presence-containers). For convenience, NULL can also be used
+ * to restore a leaf to its default value.
+ */
+extern void nb_cli_enqueue_change(struct vty *vty, const char *xpath,
+ enum nb_operation operation,
+ const char *value);
+
+/*
+ * Apply enqueued changes to the candidate configuration.
+ *
+ * vty
+ * The vty context.
+ *
+ * xpath_base_fmt
+ * Prepend the given XPath (absolute or relative) to all enqueued
+ * configuration changes.
+ *
+ * Returns:
+ * CMD_SUCCESS on success, CMD_WARNING_CONFIG_FAILED otherwise.
+ */
+extern int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt,
+ ...);
+
+/*
+ * Execute a YANG RPC or Action.
+ *
+ * xpath
+ * XPath of the YANG RPC or Action node.
+ *
+ * input
+ * List of 'yang_data' structures containing the RPC input parameters. It
+ * can be set to NULL when there are no input parameters.
+ *
+ * output
+ * List of 'yang_data' structures used to retrieve the RPC output parameters.
+ * It can be set to NULL when it's known that the given YANG RPC or Action
+ * doesn't have any output parameters.
+ *
+ * Returns:
+ * CMD_SUCCESS on success, CMD_WARNING otherwise.
+ */
extern int nb_cli_rpc(const char *xpath, struct list *input,
struct list *output);
+
+/*
+ * Show CLI commands associated to the given YANG data node.
+ *
+ * vty
+ * The vty terminal to dump the configuration to.
+ *
+ * dnode
+ * libyang data node that should be shown in the form of CLI commands.
+ *
+ * show_defaults
+ * Specify whether to display default configuration values or not.
+ */
extern void nb_cli_show_dnode_cmds(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
+
+/* Prototypes of internal functions. */
extern void nb_cli_install_default(int node);
extern void nb_cli_init(void);
extern void nb_cli_terminate(void);