System-only-config
* Fix startup diff * Add system-only to running on startup * JSON support:
This commit is contained in:
parent
3a656fac07
commit
69b65ad13d
19 changed files with 276 additions and 105 deletions
|
|
@ -172,13 +172,22 @@ startup_common(clixon_handle h,
|
|||
cxobj *xret = NULL;
|
||||
cxobj *xerr = NULL;
|
||||
|
||||
clixon_debug(CLIXON_DBG_BACKEND, "Reading initial config from %s", db);
|
||||
/* If CLICON_XMLDB_MODSTATE is enabled, then get the db XML with
|
||||
* potentially non-matching module-state in msdiff
|
||||
*/
|
||||
if (clicon_option_bool(h, "CLICON_XMLDB_MODSTATE"))
|
||||
if ((msdiff = modstate_diff_new()) == NULL)
|
||||
goto done;
|
||||
clixon_debug(CLIXON_DBG_BACKEND, "Reading initial config from %s", db);
|
||||
/* Add system-only config to running */
|
||||
if (clicon_option_bool(h, "CLICON_XMLDB_SYSTEM_ONLY_CONFIG")){
|
||||
if ((ret = xmldb_get0(h, "running", YB_MODULE, NULL, "/", 0, 0, &xt, NULL, NULL)) < 0)
|
||||
goto done;
|
||||
if (xmldb_system_only_config(h, "/", NULL, &xt) < 0)
|
||||
goto done;
|
||||
td->td_src = xt;
|
||||
xt = NULL;
|
||||
}
|
||||
if (clicon_option_bool(h, "CLICON_XMLDB_UPGRADE_CHECKOLD")){
|
||||
if ((ret = xmldb_get0(h, db, YB_MODULE, NULL, "/", 0, 0, &xt, msdiff, &xerr)) < 0)
|
||||
goto done;
|
||||
|
|
@ -659,6 +668,7 @@ candidate_validate(clixon_handle h,
|
|||
* @retval 1 Validation OK
|
||||
* @retval 0 Validation failed (with cbret set)
|
||||
* @retval -1 Error - or validation failed
|
||||
* @see startup_commit for commit on startup
|
||||
*/
|
||||
int
|
||||
candidate_commit(clixon_handle h,
|
||||
|
|
|
|||
|
|
@ -1461,7 +1461,7 @@ save_config_file(clixon_handle h,
|
|||
goto done;
|
||||
break;
|
||||
case FORMAT_JSON:
|
||||
if (clixon_json2file(f, xt, pretty, fprintf, 0, 1) < 0)
|
||||
if (clixon_json2file(f, xt, pretty, fprintf, 0, 1, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_TEXT:
|
||||
|
|
@ -1587,7 +1587,7 @@ cli_notification_cb(int s,
|
|||
goto done;
|
||||
switch (format){
|
||||
case FORMAT_JSON:
|
||||
if (clixon_json2file(stdout, xt, 1, cligen_output, 1, 1) < 0)
|
||||
if (clixon_json2file(stdout, xt, 1, cligen_output, 1, 1, 0) < 0)
|
||||
goto done;
|
||||
case FORMAT_TEXT:
|
||||
if (clixon_text2file(stdout, xt, 0, cligen_output, 1, 1) < 0)
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ pipe_showas_fn(clixon_handle h,
|
|||
goto done;
|
||||
break;
|
||||
case FORMAT_JSON:
|
||||
if (clixon_json2file(stdout, xt, pretty, cligen_output, 1, 0) < 0)
|
||||
if (clixon_json2file(stdout, xt, pretty, cligen_output, 1, 0, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_TEXT:
|
||||
|
|
|
|||
|
|
@ -1434,7 +1434,7 @@ cli_pagination(clixon_handle h,
|
|||
goto done;
|
||||
break;
|
||||
case FORMAT_JSON:
|
||||
if (clixon_json2file(stdout, xc, 1, cligen_output, 0, 1) < 0)
|
||||
if (clixon_json2file(stdout, xc, 1, cligen_output, 0, 1, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_TEXT:
|
||||
|
|
|
|||
|
|
@ -308,14 +308,14 @@ api_return_err(clixon_handle h,
|
|||
clixon_debug(CLIXON_DBG_RESTCONF, "code:%d", code);
|
||||
if (pretty){
|
||||
cprintf(cb, "{\n\"ietf-restconf:errors\" : ");
|
||||
if (clixon_json2cbuf(cb, xerr, pretty, 0, 0) < 0)
|
||||
if (clixon_json2cbuf(cb, xerr, pretty, 0, 0, 0) < 0)
|
||||
goto done;
|
||||
cprintf(cb, "\n}\r\n");
|
||||
}
|
||||
else{
|
||||
cprintf(cb, "{");
|
||||
cprintf(cb, "\"ietf-restconf:errors\":");
|
||||
if (clixon_json2cbuf(cb, xerr, pretty, 0, 0) < 0)
|
||||
if (clixon_json2cbuf(cb, xerr, pretty, 0, 0, 0) < 0)
|
||||
goto done;
|
||||
cprintf(cb, "}\r\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ api_data_get2(clixon_handle h,
|
|||
goto done;
|
||||
break;
|
||||
case YANG_DATA_JSON:
|
||||
if (clixon_json2cbuf(cbx, xret, pretty, 0, 0) < 0)
|
||||
if (clixon_json2cbuf(cbx, xret, pretty, 0, 0, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ yang_patch_xml2json_modified_cbuf(cxobj *x_simple_patch)
|
|||
if (json_simple_patch == NULL)
|
||||
return NULL;
|
||||
cb = cbuf_new();
|
||||
if (clixon_json2cbuf(cb, x_simple_patch, 0, 0) < 0)
|
||||
if (clixon_json2cbuf(cb, x_simple_patch, 0, 0, 0) < 0)
|
||||
goto done;
|
||||
|
||||
// Insert a '[' after the first '{' to get the JSON to match what api_data_post/write() expect
|
||||
|
|
@ -271,7 +271,7 @@ yang_patch_do_replace(clixon_handle h,
|
|||
}
|
||||
}
|
||||
// Convert the data to json
|
||||
if (clixon_json2cbuf(json_simple_patch, x_simple_patch, 0, 0) < 0)
|
||||
if (clixon_json2cbuf(json_simple_patch, x_simple_patch, 0, 0, 0) < 0)
|
||||
goto done;
|
||||
|
||||
// Send the POST request
|
||||
|
|
@ -336,7 +336,7 @@ yang_patch_do_create(clixon_handle h,
|
|||
xml_addsub(x_simple_patch, value_vec_tmp);
|
||||
}
|
||||
}
|
||||
if (clixon_json2cbuf(cb, x_simple_patch, 0, 0) < 0)
|
||||
if (clixon_json2cbuf(cb, x_simple_patch, 0, 0, 0) < 0)
|
||||
goto done;
|
||||
if (api_data_post(h, req, cbuf_get(simple_patch_request_uri),
|
||||
pi, qvec,
|
||||
|
|
@ -492,7 +492,7 @@ yang_patch_do_merge(clixon_handle h,
|
|||
xml_addsub(x_simple_patch, value_vec_tmp);
|
||||
}
|
||||
cbuf_reset(cb); /* reuse cb */
|
||||
if (clixon_json2cbuf(cb, x_simple_patch, 0, 0) < 0)
|
||||
if (clixon_json2cbuf(cb, x_simple_patch, 0, 0, 0) < 0)
|
||||
goto done;
|
||||
|
||||
if ((json_simple_patch = yang_patch_xml2json_modified_cbuf(x_simple_patch)) == NULL)
|
||||
|
|
|
|||
|
|
@ -884,7 +884,7 @@ api_operations_post(clixon_handle h,
|
|||
/* xoutput should now look: <output xmlns="uri"><x>0</x></output> */
|
||||
break;
|
||||
case YANG_DATA_JSON:
|
||||
if (clixon_json2cbuf(cbret, xoutput, pretty, 0, 0) < 0)
|
||||
if (clixon_json2cbuf(cbret, xoutput, pretty, 0, 0, 0) < 0)
|
||||
goto done;
|
||||
/* xoutput should now look: {"example:output": {"x":0,"y":42}} */
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ api_root_restconf_exact(clixon_handle h,
|
|||
break;
|
||||
case YANG_DATA_JSON:
|
||||
case YANG_PATCH_JSON:
|
||||
if (clixon_json2cbuf(cb, xt, pretty, 0, 0) < 0)
|
||||
if (clixon_json2cbuf(cb, xt, pretty, 0, 0, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -299,7 +299,7 @@ api_yang_library_version(clixon_handle h,
|
|||
break;
|
||||
case YANG_DATA_JSON:
|
||||
case YANG_PATCH_JSON:
|
||||
if (clixon_json2cbuf(cb, xt, pretty, 0, 0) < 0)
|
||||
if (clixon_json2cbuf(cb, xt, pretty, 0, 0, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue