Upgrade creator-attr code
This commit is contained in:
parent
ea645d1334
commit
7b5dc3d24c
3 changed files with 8 additions and 77 deletions
|
|
@ -859,10 +859,6 @@ xmldb_get_nocache(clixon_handle h,
|
||||||
if (disable_nacm_on_empty(xt, yspec) < 0)
|
if (disable_nacm_on_empty(xt, yspec) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
#if 0 /* debug */
|
|
||||||
if (xml_apply0(xt, -1, xml_sort_verify, NULL) < 0)
|
|
||||||
clixon_log(h, LOG_NOTICE, "%s: sort verify failed #2", __FUNCTION__);
|
|
||||||
#endif
|
|
||||||
if (clixon_debug_get()>1)
|
if (clixon_debug_get()>1)
|
||||||
if (clixon_xml2file(stderr, xt, 0, 1, NULL, fprintf, 0, 0) < 0)
|
if (clixon_xml2file(stderr, xt, 0, 1, NULL, fprintf, 0, 0) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -1007,8 +1003,10 @@ xmldb_get_cache(clixon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
/* Original tree: Remove global defaults and empty non-presence containers */
|
/* Original tree: Remove global defaults and empty non-presence containers */
|
||||||
|
#if 0
|
||||||
if (xml_defaults_nopresence(x0t, 2) < 0)
|
if (xml_defaults_nopresence(x0t, 2) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
#endif
|
||||||
switch (wdef){
|
switch (wdef){
|
||||||
case WITHDEFAULTS_REPORT_ALL:
|
case WITHDEFAULTS_REPORT_ALL:
|
||||||
break;
|
break;
|
||||||
|
|
@ -1016,8 +1014,7 @@ xmldb_get_cache(clixon_handle h,
|
||||||
/* Mark and remove nodes having schema default values */
|
/* Mark and remove nodes having schema default values */
|
||||||
if (xml_apply(x1t, CX_ELMNT, (xml_applyfn_t*) xml_flag_default_value, (void*) XML_FLAG_MARK) < 0)
|
if (xml_apply(x1t, CX_ELMNT, (xml_applyfn_t*) xml_flag_default_value, (void*) XML_FLAG_MARK) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (xml_tree_prune_flags(x1t, XML_FLAG_MARK, XML_FLAG_MARK)
|
if (xml_tree_prune_flags(x1t, XML_FLAG_MARK, XML_FLAG_MARK) < 0)
|
||||||
< 0)
|
|
||||||
goto done;
|
goto done;
|
||||||
if (xml_defaults_nopresence(x1t, 1) < 0)
|
if (xml_defaults_nopresence(x1t, 1) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
|
||||||
|
|
@ -145,70 +145,6 @@ attr_ns_value(cxobj *x,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Add creator data to metadata xml object on the form name:xpath*
|
|
||||||
*
|
|
||||||
* Callback function type for xml_apply
|
|
||||||
* @param[in] x XML node
|
|
||||||
* @param[in] arg General-purpose argument
|
|
||||||
* @retval -1 Error, aborted at first error encounter, return -1 to end user
|
|
||||||
* @retval 0 OK, continue
|
|
||||||
* @retval 1 Abort, dont continue with others, return 1 to end user
|
|
||||||
* @retval 2 Locally abort this subtree, continue with others
|
|
||||||
* On the form:
|
|
||||||
* <creator>
|
|
||||||
* <name>testA[name='foo']</name>
|
|
||||||
* <xpath>...</xpath>
|
|
||||||
* ...
|
|
||||||
* </creator>
|
|
||||||
* @see xml_creator_metadata_read
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
xml_creator_metadata_write(cxobj *x,
|
|
||||||
void *arg)
|
|
||||||
{
|
|
||||||
int retval = -1;
|
|
||||||
cxobj *xmeta = (cxobj*)arg;
|
|
||||||
cxobj *xmc;
|
|
||||||
cvec *cvv;
|
|
||||||
cg_var *cv;
|
|
||||||
char *val;
|
|
||||||
cvec *nsc = NULL;
|
|
||||||
char *xpath = NULL;
|
|
||||||
|
|
||||||
if ((cvv = xml_creator_get(x)) == NULL){
|
|
||||||
retval = 0;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
/* Note this requires x to have YANG spec */
|
|
||||||
if (xml2xpath(x, nsc, 0, 0, &xpath) < 0)
|
|
||||||
goto done;
|
|
||||||
cv = NULL;
|
|
||||||
while ((cv = cvec_each(cvv, cv)) != NULL){
|
|
||||||
val = cv_name_get(cv);
|
|
||||||
/* Find existing entry where name is val */
|
|
||||||
xmc = NULL;
|
|
||||||
while ((xmc = xml_child_each(xmeta, xmc, CX_ELMNT)) != NULL){
|
|
||||||
if (strcmp(xml_find_body(xmc, "name"), val) == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (xmc != NULL){
|
|
||||||
if (clixon_xml_parse_va(YB_NONE, NULL, &xmc, NULL, "<path>%s</path>", xpath) < 0)
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (clixon_xml_parse_va(YB_NONE, NULL, &xmeta, NULL,
|
|
||||||
"<creator><name>%s</name><path>%s</path></creator>",
|
|
||||||
val, xpath) < 0)
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
retval = 2;
|
|
||||||
done:
|
|
||||||
if (xpath)
|
|
||||||
free(xpath);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! When new body is added, some needs type lookup is made and namespace checked
|
/*! When new body is added, some needs type lookup is made and namespace checked
|
||||||
*
|
*
|
||||||
* This includes identityrefs, paths
|
* This includes identityrefs, paths
|
||||||
|
|
@ -1416,13 +1352,12 @@ xmldb_put(clixon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
pretty = clicon_option_bool(h, "CLICON_XMLDB_PRETTY");
|
pretty = clicon_option_bool(h, "CLICON_XMLDB_PRETTY");
|
||||||
/* Add creator attribute */
|
/* Add creator attributes to datastore */
|
||||||
if (clicon_option_bool(h, "CLICON_NETCONF_CREATOR_ATTR")){
|
if (clicon_option_bool(h, "CLICON_NETCONF_CREATOR_ATTR")){
|
||||||
if ((xmeta = xml_new("creators", x0, CX_ELMNT)) == NULL)
|
/* @see xml_creator_metadata_read */
|
||||||
|
if (xml_creator_tree(x0, &xmeta) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (xmlns_set(xmeta, NULL, CLIXON_LIB_NS) < 0)
|
if (xml_addsub(x0, xmeta) < 0)
|
||||||
goto done;
|
|
||||||
if (xml_apply(x0, CX_ELMNT, xml_creator_metadata_write, xmeta) < 0)
|
|
||||||
goto done;
|
goto done;
|
||||||
if (xml_child_nr_type(xmeta, CX_ELMNT) == 0){
|
if (xml_child_nr_type(xmeta, CX_ELMNT) == 0){
|
||||||
xml_purge(xmeta);
|
xml_purge(xmeta);
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,6 @@ cat <<EOF > $fstate
|
||||||
</interfaces>
|
</interfaces>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
||||||
db=startup
|
db=startup
|
||||||
if [ $db = startup ]; then
|
if [ $db = startup ]; then
|
||||||
sudo echo "<${DATASTORE_TOP}>$XML</${DATASTORE_TOP}>" > $dir/startup_db
|
sudo echo "<${DATASTORE_TOP}>$XML</${DATASTORE_TOP}>" > $dir/startup_db
|
||||||
|
|
@ -334,7 +333,7 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||||
"<rpc $DEFAULTNS><edit-config><target><candidate/></target><config>\
|
"<rpc $DEFAULTNS><edit-config><target><candidate/></target><config>\
|
||||||
<interfaces $EXAMPLENS xmlns:nc=\"${BASENS}\">\
|
<interfaces $EXAMPLENS xmlns:nc=\"${BASENS}\">\
|
||||||
<interface><name>eth1</name><mtu nc:operation=\"create\">3000</mtu></interface>\
|
<interface><name>eth1</name><mtu nc:operation=\"create\">3000</mtu></interface>\
|
||||||
</interfaces></config><default-operation>none</default-operation> </edit-config></rpc>" \
|
</interfaces></config><default-operation>none</default-operation></edit-config></rpc>" \
|
||||||
"" \
|
"" \
|
||||||
"<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
"<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue