summaryrefslogtreecommitdiff
path: root/python/vyos/config.py
diff options
context:
space:
mode:
authorTaniadz <tdziubenko@ukr.net>2017-10-26 14:47:33 +0300
committerTaniadz <tdziubenko@ukr.net>2017-10-26 14:47:33 +0300
commitbe772dcd50c26dceb4ac34a48401ea224a83dfbc (patch)
treec35a634d8c803c03d3f1be98c14bf33b1cc186cd /python/vyos/config.py
parent4a45d218691e69c8578dbd39f3128752868dd07d (diff)
downloadvyos-1x-be772dcd50c26dceb4ac34a48401ea224a83dfbc.tar.gz
vyos-1x-be772dcd50c26dceb4ac34a48401ea224a83dfbc.zip
T433: Add "effective" observers and inSession to the vyos.config library
Diffstat (limited to 'python/vyos/config.py')
-rw-r--r--python/vyos/config.py45
1 files changed, 45 insertions, 0 deletions
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))