Skip to content

Commit 98fcfcf

Browse files
committed
sonic-yang-mgmt: new public function of load_module_str_name() to prevent call into libyang by sonic-utilities
1 parent eadbc80 commit 98fcfcf

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/sonic-yang-mgmt/sonic_yang.py

+17
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,23 @@ def _find_data_nodes(self, data_xpath):
476476
def _find_schema_dependencies(self, match_path, match_ancestors: bool=False):
477477
return self.ctx.find_backlinks_paths(match_path, match_ancestors=match_ancestors)
478478

479+
"""
480+
load_module_str_name(): load a module based on the provided string and return
481+
the loaded module name. This is needed by
482+
sonic-yang-modules to prevent direct dependency on
483+
libyang.
484+
input: yang_module_str yang-formatted module
485+
returns: module name on success, exception on failure
486+
"""
487+
def load_module_str_name(yang_module_str):
488+
try:
489+
module = self.ctx.parse_module_str(yang_module_str)
490+
except Exception as e:
491+
self.fail(e);
492+
else:
493+
return module.name()
494+
495+
return None
479496

480497
"""
481498
find_data_dependencies(): find the data dependencies from data xpath (Public)

0 commit comments

Comments
 (0)