diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index e32509f2..24ed0d3c 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -1320,3 +1320,33 @@ cli_help(clicon_handle h, cvec *vars, cvec *argv) return cligen_help(ch, stdout, pt); } +/*! CLI support function for restarting a plugin + * + * @param[in] h Clicon handle + * @param[in] cvv Not used + * @param[in] arg A string with + * @code + * restart("comment") , cli_restart_plugin("myplugin", "restart"); + * @endcode + */ +int +cli_restart_plugin(clicon_handle h, + cvec *cvv, + cvec *argv) +{ + int retval = -1; + cg_var *cv; + char *plugin; + + if ((cv = cvec_find_var(cvv, "plugin")) == NULL){ + if (cvec_len(argv) != 1){ + clicon_err(OE_PLUGIN, EINVAL, "Requires plugin variable"); + goto done; + } + cv = cvec_i(argv, 0); + } + plugin = cv_string_get(cv); + retval = clicon_rpc_restart_plugin(h, plugin); + done: + return retval; +} diff --git a/example/main/example_cli.cli b/example/main/example_cli.cli index 76b2b7d8..f0a118ce 100644 --- a/example/main/example_cli.cli +++ b/example/main/example_cli.cli @@ -105,4 +105,5 @@ rpc("example rpc") ("routing instance"), example_client_rpc(""); notify("Get notifications from backend"), cli_notify("EXAMPLE", "1", "text"); no("Negate") notify("Get notifications from backend"), cli_notify("EXAMPLE", "0", "xml"); lock,cli_lock("candidate"); -unlock,cli_unlock("candidate"); \ No newline at end of file +unlock,cli_unlock("candidate"); +restart , cli_restart_plugin(); diff --git a/lib/clixon/clixon_proto_client.h b/lib/clixon/clixon_proto_client.h index 666c52e1..d350c379 100644 --- a/lib/clixon/clixon_proto_client.h +++ b/lib/clixon/clixon_proto_client.h @@ -69,5 +69,6 @@ int clicon_rpc_create_subscription(clicon_handle h, char *stream, char *filter, int clicon_rpc_debug(clicon_handle h, int level); int clicon_rpc_restconf_debug(clicon_handle h, int level); int clicon_hello_req(clicon_handle h, uint32_t *id); +int clicon_rpc_restart_plugin(clicon_handle h, char *plugin); #endif /* _CLIXON_PROTO_CLIENT_H_ */ diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index 8e982e46..735f0599 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -1424,3 +1424,50 @@ clicon_hello_req(clicon_handle h, xml_free(xret); return retval; } + +/*! Send a restart plugin request to backend server + * @param[in] h CLICON handle + * @param[in] level Debug level + * @retval 0 OK + * @retval -1 Error and logged to syslog + */ +int +clicon_rpc_restart_plugin(clicon_handle h, + char *plugin) +{ + int retval = -1; + struct clicon_msg *msg = NULL; + cxobj *xret = NULL; + cxobj *xerr; + char *username; + uint32_t session_id; + + if (session_id_check(h, &session_id) < 0) + goto done; + username = clicon_username_get(h); + if ((msg = clicon_msg_encode(session_id, + "%s", + NETCONF_BASE_NAMESPACE, + username?username:"", + NETCONF_MESSAGE_ID_ATTR, + CLIXON_LIB_NS, + plugin)) == NULL) + goto done; + if (clicon_rpc_msg(h, msg, &xret) < 0) + goto done; + if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){ + clixon_netconf_error(xerr, "Debug", NULL); + goto done; + } + if (xpath_first(xret, NULL, "//rpc-reply/ok") == NULL){ + clicon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */ + goto done; + } + retval = 0; + done: + if (msg) + free(msg); + if (xret) + xml_free(xret); + return retval; +}