* Made a separate Clixon datastore XML/JSON top-level symbol
* Replaces the hardcoded "config" keyword. * Implemented by a compile-time option called `DATASTORE_TOP_SYMBOL` option in clixon_custom.h * Tests: added endtest to all tests. Removed all premature exits if BE=0
This commit is contained in:
parent
2ab90d847b
commit
b7991d9b39
132 changed files with 939 additions and 628 deletions
|
|
@ -443,7 +443,7 @@ client_get_config_only(clicon_handle h,
|
|||
if (xret==NULL)
|
||||
cprintf(cbret, "<data/>");
|
||||
else{
|
||||
if (xml_name_set(xret, "data") < 0)
|
||||
if (xml_name_set(xret, NETCONF_OUTPUT_DATA) < 0)
|
||||
goto done;
|
||||
if (clicon_xml2cbuf(cbret, xret, 0, 0, depth>0?depth+1:depth) < 0)
|
||||
goto done;
|
||||
|
|
@ -638,10 +638,13 @@ from_client_edit_config(clicon_handle h,
|
|||
}
|
||||
}
|
||||
/* Get config element */
|
||||
if ((xc = xpath_first(xn, nsc, "%s%sconfig", prefix?prefix:"", prefix?":":"")) == NULL){
|
||||
if ((xc = xpath_first(xn, nsc, "%s%s%s",
|
||||
prefix?prefix:"",
|
||||
prefix?":":"",
|
||||
NETCONF_INPUT_CONFIG)) == NULL){
|
||||
cprintf(cbx, "Element not found, or mismatching prefix %s for namespace %s",
|
||||
prefix?prefix:"null", NETCONF_BASE_NAMESPACE);
|
||||
if (netconf_missing_element(cbret, "protocol", "config", cbuf_get(cbx)) < 0)
|
||||
if (netconf_missing_element(cbret, "protocol", NETCONF_INPUT_CONFIG, cbuf_get(cbx)) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
|
|
@ -1215,7 +1218,7 @@ from_client_get(clicon_handle h,
|
|||
if (xret==NULL)
|
||||
cprintf(cbret, "<data/>");
|
||||
else{
|
||||
if (xml_name_set(xret, "data") < 0)
|
||||
if (xml_name_set(xret, NETCONF_OUTPUT_DATA) < 0)
|
||||
goto done;
|
||||
/* Top level is data, so add 1 to depth if significant */
|
||||
if (clicon_xml2cbuf(cbret, xret, 0, 0, depth>0?depth+1:depth) < 0)
|
||||
|
|
|
|||
|
|
@ -399,32 +399,37 @@ startup_commit(clicon_handle h,
|
|||
goto done;
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
/* 8. Call plugin transaction commit callbacks */
|
||||
if (plugin_transaction_commit_all(h, td) < 0)
|
||||
goto done;
|
||||
/* After commit, make a post-commit call (sure that all plugins have committed) */
|
||||
if (plugin_transaction_commit_done_all(h, td) < 0)
|
||||
goto done;
|
||||
/* Clear cached trees from default values and marking */
|
||||
if (xmldb_get0_clear(h, td->td_target) < 0)
|
||||
goto done;
|
||||
/* 8. Call plugin transaction commit callbacks */
|
||||
if (plugin_transaction_commit_all(h, td) < 0)
|
||||
goto done;
|
||||
/* After commit, make a post-commit call (sure that all plugins have committed) */
|
||||
if (plugin_transaction_commit_done_all(h, td) < 0)
|
||||
goto done;
|
||||
/* Clear cached trees from default values and marking */
|
||||
if (xmldb_get0_clear(h, td->td_target) < 0)
|
||||
goto done;
|
||||
|
||||
/* [Delete and] create running db */
|
||||
if (xmldb_exists(h, "running") == 1){
|
||||
/* [Delete and] create running db */
|
||||
if (xmldb_exists(h, "running") == 1){
|
||||
if (xmldb_delete(h, "running") != 0 && errno != ENOENT)
|
||||
goto done;;
|
||||
}
|
||||
if (xmldb_create(h, "running") < 0)
|
||||
goto done;
|
||||
/* 9, write (potentially modified) tree to running
|
||||
* XXX note here startup is copied to candidate, which may confuse everything
|
||||
* XXX default values are overwritten
|
||||
*/
|
||||
if ((ret = xmldb_put(h, "running", OP_REPLACE, td->td_target,
|
||||
clicon_username_get(h), cbret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
/* 9, write (potentially modified) tree to running
|
||||
* XXX note here startup is copied to candidate, which may confuse everything
|
||||
* XXX default values are overwritten
|
||||
*/
|
||||
if (td->td_target)
|
||||
/* target is datastore, but is here transformed to mimic an incoming
|
||||
* edit-config
|
||||
*/
|
||||
xml_name_set(td->td_target, NETCONF_INPUT_CONFIG);
|
||||
if ((ret = xmldb_put(h, "running", OP_REPLACE, td->td_target,
|
||||
clicon_username_get(h), cbret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
/* 10. Call plugin transaction end callbacks */
|
||||
plugin_transaction_end_all(h, td);
|
||||
retval = 1;
|
||||
|
|
@ -432,8 +437,8 @@ startup_commit(clicon_handle h,
|
|||
if (td){
|
||||
if (retval < 1)
|
||||
plugin_transaction_abort_all(h, td);
|
||||
xmldb_get0_free(h, &td->td_target);
|
||||
transaction_free(td);
|
||||
xmldb_get0_free(h, &td->td_target);
|
||||
transaction_free(td);
|
||||
}
|
||||
return retval;
|
||||
fail: /* cbret should be set */
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ clixon_plugin_statedata_one(clixon_plugin *cp,
|
|||
cxobj *x = NULL;
|
||||
|
||||
if ((fn = cp->cp_api.ca_statedata) != NULL){
|
||||
if ((x = xml_new("config", NULL, CX_ELMNT)) == NULL)
|
||||
if ((x = xml_new(XML_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
|
||||
goto done;
|
||||
if (fn(h, nsc, xpath, x) < 0){
|
||||
if (clicon_errno < 0)
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ db_merge(clicon_handle h,
|
|||
/* Get data as xml from db1 */
|
||||
if (xmldb_get0(h, (char*)db1, YB_MODULE, NULL, NULL, 0, &xt, NULL) < 0)
|
||||
goto done;
|
||||
xml_name_set(xt, NETCONF_INPUT_CONFIG);
|
||||
/* Merge xml into db2. Without commit */
|
||||
retval = xmldb_put(h, (char*)db2, OP_MERGE, xt, clicon_username_get(h), cbret);
|
||||
done:
|
||||
|
|
@ -168,8 +169,10 @@ load_extraxml(clicon_handle h,
|
|||
{
|
||||
int retval = -1;
|
||||
cxobj *xt = NULL;
|
||||
cxobj *xerr = NULL;
|
||||
FILE *fp = NULL;
|
||||
yang_stmt *yspec = NULL;
|
||||
int ret;
|
||||
|
||||
if (filename == NULL)
|
||||
return 1;
|
||||
|
|
@ -178,11 +181,25 @@ load_extraxml(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if (clixon_xml_parse_file(fp, YB_MODULE, yspec, NULL, &xt, NULL) < 0)
|
||||
/* No yang check yet because it has <config> as top symbol, do it later after that is removed */
|
||||
if (clixon_xml_parse_file(fp, YB_NONE, yspec, NULL, &xt, &xerr) < 0)
|
||||
goto done;
|
||||
/* Replace parent w first child */
|
||||
if (xml_rootchild(xt, 0, &xt) < 0)
|
||||
goto done;
|
||||
/* Ensure edit-config "config" statement */
|
||||
if (xt)
|
||||
xml_name_set(xt, NETCONF_INPUT_CONFIG);
|
||||
/* Now we can yang bind */
|
||||
if ((ret = xml_bind_yang(xt, YB_MODULE, yspec, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if (netconf_err2cb(xerr, cbret) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Merge user reset state */
|
||||
retval = xmldb_put(h, (char*)db, OP_MERGE, xt, clicon_username_get(h), cbret);
|
||||
done:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue