From be772dcd50c26dceb4ac34a48401ea224a83dfbc Mon Sep 17 00:00:00 2001 From: Taniadz Date: Thu, 26 Oct 2017 14:47:33 +0300 Subject: T433: Add "effective" observers and inSession to the vyos.config library --- python/vyos/config.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'python/vyos') diff --git a/python/vyos/config.py b/python/vyos/config.py index edee6b33e..6160d9a6b 100644 --- a/python/vyos/config.py +++ b/python/vyos/config.py @@ -132,3 +132,48 @@ class Config(object): return(default) else: raise VyOSError("Cannot use list_nodes on a non-tag node: {0}".format(full_path)) + + def exists_effective(self, path): + try: + self._run(self._make_command('existsEffective', self._level + path)) + return True + except VyOSError: + return False + + def return_effective_value(self, path, default=None): + full_path = self._level + path + if self.is_multi(path): + raise VyOSError("Cannot use return_effective_value on multi node: {0}".format(full_path)) + elif not self.is_leaf(path): + raise VyOSError("Cannot use return_effective_value on non-leaf node: {0}".format(full_path)) + else: + try: + out = self._run(self._make_command('returnEffectiveValue', full_path)) + return out + except VyOSError: + return(default) + + def return_effective_values(self, path, default=[]): + full_path = self._level + path + if not self.is_multi(path): + raise VyOSError("Cannot use return_effective_values on non-multi node: {0}".format(full_path)) + elif not self.is_leaf(path): + raise VyOSError("Cannot use return_effective_values on non-leaf node: {0}".format(full_path)) + else: + try: + out = self._run(self._make_command('returnEffectiveValues', full_path)) + return out + except VyOSError: + return(default) + + def list_effective_nodes(self, path, default=[]): + full_path = self._level + path + if self.is_tag(path): + try: + out = self._run(self._make_command('listEffectiveNodes', full_path)) + values = out.split() + return list(map(lambda x: re.sub(r'^\'(.*)\'$', r'\1',x), values)) + except VyOSError: + return(default) + else: + raise VyOSError("Cannot use list_effective_nodes on a non-tag node: {0}".format(full_path)) -- cgit v1.2.3