Non-key list now not accepted in edit-config (before only on validation)
This commit is contained in:
parent
4e23864acd
commit
06e6ef80d1
25 changed files with 620 additions and 71 deletions
|
|
@ -433,6 +433,7 @@ from_client_edit_config(clicon_handle h,
|
|||
*/
|
||||
if (xml_apply(xc, CX_ELMNT, xml_spec_populate, yspec) < 0)
|
||||
goto done;
|
||||
|
||||
if (xml_apply(xc, CX_ELMNT, xml_non_config_data, &non_config) < 0)
|
||||
goto done;
|
||||
if (non_config){
|
||||
|
|
@ -440,6 +441,11 @@ from_client_edit_config(clicon_handle h,
|
|||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
/* xmldb_put (difflist handling) requires list keys */
|
||||
if ((ret = xml_yang_validate_list_key_only(xc, cbret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
goto ok;
|
||||
/* Cant do this earlier since we dont have a yang spec to
|
||||
* the upper part of the tree, until we get the "config" tree.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -160,6 +160,7 @@ generic_validate(yang_stmt *yspec,
|
|||
* 4. Validate startup db. (valid)
|
||||
* 5. If valid fails, call startup-cb(Invalid, msdiff), keep startup in candidate and commit failsafe db. Done.
|
||||
* 6. Call startup-cb(OK, msdiff) and commit.
|
||||
* @see from_validate_common for incoming validate/commit
|
||||
*/
|
||||
static int
|
||||
startup_common(clicon_handle h,
|
||||
|
|
@ -181,10 +182,14 @@ startup_common(clicon_handle h,
|
|||
if ((msd = modstate_diff_new()) == NULL)
|
||||
goto done;
|
||||
clicon_debug(1, "Reading startup config from %s", db);
|
||||
if (xmldb_get(h, db, "/", &xt, msd) < 0)
|
||||
if (xmldb_get1(h, db, "/", &xt, msd) < 0)
|
||||
goto done;
|
||||
/* Clear flags xpath for get */
|
||||
xml_apply0(xt, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset,
|
||||
(void*)(XML_FLAG_MARK|XML_FLAG_CHANGE));
|
||||
if (xml_child_nr(xt) == 0){ /* If empty skip */
|
||||
td->td_target = xt;
|
||||
xt = NULL;
|
||||
goto ok;
|
||||
}
|
||||
if (msd){
|
||||
|
|
@ -204,6 +209,7 @@ startup_common(clicon_handle h,
|
|||
goto done;
|
||||
/* Handcraft transition with with only add tree */
|
||||
td->td_target = xt;
|
||||
xt = NULL;
|
||||
x = NULL;
|
||||
while ((x = xml_child_each(td->td_target, x, CX_ELMNT)) != NULL){
|
||||
if (cxvec_append(x, &td->td_avec, &td->td_alen) < 0)
|
||||
|
|
@ -232,6 +238,8 @@ startup_common(clicon_handle h,
|
|||
ok:
|
||||
retval = 1;
|
||||
done:
|
||||
if (xt)
|
||||
xml_free(xt);
|
||||
if (msd)
|
||||
modstate_diff_free(msd);
|
||||
return retval;
|
||||
|
|
@ -267,14 +275,23 @@ startup_validate(clicon_handle h,
|
|||
goto done;
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
/* Clear cached trees from default values and marking */
|
||||
if (xmldb_get1_clear(h, db) < 0)
|
||||
goto done;
|
||||
if (xtr){
|
||||
*xtr = td->td_target;
|
||||
td->td_target = NULL;
|
||||
}
|
||||
retval = 1;
|
||||
done:
|
||||
if (td)
|
||||
transaction_free(td);
|
||||
if (td){
|
||||
if (clicon_option_bool(h, "CLICON_XMLDB_CACHE")){
|
||||
/* xmldb_get1 requires free only if not cache */
|
||||
td->td_target = NULL;
|
||||
td->td_src = NULL;
|
||||
}
|
||||
transaction_free(td);
|
||||
}
|
||||
return retval;
|
||||
fail: /* cbret should be set */
|
||||
retval = 0;
|
||||
|
|
@ -314,6 +331,10 @@ startup_commit(clicon_handle h,
|
|||
/* 8. Call plugin transaction commit callbacks */
|
||||
if (plugin_transaction_commit(h, td) < 0)
|
||||
goto done;
|
||||
/* Clear cached trees from default values and marking */
|
||||
if (xmldb_get1_clear(h, db) < 0)
|
||||
goto done;
|
||||
|
||||
/* [Delete and] create running db */
|
||||
if (xmldb_exists(h, "running") == 1){
|
||||
if (xmldb_delete(h, "running") != 0 && errno != ENOENT)
|
||||
|
|
@ -334,8 +355,14 @@ startup_commit(clicon_handle h,
|
|||
|
||||
retval = 1;
|
||||
done:
|
||||
if (td)
|
||||
transaction_free(td);
|
||||
if (td){
|
||||
if (clicon_option_bool(h, "CLICON_XMLDB_CACHE")){
|
||||
/* xmldb_get1 requires free only if not cache */
|
||||
td->td_target = NULL;
|
||||
td->td_src = NULL;
|
||||
}
|
||||
transaction_free(td);
|
||||
}
|
||||
return retval;
|
||||
fail: /* cbret should be set */
|
||||
retval = 0;
|
||||
|
|
@ -352,6 +379,7 @@ startup_commit(clicon_handle h,
|
|||
* @retval 1 Validation OK
|
||||
* @note Need to differentiate between error and validation fail
|
||||
* (only done for generic_validate)
|
||||
* @see startup_common for startup scenario
|
||||
*/
|
||||
static int
|
||||
from_validate_common(clicon_handle h,
|
||||
|
|
@ -511,6 +539,16 @@ candidate_commit(clicon_handle h,
|
|||
*/
|
||||
if (xmldb_copy(h, candidate, "running") < 0)
|
||||
goto done;
|
||||
/* Here pointers to old (source) tree are obsolete */
|
||||
if (td->td_dvec){
|
||||
td->td_dlen = 0;
|
||||
free(td->td_dvec);
|
||||
td->td_dvec = NULL;
|
||||
}
|
||||
if (td->td_scvec){
|
||||
free(td->td_scvec);
|
||||
td->td_scvec = NULL;
|
||||
}
|
||||
|
||||
/* 9. Call plugin transaction end callbacks */
|
||||
plugin_transaction_end(h, td);
|
||||
|
|
|
|||
|
|
@ -709,7 +709,8 @@ main(int argc,
|
|||
demonized errors OK. Before this stage, errors are logged on stderr
|
||||
also */
|
||||
if (foreground==0){
|
||||
clicon_log_init(__PROGRAM__, debug?LOG_DEBUG:LOG_INFO, CLICON_LOG_SYSLOG);
|
||||
clicon_log_init(__PROGRAM__, debug?LOG_DEBUG:LOG_INFO,
|
||||
logdst==CLICON_LOG_FILE?CLICON_LOG_FILE:CLICON_LOG_SYSLOG);
|
||||
if (daemon(0, 0) < 0){
|
||||
fprintf(stderr, "config: daemon");
|
||||
exit(-1);
|
||||
|
|
|
|||
|
|
@ -262,11 +262,6 @@ startup_extraxml(clicon_handle h,
|
|||
goto fail;
|
||||
if (xt==NULL || xml_child_nr(xt)==0)
|
||||
goto ok;
|
||||
/* Write (potentially modified) xml tree xt back to tmp
|
||||
*/
|
||||
if ((ret = xmldb_put(h, "tmp", OP_REPLACE, xt,
|
||||
clicon_username_get(h), cbret)) < 0)
|
||||
goto done;
|
||||
/* Merge tmp into running (no commit) */
|
||||
if ((ret = db_merge(h, db, "running", cbret)) < 0)
|
||||
goto fail;
|
||||
|
|
@ -275,9 +270,9 @@ startup_extraxml(clicon_handle h,
|
|||
ok:
|
||||
retval = 1;
|
||||
done:
|
||||
if (xt)
|
||||
if (xt && !clicon_option_bool(h, "CLICON_XMLDB_CACHE"))
|
||||
xml_free(xt);
|
||||
if (xmldb_delete(h, "tmp") != 0 && errno != ENOENT)
|
||||
if (xmldb_delete(h, db) != 0 && errno != ENOENT)
|
||||
return -1;
|
||||
return retval;
|
||||
fail:
|
||||
|
|
|
|||
|
|
@ -188,6 +188,9 @@ transaction_clen(transaction_data td)
|
|||
return ((transaction_data_t *)td)->td_clen;
|
||||
}
|
||||
|
||||
/*! Print transaction on FILE for debug
|
||||
* @see transaction_log
|
||||
*/
|
||||
int
|
||||
transaction_print(FILE *f,
|
||||
transaction_data th)
|
||||
|
|
@ -218,3 +221,50 @@ transaction_print(FILE *f,
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
transaction_log(clicon_handle h,
|
||||
transaction_data th,
|
||||
int level,
|
||||
const char *op)
|
||||
{
|
||||
cxobj *xn;
|
||||
int i;
|
||||
transaction_data_t *td;
|
||||
cbuf *cb = NULL;
|
||||
|
||||
td = (transaction_data_t *)th;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_CFG, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
for (i=0; i<td->td_dlen; i++){
|
||||
xn = td->td_dvec[i];
|
||||
clicon_xml2cbuf(cb, xn, 0, 0);
|
||||
}
|
||||
if (i)
|
||||
clicon_log(level, "%s %" PRIu64 " %s del: %s",
|
||||
__FUNCTION__, td->td_id, op, cbuf_get(cb));
|
||||
cbuf_reset(cb);
|
||||
for (i=0; i<td->td_alen; i++){
|
||||
xn = td->td_avec[i];
|
||||
clicon_xml2cbuf(cb, xn, 0, 0);
|
||||
}
|
||||
if (i)
|
||||
clicon_log(level, "%s %" PRIu64 " %s add: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb));
|
||||
cbuf_reset(cb);
|
||||
for (i=0; i<td->td_clen; i++){
|
||||
if (td->td_scvec){
|
||||
xn = td->td_scvec[i];
|
||||
clicon_xml2cbuf(cb, xn, 0, 0);
|
||||
}
|
||||
xn = td->td_tcvec[i];
|
||||
clicon_xml2cbuf(cb, xn, 0, 0);
|
||||
}
|
||||
if (i)
|
||||
clicon_log(level, "%s %" PRIu64 " %s change: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb));
|
||||
done:
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,5 +60,6 @@ cxobj **transaction_tcvec(transaction_data td);
|
|||
size_t transaction_clen(transaction_data td);
|
||||
|
||||
int transaction_print(FILE *f, transaction_data th);
|
||||
int transaction_log(clicon_handle h, transaction_data th, int level, const char *id);
|
||||
|
||||
#endif /* _CLIXON_BACKEND_TRANSACTION_H_ */
|
||||
|
|
|
|||
|
|
@ -656,6 +656,12 @@ cli_show_auto(clicon_handle h,
|
|||
// goto done;
|
||||
if (api_path_fmt2xpath(api_path_fmt, cvv, &xpath) < 0)
|
||||
goto done;
|
||||
/* XXX Kludge to overcome a trailing / in show, that I cannot add to
|
||||
* yang2api_path_fmt_1 where it should belong.
|
||||
*/
|
||||
if (xpath[strlen(xpath)-1] == '/')
|
||||
xpath[strlen(xpath)-1] = '\0';
|
||||
|
||||
/* Get configuration from database */
|
||||
if (clicon_rpc_get_config(h, db, xpath, &xt) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue