summaryrefslogtreecommitdiff
path: root/src/conf_mode/vrf.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-03-07 10:01:10 +0100
committerChristian Poessinger <christian@poessinger.com>2020-03-07 10:01:10 +0100
commitbfd90c6aef059e7513d804f99bef00fa96c4cdb7 (patch)
tree4dc21491d646ef1543de6d3207b39e421026b397 /src/conf_mode/vrf.py
parentfb12d6b97fd2ae836d9f4d363908c7721e854c14 (diff)
downloadvyos-1x-bfd90c6aef059e7513d804f99bef00fa96c4cdb7.tar.gz
vyos-1x-bfd90c6aef059e7513d804f99bef00fa96c4cdb7.zip
vrf: T31: ensure VRF can not be deleted with an attached routing protocol
Diffstat (limited to 'src/conf_mode/vrf.py')
-rwxr-xr-xsrc/conf_mode/vrf.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/conf_mode/vrf.py b/src/conf_mode/vrf.py
index cb4bbfcce..6b53d052a 100755
--- a/src/conf_mode/vrf.py
+++ b/src/conf_mode/vrf.py
@@ -61,7 +61,7 @@ def list_rules():
answer = loads(check_output(command.split()).decode())
return [_ for _ in answer if _]
-def interfaces_with_vrf(c, match):
+def vrf_interfaces(c, match):
matched = []
old_level = c.get_level()
c.set_level(['interfaces'])
@@ -78,6 +78,17 @@ def interfaces_with_vrf(c, match):
c.set_level(old_level)
return matched
+def vrf_routing(c, match):
+ matched = []
+ old_level = c.get_level()
+ c.set_level(['protocols', 'vrf'])
+ if match in c.list_nodes([]):
+ matched.append(match)
+
+ c.set_level(old_level)
+ return matched
+
+
def get_config():
conf = Config()
vrf_config = deepcopy(default_config_data)
@@ -124,9 +135,6 @@ def get_config():
if conf.exists(['description']):
vrf_inst['description'] = conf.return_value(['description'])
- # find member interfaces of this particulat VRF
- vrf_inst['members'] = interfaces_with_vrf(conf, name)
-
# append individual VRF configuration to global configuration list
vrf_config['vrf_add'].append(vrf_inst)
@@ -138,12 +146,16 @@ def get_config():
tmp = []
for name in vrf_config['vrf_remove']:
vrf_inst = {
- 'members': [],
- 'name' : name,
+ 'interfaces': [],
+ 'name': name,
+ 'routes': []
}
# find member interfaces of this particulat VRF
- vrf_inst['members'] = interfaces_with_vrf(conf, name)
+ vrf_inst['interfaces'] = vrf_interfaces(conf, name)
+
+ # find routing protocols used by this VRF
+ vrf_inst['routes'] = vrf_routing(conf, name)
# append individual VRF configuration to temporary configuration list
tmp.append(vrf_inst)
@@ -156,9 +168,12 @@ def get_config():
def verify(vrf_config):
# ensure VRF is not assigned to any interface
for vrf in vrf_config['vrf_remove']:
- if len(vrf['members']) > 0:
+ if len(vrf['interfaces']) > 0:
raise ConfigError('VRF {} can not be deleted. It has active member interfaces!'.format(vrf['name']))
+ if len(vrf['routes']) > 0:
+ raise ConfigError('VRF {} can not be deleted. It has routing protocols attached!'.format(vrf['name']))
+
table_ids = []
for vrf in vrf_config['vrf_add']:
# table id is mandatory