summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-07-25 00:39:14 +0200
committerChristian Poessinger <christian@poessinger.com>2020-07-25 17:30:12 +0200
commite70a304e36fc6456e16fea81ace4a0a5fd8bd1df (patch)
tree3959df9b7a5509b84ea92fd1fb577a8e0038d004 /python
parent72c0ac35b4acf049de29ce1ea67af28659793098 (diff)
downloadvyos-1x-e70a304e36fc6456e16fea81ace4a0a5fd8bd1df.tar.gz
vyos-1x-e70a304e36fc6456e16fea81ace4a0a5fd8bd1df.zip
ifconfig: T2653: make ifname an optional argument to get_interface_dict()
Further reduce the boiler-plate code to determine interface tag node or not. It can be passed into get_interface_dict() if explicitly required - else it is taken from the environment.
Diffstat (limited to 'python')
-rw-r--r--python/vyos/configdict.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py
index 53b5f9492..126d6195a 100644
--- a/python/vyos/configdict.py
+++ b/python/vyos/configdict.py
@@ -15,8 +15,8 @@
"""
A library for retrieving value dicts from VyOS configs in a declarative fashion.
-
"""
+import os
import jmespath
from enum import Enum
@@ -24,7 +24,6 @@ from copy import deepcopy
from vyos import ConfigError
from vyos.validate import is_member
-from vyos.util import ifname_from_config
def retrieve_config(path_hash, base_path, config):
"""
@@ -195,7 +194,7 @@ def get_removed_vlans(conf, dict):
return dict
-def get_interface_dict(config, base, ifname):
+def get_interface_dict(config, base, ifname=''):
"""
Common utility function to retrieve and mandgle the interfaces available
in CLI configuration. All interfaces have a common base ground where the
@@ -205,6 +204,12 @@ def get_interface_dict(config, base, ifname):
"""
from vyos.xml import defaults
+ if not ifname:
+ # determine tagNode instance
+ if 'VYOS_TAGNODE_VALUE' not in os.environ:
+ raise ConfigError('Interface (VYOS_TAGNODE_VALUE) not specified')
+ ifname = os.environ['VYOS_TAGNODE_VALUE']
+
# retrieve interface default values
default_values = defaults(base)