Add restart plugin library code for netconf and cli

This commit is contained in:
Olof hagsand 2021-11-13 16:46:47 +01:00
parent 51316d5d61
commit 7976c11f11
4 changed files with 80 additions and 1 deletions

View file

@ -1320,3 +1320,33 @@ cli_help(clicon_handle h, cvec *vars, cvec *argv)
return cligen_help(ch, stdout, pt); 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 <database>
* @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;
}

View file

@ -105,4 +105,5 @@ rpc("example rpc") <a:string>("routing instance"), example_client_rpc("");
notify("Get notifications from backend"), cli_notify("EXAMPLE", "1", "text"); notify("Get notifications from backend"), cli_notify("EXAMPLE", "1", "text");
no("Negate") notify("Get notifications from backend"), cli_notify("EXAMPLE", "0", "xml"); no("Negate") notify("Get notifications from backend"), cli_notify("EXAMPLE", "0", "xml");
lock,cli_lock("candidate"); lock,cli_lock("candidate");
unlock,cli_unlock("candidate"); unlock,cli_unlock("candidate");
restart <plugin:string>, cli_restart_plugin();

View file

@ -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_debug(clicon_handle h, int level);
int clicon_rpc_restconf_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_hello_req(clicon_handle h, uint32_t *id);
int clicon_rpc_restart_plugin(clicon_handle h, char *plugin);
#endif /* _CLIXON_PROTO_CLIENT_H_ */ #endif /* _CLIXON_PROTO_CLIENT_H_ */

View file

@ -1424,3 +1424,50 @@ clicon_hello_req(clicon_handle h,
xml_free(xret); xml_free(xret);
return retval; 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,
"<rpc xmlns=\"%s\" username=\"%s\" %s><restart-plugin xmlns=\"%s\"><plugin>%s</plugin></restart-plugin></rpc>",
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;
}