diff options
author | John Estabrook <jestabro@vyos.io> | 2024-08-04 21:19:32 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2024-08-12 07:58:05 -0500 |
commit | 832056ad5171b28c50270389c4537f6c7a542d59 (patch) | |
tree | aa511514a25ccffbfab61a22543ecf8bbe559eee /python/vyos/xml_ref/__init__.py | |
parent | ba0f8dbdb2766a67b6715291ac08ad0eb1cf62b7 (diff) | |
download | vyos-1x-832056ad5171b28c50270389c4537f6c7a542d59.tar.gz vyos-1x-832056ad5171b28c50270389c4537f6c7a542d59.zip |
xml: T6650: add initial op-mode cache support
Diffstat (limited to 'python/vyos/xml_ref/__init__.py')
-rw-r--r-- | python/vyos/xml_ref/__init__.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/python/vyos/xml_ref/__init__.py b/python/vyos/xml_ref/__init__.py index 2ba3da4e8..91ce394f7 100644 --- a/python/vyos/xml_ref/__init__.py +++ b/python/vyos/xml_ref/__init__.py @@ -15,6 +15,7 @@ from typing import Optional, Union, TYPE_CHECKING from vyos.xml_ref import definition +from vyos.xml_ref import op_definition if TYPE_CHECKING: from vyos.config import ConfigDict @@ -87,3 +88,25 @@ def from_source(d: dict, path: list) -> bool: def ext_dict_merge(source: dict, destination: Union[dict, 'ConfigDict']): return definition.ext_dict_merge(source, destination) + +def load_op_reference(op_cache=[]): + if op_cache: + return op_cache[0] + + op_xml = op_definition.OpXml() + + try: + from vyos.xml_ref.op_cache import op_reference + except Exception: + raise ImportError('no xml op reference cache !!') + + if not op_reference: + raise ValueError('empty xml op reference cache !!') + + op_xml.define(op_reference) + op_cache.append(op_xml) + + return op_xml + +def get_op_ref_path(path: list) -> list[op_definition.PathData]: + return load_op_reference()._get_op_ref_path(path) |