forked from Mirror/frr
lib: Add support to load submodules in embedded modules framework
BGP Yang is using sub modules and at present FRR is not processing submodules in embedded framework yang Signed-off-by: VishalDhingra <vdhingra@vmware.com>
This commit is contained in:
parent
5677e93f8f
commit
65de8bc8d0
28
lib/yang.c
28
lib/yang.c
|
@ -53,22 +53,30 @@ static const char *yang_module_imp_clb(const char *mod_name,
|
||||||
{
|
{
|
||||||
struct yang_module_embed *e;
|
struct yang_module_embed *e;
|
||||||
|
|
||||||
if (submod_name || submod_rev)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
for (e = embeds; e; e = e->next) {
|
for (e = embeds; e; e = e->next) {
|
||||||
if (strcmp(e->mod_name, mod_name))
|
if (e->sub_mod_name && submod_name) {
|
||||||
continue;
|
if (strcmp(e->sub_mod_name, submod_name))
|
||||||
if (mod_rev && strcmp(e->mod_rev, mod_rev))
|
continue;
|
||||||
continue;
|
|
||||||
|
if (submod_rev && strcmp(e->sub_mod_rev, submod_rev))
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
if (strcmp(e->mod_name, mod_name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (mod_rev && strcmp(e->mod_rev, mod_rev))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
*format = e->format;
|
*format = e->format;
|
||||||
return e->data;
|
return e->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
flog_warn(EC_LIB_YANG_MODULE_LOAD,
|
flog_warn(
|
||||||
"YANG model \"%s@%s\" not embedded, trying external file",
|
EC_LIB_YANG_MODULE_LOAD,
|
||||||
mod_name, mod_rev ? mod_rev : "*");
|
"YANG model \"%s@%s\" \"%s@%s\"not embedded, trying external file",
|
||||||
|
mod_name, mod_rev ? mod_rev : "*",
|
||||||
|
submod_name ? submod_name : "*", submod_rev ? submod_rev : "*");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,8 @@ extern "C" {
|
||||||
struct yang_module_embed {
|
struct yang_module_embed {
|
||||||
struct yang_module_embed *next;
|
struct yang_module_embed *next;
|
||||||
const char *mod_name, *mod_rev;
|
const char *mod_name, *mod_rev;
|
||||||
|
const char *sub_mod_name;
|
||||||
|
const char *sub_mod_rev;
|
||||||
const char *data;
|
const char *data;
|
||||||
LYS_INFORMAT format;
|
LYS_INFORMAT format;
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,6 +20,8 @@ if not os.path.isdir(outdir):
|
||||||
# to make it even harder.
|
# to make it even harder.
|
||||||
|
|
||||||
re_name = re.compile(r'\bmodule\s+([^\s]+)\s+\{')
|
re_name = re.compile(r'\bmodule\s+([^\s]+)\s+\{')
|
||||||
|
re_subname = re.compile(r'\bsubmodule\s+([^\s]+)\s+\{')
|
||||||
|
re_mainname = re.compile(r'\bbelongs-to\s+([^\s]+)\s+\{')
|
||||||
re_rev = re.compile(r'\brevision\s+([\d-]+)\s+\{')
|
re_rev = re.compile(r'\brevision\s+([\d-]+)\s+\{')
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,6 +36,8 @@ static const char model[] =
|
||||||
static struct yang_module_embed embed = {
|
static struct yang_module_embed embed = {
|
||||||
\t.mod_name = "%s",
|
\t.mod_name = "%s",
|
||||||
\t.mod_rev = "%s",
|
\t.mod_rev = "%s",
|
||||||
|
\t.sub_mod_name = "%s",
|
||||||
|
\t.sub_mod_rev = "%s",
|
||||||
\t.data = model,
|
\t.data = model,
|
||||||
\t.format = %s,
|
\t.format = %s,
|
||||||
};
|
};
|
||||||
|
@ -62,6 +66,10 @@ def escape(line):
|
||||||
with open(inname, 'r') as fd:
|
with open(inname, 'r') as fd:
|
||||||
data = fd.read()
|
data = fd.read()
|
||||||
|
|
||||||
|
sub_name = ""
|
||||||
|
rev = ""
|
||||||
|
sub_rev = ""
|
||||||
|
|
||||||
# XML support isn't actively used currently, but it's here in case the need
|
# XML support isn't actively used currently, but it's here in case the need
|
||||||
# arises. It does avoid the regex'ing.
|
# arises. It does avoid the regex'ing.
|
||||||
if '<?xml' in data:
|
if '<?xml' in data:
|
||||||
|
@ -71,8 +79,15 @@ if '<?xml' in data:
|
||||||
rev = xml.find('{urn:ietf:params:xml:ns:yang:yin:1}revision').get('date')
|
rev = xml.find('{urn:ietf:params:xml:ns:yang:yin:1}revision').get('date')
|
||||||
fmt = 'LYS_YIN'
|
fmt = 'LYS_YIN'
|
||||||
else:
|
else:
|
||||||
name = re_name.search(data).group(1)
|
search_name = re_name.search(data)
|
||||||
rev = re_rev.search(data).group(1)
|
if search_name :
|
||||||
|
name = search_name.group(1)
|
||||||
|
rev = re_rev.search(data).group(1)
|
||||||
|
else :
|
||||||
|
search_name = re_subname.search(data)
|
||||||
|
sub_name = search_name.group(1)
|
||||||
|
name = re_mainname.search(data).group(1)
|
||||||
|
sub_rev = re_rev.search(data).group(1)
|
||||||
fmt = 'LYS_YANG'
|
fmt = 'LYS_YANG'
|
||||||
|
|
||||||
if name is None or rev is None:
|
if name is None or rev is None:
|
||||||
|
@ -82,4 +97,4 @@ lines = [escape(row) for row in data.split('\n')]
|
||||||
text = '\\n"\n\t"'.join(lines)
|
text = '\\n"\n\t"'.join(lines)
|
||||||
|
|
||||||
with open(outname, 'w') as fd:
|
with open(outname, 'w') as fd:
|
||||||
fd.write(template % (text, escape(name), escape(rev), fmt))
|
fd.write(template % (text, escape(name), escape(rev), escape(sub_name), escape(sub_rev), fmt))
|
||||||
|
|
Loading…
Reference in a new issue