Added nsctx argument to cli_dbxml() and exposed it as a public function
Added function clixon_instance_id_bind()
This commit is contained in:
parent
3ecc259ec7
commit
d2ccee4eab
4 changed files with 129 additions and 19 deletions
|
|
@ -180,14 +180,12 @@ cli_signal_flush(clicon_handle h)
|
|||
cli_signal_block (h);
|
||||
}
|
||||
|
||||
/*! Transform data
|
||||
* Add next-last cvv (resolved variable) as body to xml bottom for leaf and
|
||||
* leaf-list.
|
||||
* There may be some translation necessary.
|
||||
/*! Create body and add last CLI variable vector as value
|
||||
* Create and add an XML body as child of XML node xbot. Set its value to the last
|
||||
* CLI variable vector element.
|
||||
*/
|
||||
static int
|
||||
dbxml_body(cxobj *xbot,
|
||||
yang_stmt *ybot,
|
||||
cvec *cvv)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -214,12 +212,14 @@ dbxml_body(cxobj *xbot,
|
|||
}
|
||||
|
||||
/*! Modify xml datastore from a callback using xml key format strings
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] cvv Vector of cli string and instantiated variables
|
||||
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
|
||||
* @param[in] op Operation to perform on database
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] cvv Vector of cli string and instantiated variables
|
||||
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
|
||||
* @param[in] op Operation to perform on database
|
||||
* @param[in] nsctx Namespace context for last value added
|
||||
* Cvv will contain first the complete cli string, and then a set of optional
|
||||
* instantiated variables.
|
||||
* If the last node is a leaf, the last cvv element is added as a value. This value
|
||||
* Example:
|
||||
* cvv[0] = "set interfaces interface eth0 type bgp"
|
||||
* cvv[1] = "eth0"
|
||||
|
|
@ -227,12 +227,16 @@ dbxml_body(cxobj *xbot,
|
|||
* argv[0] = "/interfaces/interface/%s/type"
|
||||
* op: OP_MERGE
|
||||
* @see cli_callback_generate where arg is generated
|
||||
* @note The last value may require namespace binding present in nsctx. Note that the nsctx
|
||||
* cannot normally be supplied by the clispec functions, such as cli_set, but need to be
|
||||
* generated by afunction such as clixon_instance_id_bind() or other programmatically.
|
||||
*/
|
||||
static int
|
||||
int
|
||||
cli_dbxml(clicon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv,
|
||||
enum operation_type op)
|
||||
enum operation_type op,
|
||||
cvec *nsctx)
|
||||
{
|
||||
int retval = -1;
|
||||
char *api_path_fmt; /* xml key format */
|
||||
|
|
@ -246,6 +250,7 @@ cli_dbxml(clicon_handle h,
|
|||
cxobj *xa; /* attribute */
|
||||
cxobj *xerr = NULL;
|
||||
int ret;
|
||||
cg_var *cv;
|
||||
|
||||
if (cvec_len(argv) != 1){
|
||||
clicon_err(OE_PLUGIN, 0, "Requires one element to be xml key format string");
|
||||
|
|
@ -284,10 +289,20 @@ cli_dbxml(clicon_handle h,
|
|||
goto done;
|
||||
if (xml_value_set(xa, xml_operation2str(op)) < 0)
|
||||
goto done;
|
||||
if (yang_keyword_get(y) != Y_LIST && yang_keyword_get(y) != Y_LEAF_LIST){
|
||||
if (cvec_len(cvv) > 1 &&
|
||||
dbxml_body(xbot, y, cvv) < 0)
|
||||
/* should it not be list & container?? */
|
||||
if (yang_keyword_get(y) != Y_LIST &&
|
||||
yang_keyword_get(y) != Y_LEAF_LIST &&
|
||||
cvec_len(cvv) > 1){
|
||||
if (dbxml_body(xbot, cvv) < 0)
|
||||
goto done;
|
||||
/* Loop over namespace context and add them for the value */
|
||||
cv = NULL;
|
||||
while ((cv = cvec_each(nsctx, cv)) != NULL){
|
||||
char *ns = cv_string_get(cv);
|
||||
char *pf = cv_name_get(cv);
|
||||
if (ns && pf && xmlns_set(xbot, pf, ns) < 0)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
|
|
@ -326,7 +341,7 @@ cli_set(clicon_handle h,
|
|||
{
|
||||
int retval = -1;
|
||||
|
||||
if (cli_dbxml(h, cvv, argv, OP_REPLACE) < 0)
|
||||
if (cli_dbxml(h, cvv, argv, OP_REPLACE, NULL) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -345,7 +360,7 @@ cli_merge(clicon_handle h,
|
|||
{
|
||||
int retval = -1;
|
||||
|
||||
if (cli_dbxml(h, cvv, argv, OP_MERGE) < 0)
|
||||
if (cli_dbxml(h, cvv, argv, OP_MERGE, NULL) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -364,7 +379,7 @@ cli_create(clicon_handle h,
|
|||
{
|
||||
int retval = -1;
|
||||
|
||||
if (cli_dbxml(h, cvv, argv, OP_CREATE) < 0)
|
||||
if (cli_dbxml(h, cvv, argv, OP_CREATE, NULL) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -383,7 +398,7 @@ cli_remove(clicon_handle h,
|
|||
{
|
||||
int retval = -1;
|
||||
|
||||
if (cli_dbxml(h, cvv, argv, OP_REMOVE) < 0)
|
||||
if (cli_dbxml(h, cvv, argv, OP_REMOVE, NULL) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -402,7 +417,7 @@ cli_del(clicon_handle h,
|
|||
{
|
||||
int retval = -1;
|
||||
|
||||
if (cli_dbxml(h, cvv, argv, OP_REMOVE) < 0)
|
||||
if (cli_dbxml(h, cvv, argv, OP_REMOVE, NULL) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue