diff options
author | Daniil Baturin <daniil@vyos.io> | 2024-08-14 17:26:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-14 17:26:05 +0100 |
commit | e0ce3f0e5a979e678d20a77f37fb6626806c28a5 (patch) | |
tree | ce3750b4f2cd9a269b1d7be6a8b55dd5119f4286 /python/vyos/xml_ref/__init__.py | |
parent | e229d7498cc77298c79af9811a742f3ad54edf4c (diff) | |
parent | 832056ad5171b28c50270389c4537f6c7a542d59 (diff) | |
download | vyos-1x-e0ce3f0e5a979e678d20a77f37fb6626806c28a5.tar.gz vyos-1x-e0ce3f0e5a979e678d20a77f37fb6626806c28a5.zip |
Merge pull request #3971 from jestabro/op-mode-cache
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) |