summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-01-22 16:31:20 +0100
committerChristian Poessinger <christian@poessinger.com>2021-01-22 19:37:26 +0100
commit0ddd684ff12b297313331a1c87f36d8308eade8d (patch)
treeba6f2b896bde676a86dc3bfb4b43bee9d43af4b5 /src
parented482498b0baffe0d0c6aecefebb806f09c1f0a7 (diff)
downloadvyos-1x-0ddd684ff12b297313331a1c87f36d8308eade8d.tar.gz
vyos-1x-0ddd684ff12b297313331a1c87f36d8308eade8d.zip
ospf: T3236: add default values
Diffstat (limited to 'src')
-rwxr-xr-x[-rw-r--r--]src/conf_mode/protocols_ospf.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/conf_mode/protocols_ospf.py b/src/conf_mode/protocols_ospf.py
index 73c244571..fc66a884c 100644..100755
--- a/src/conf_mode/protocols_ospf.py
+++ b/src/conf_mode/protocols_ospf.py
@@ -24,6 +24,7 @@ from vyos.template import render
from vyos.template import render_to_string
from vyos.util import call
from vyos.util import dict_search
+from vyos.xml import defaults
from vyos import ConfigError
from vyos import frr
from vyos import airbag
@@ -43,6 +44,30 @@ def get_config():
conf = Config()
base = ['protocols', 'ospf']
ospf = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True)
+
+ # Bail out early if configuration tree does not exist
+ if not conf.exists(base):
+ return ospf
+
+ # We have gathered the dict representation of the CLI, but there are default
+ # options which we need to update into the dictionary retrived.
+ default_values = defaults(base)
+
+ # We have to cleanup the default dict, as default values could enable features
+ # which are not explicitly enabled on the CLI. Example: default-information
+ # originate comes with a default metric-type of 2, which will enable the
+ # entire default-information originate tree, even when not set via CLI so we
+ # need to check this first and probably drop that key.
+ if dict_search('default_information.originate', ospf) is None:
+ del default_values['default_information']
+ if dict_search('area.area_type.nssa', ospf) is None:
+ del default_values['area']['area_type']['nssa']
+ for protocol in ['bgp', 'connected', 'kernel', 'rip', 'static']:
+ if dict_search(f'redistribute.{protocol}', ospf) is None:
+ del default_values['redistribute'][protocol]
+
+ ospf = dict_merge(default_values, ospf)
+
return ospf
def verify(ospf):