* Restconf: added inline configuration using -R <xml> command line as an alternative to making advanced restconf configuration
This commit is contained in:
parent
1ef7a280d7
commit
164aa1cb4c
9 changed files with 161 additions and 41 deletions
|
|
@ -61,10 +61,11 @@
|
|||
|
||||
#define RESTCONF_PROCESS "restconf"
|
||||
|
||||
/*! Set current debug flag when starting process using -D <dbg>
|
||||
/*! Set current debug and log flags when starting process using -D <dbg> -l <logdst>
|
||||
*
|
||||
* process argv list including -D is set on start. But the debug flags may change and this is a way
|
||||
* to set it dynamically, ie at the time the process is started, not when the backend is started.
|
||||
* process argv list including -D and -l are set on start. But the debug/log flags may change and
|
||||
* this is a way to set it dynamically, ie at the time the process is started, not when the backend
|
||||
* is started.
|
||||
* @param[in] h Clixon backend
|
||||
* @param[in] xt XML target
|
||||
*/
|
||||
|
|
@ -129,6 +130,57 @@ restconf_pseudo_set_log(clicon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Set current restconf inline config when starting process using -R <config>
|
||||
*
|
||||
* process argv list including -R is set on start. Get the running restconfig config, stringify it
|
||||
* and insert it as a optimization to reading it from the backend.
|
||||
* @param[in] h Clixon backend
|
||||
* @param[in] xt XML target
|
||||
*/
|
||||
static int
|
||||
restconf_pseudo_set_inline(clicon_handle h,
|
||||
cxobj *xt)
|
||||
{
|
||||
int retval = -1;
|
||||
char **argv;
|
||||
int argc;
|
||||
int i;
|
||||
char *str = NULL;
|
||||
cxobj *xrestconf;
|
||||
cbuf *cb = NULL;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
if (clixon_process_argv_get(h, RESTCONF_PROCESS, &argv, &argc) < 0)
|
||||
goto done;
|
||||
if ((xrestconf = xpath_first(xt, NULL, "restconf")) != NULL)
|
||||
for (i=0; i<argc; i++){
|
||||
if (argv[i] == NULL)
|
||||
break;
|
||||
if (strcmp(argv[i], "-R") == 0 && argc > i+1 && argv[i+1]){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (clicon_xml2cbuf(cb, xrestconf, 0, 0, -1) < 0)
|
||||
goto done;
|
||||
if ((str = strdup(cbuf_get(cb))) == NULL){
|
||||
clicon_err(OE_XML, errno, "stdup");
|
||||
goto done;
|
||||
}
|
||||
clicon_debug(1, "%s str:%s", __FUNCTION__, str);
|
||||
if (argv[i+1])
|
||||
free(argv[i+1]);
|
||||
argv[i+1] = str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Process rpc callback function
|
||||
* - if RPC op is start, if enable is true, start the service, if false, error or ignore it
|
||||
* - if RPC op is stop, stop the service
|
||||
|
|
@ -164,6 +216,8 @@ restconf_rpc_wrapper(clicon_handle h,
|
|||
*/
|
||||
if (restconf_pseudo_set_log(h, xt) < 0)
|
||||
goto done;
|
||||
if (restconf_pseudo_set_inline(h, xt) < 0)
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
@ -192,7 +246,7 @@ restconf_pseudo_process_control(clicon_handle h)
|
|||
int nr;
|
||||
cbuf *cb = NULL;
|
||||
|
||||
nr = 8;
|
||||
nr = 10;
|
||||
if ((argv = calloc(nr, sizeof(char *))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
goto done;
|
||||
|
|
@ -216,9 +270,11 @@ restconf_pseudo_process_control(clicon_handle h)
|
|||
* see restconf_pseudo_set_log which sets flag when process starts
|
||||
*/
|
||||
argv[i++] = "-D";
|
||||
argv[i++] = "0";
|
||||
argv[i++] = strdup("0");
|
||||
argv[i++] = "-l";
|
||||
argv[i++] = "s"; /* There is also log-destination in clixon-restconf.yang */
|
||||
argv[i++] = strdup("s"); /* There is also log-destination in clixon-restconf.yang */
|
||||
argv[i++] = "-R";
|
||||
argv[i++] = strdup("");
|
||||
argv[i++] = NULL;
|
||||
assert(i==nr);
|
||||
if (clixon_process_register(h, RESTCONF_PROCESS,
|
||||
|
|
@ -289,6 +345,8 @@ restconf_pseudo_process_commit(clicon_handle h,
|
|||
*/
|
||||
if (restconf_pseudo_set_log(h, xtarget) < 0)
|
||||
goto done;
|
||||
if (restconf_pseudo_set_inline(h, xtarget) < 0)
|
||||
goto done;
|
||||
/* Toggle start/stop if enable flag changed */
|
||||
if ((cx = xpath_first(xtarget, NULL, "/restconf/enable")) != NULL &&
|
||||
xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_ADD)){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue