From 1d8f1f2a8a286aedefbf40451c6fcfd78bd5f723 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Tue, 3 Aug 2021 10:30:26 -0500 Subject: configquery: T3402: add class using configtree to list tag node values The class ConfigTreeActiveQuery uses configtree to access tag node values; note that this will only report saved configuration data. --- python/vyos/configquery.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'python/vyos/configquery.py') diff --git a/python/vyos/configquery.py b/python/vyos/configquery.py index ed7346f1f..0f0bc2f79 100644 --- a/python/vyos/configquery.py +++ b/python/vyos/configquery.py @@ -20,7 +20,7 @@ settings from op mode, and execution of arbitrary op mode commands. from subprocess import STDOUT from vyos.util import popen - +from vyos.configtree import ConfigTree class ConfigQueryError(Exception): pass @@ -70,6 +70,26 @@ class CliShellApiConfigQuery(GenericConfigQuery): raise ConfigQueryError('No values for given path') return out +class ConfigTreeActiveQuery(GenericConfigQuery): + def __init__(self): + super().__init__() + + with open('/config/config.boot') as f: + config_file = f.read() + self.configtree = ConfigTree(config_file) + + def exists(self, path: list): + return self.configtree.exists(path) + + def value(self, path: list): + return self.configtree.return_value(path) + + def values(self, path: list): + return self.configtree.return_values(path) + + def list_nodes(self, path: list): + return self.configtree.list_nodes(path) + class VbashOpRun(GenericOpRun): def __init__(self): super().__init__() -- cgit v1.2.3