summaryrefslogtreecommitdiff
path: root/src/conf_mode/igmp_proxy.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/conf_mode/igmp_proxy.py')
-rwxr-xr-xsrc/conf_mode/igmp_proxy.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/conf_mode/igmp_proxy.py b/src/conf_mode/igmp_proxy.py
index b994369af..cd0704124 100755
--- a/src/conf_mode/igmp_proxy.py
+++ b/src/conf_mode/igmp_proxy.py
@@ -20,6 +20,7 @@ import sys
import os
import jinja2
+from netifaces import interfaces
from vyos.config import Config
from vyos import ConfigError
@@ -50,17 +51,17 @@ config_tmpl = """
quickleave
{% endif -%}
-{% for i in interface %}
-# Configuration for {{ i.interface }} ({{ i.role }} interface)
-{% if i.role == 'disabled' -%}
-phyint {{ i.interface }} disabled
+{% for interface in interfaces %}
+# Configuration for {{ interface.name }} ({{ interface.role }} interface)
+{% if interface.role == 'disabled' -%}
+phyint {{ interface.name }} disabled
{%- else -%}
-phyint {{ i.interface }} {{ i.role }} ratelimit 0 threshold {{ i.threshold }}
+phyint {{ interface.name }} {{ interface.role }} ratelimit 0 threshold {{ interface.threshold }}
{%- endif -%}
-{%- for subnet in i.alt_subnet %}
+{%- for subnet in interface.alt_subnet %}
altnet {{ subnet }}
{%- endfor %}
-{%- for subnet in i.whitelist %}
+{%- for subnet in interface.whitelist %}
whitelist {{ subnet }}
{%- endfor %}
{% endfor %}
@@ -69,7 +70,7 @@ phyint {{ i.interface }} {{ i.role }} ratelimit 0 threshold {{ i.threshold }}
default_config_data = {
'disable': False,
'disable_quickleave': False,
- 'interface': [],
+ 'interfaces': [],
}
def get_config():
@@ -91,7 +92,7 @@ def get_config():
for intf in conf.list_nodes('interface'):
conf.set_level('protocols igmp-proxy interface {0}'.format(intf))
interface = {
- 'interface': intf,
+ 'name': intf,
'alt_subnet': [],
'role': 'downstream',
'threshold': '1',
@@ -111,7 +112,7 @@ def get_config():
interface['whitelist'] = conf.return_values('whitelist')
# Append interface configuration to global configuration list
- igmp_proxy['interface'].append(interface)
+ igmp_proxy['interfaces'].append(interface)
return igmp_proxy
@@ -125,12 +126,14 @@ def verify(igmp_proxy):
return None
# at least two interfaces are required, one upstream and one downstream
- if len(igmp_proxy['interface']) < 2:
+ if len(igmp_proxy['interfaces']) < 2:
raise ConfigError('Must define an upstream and at least 1 downstream interface!')
upstream = 0
- for i in igmp_proxy['interface']:
- if "upstream" == i['role']:
+ for interface in igmp_proxy['interfaces']:
+ if interface['name'] not in interfaces():
+ raise ConfigError('Interface "{}" does not exist'.format(interface['name']))
+ if "upstream" == interface['role']:
upstream += 1
if upstream == 0: