diff options
author | Daniil Baturin <daniil@baturin.org> | 2017-10-26 19:08:39 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-26 19:08:39 +0700 |
commit | 3939aedea2cf488eb4639c4ca69756997aed6a7c (patch) | |
tree | c35a634d8c803c03d3f1be98c14bf33b1cc186cd | |
parent | bb898d7b058514b84755f05ca5d694b145d87253 (diff) | |
parent | be772dcd50c26dceb4ac34a48401ea224a83dfbc (diff) | |
download | vyos-1x-3939aedea2cf488eb4639c4ca69756997aed6a7c.tar.gz vyos-1x-3939aedea2cf488eb4639c4ca69756997aed6a7c.zip |
Merge pull request #6 from Taniadz/current
T433: Add "effective" observers and inSession to the vyos.config library
-rw-r--r-- | python/vyos/config.py | 45 |
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)) |