Implementation of OpenConfig path compression.

This commit is contained in:
Kristofer Hallin 2021-10-15 13:55:31 +02:00
parent 2f56357adb
commit 4ac1f0bad0
No known key found for this signature in database
GPG key ID: 5A2B21943DE5C500
6 changed files with 20 additions and 7 deletions

View file

@ -353,7 +353,7 @@ cli_xml2cli(cxobj *xn,
yang_keyword_get(ys) == Y_LEAF_LIST){
if (prepend)
(*fn)(stdout, "%s", prepend);
if (gt == GT_ALL || gt == GT_VARS || gt == GT_HIDE)
if (gt == GT_ALL || gt == GT_VARS || gt == GT_HIDE || gt == GT_OC_COMPRESS)
(*fn)(stdout, "%s ", xml_name(xn));
if ((body = xml_body(xn)) != NULL){
if (index(body, ' '))

View file

@ -763,7 +763,7 @@ yang2cli_leaf(clicon_handle h,
/* Look for autocli-op defined in clixon-lib.yang */
if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, &opext) < 0)
goto done;
if (gt == GT_VARS|| gt == GT_ALL || gt == GT_HIDE){
if (gt == GT_VARS || gt == GT_ALL || gt == GT_HIDE || gt == GT_OC_COMPRESS){
cprintf(cb, "%s", yang_argument_get(ys));
yang2cli_helptext(cb, helptext);
cprintf(cb, " ");
@ -832,13 +832,24 @@ yang2cli_container(clicon_handle h,
char *helptext = NULL;
char *s;
int hide = 0;
int hide_oc = 0;
char *opext = NULL;
yang_stmt *ymod = NULL;
char **name;
if (ys_real_module(ys, &ymod) < 0)
goto done;
if (yang_extension_value(ymod, "openconfig-extensions", "http://openconfig.net/yang/openconfig-ext", &opext) == 0) {
if (strcmp(yang_argument_get(ys), "config") == 0){
hide_oc = 1;
}
}
/* If non-presence container && HIDE mode && only child is
* a list, then skip container keyword
* See also xml2cli
*/
if ((hide = yang_container_cli_hide(ys, gt)) == 0){
if ((hide = yang_container_cli_hide(ys, gt)) == 0 && hide_oc == 0){
cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
if ((helptext = strdup(yang_argument_get(yd))) == NULL){
@ -868,7 +879,7 @@ yang2cli_container(clicon_handle h,
while ((yc = yn_each(ys, yc)) != NULL)
if (yang2cli_stmt(h, yc, gt, level+1, state, show_tree, cb) < 0)
goto done;
if (hide == 0)
if (hide == 0 && hide_oc == 0)
cprintf(cb, "%*s}\n", level*3, "");
retval = 0;
done:
@ -955,7 +966,7 @@ yang2cli_list(clicon_handle h,
cprintf(cb, "{\n");
}
if (yang2cli_leaf(h, yleaf,
(gt==GT_VARS||gt==GT_HIDE)?GT_NONE:gt, level+1,
(gt==GT_VARS||gt==GT_HIDE||gt==GT_OC_COMPRESS)?GT_NONE:gt, level+1,
last_key, show_tree, 1,
cb) < 0)
goto done;

View file

@ -77,6 +77,7 @@ enum genmodel_type{
GT_VARS, /* Keywords on non-key variables */
GT_ALL, /* Keywords on all variables */
GT_HIDE, /* Keywords on all variables and hide container around lists */
GT_OC_COMPRESS, /* OpenConfig */
};
typedef enum genmodel_type genmodel_type;

View file

@ -89,6 +89,7 @@ static const map_str2int cli_genmodel_map[] = {
{"VARS", GT_VARS},
{"ALL", GT_ALL},
{"HIDE", GT_HIDE},
{"OC_COMPRESS", GT_OC_COMPRESS},
{NULL, -1}
};

View file

@ -286,7 +286,7 @@ xml2cli_recurse(FILE *f,
/* If presence container, then print as leaf (but continue to children) */
if (prepend)
(*fn)(f, "%s", prepend);
if (gt == GT_ALL || gt == GT_VARS || gt == GT_HIDE)
if (gt == GT_ALL || gt == GT_VARS || gt == GT_HIDE || gt == GT_OC_COMPRESS)
(*fn)(f, "%s ", xml_name(x));
if ((body = xml_body(x)) != NULL){
if (index(body, ' '))

View file

@ -3255,7 +3255,7 @@ yang_container_cli_hide(yang_stmt *ys,
keyw = yang_keyword_get(ys);
/* HIDE mode */
if (gt != GT_HIDE)
if (gt != GT_HIDE && gt != GT_OC_COMPRESS)
return 0;
/* A container */
if (yang_keyword_get(ys) != Y_CONTAINER)