summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig
diff options
context:
space:
mode:
Diffstat (limited to 'python/vyos/ifconfig')
-rw-r--r--python/vyos/ifconfig/ethernet.py5
-rw-r--r--python/vyos/ifconfig/geneve.py2
-rw-r--r--python/vyos/ifconfig/interface.py32
-rw-r--r--python/vyos/ifconfig/tunnel.py16
-rw-r--r--python/vyos/ifconfig/vrrp.py2
5 files changed, 29 insertions, 28 deletions
diff --git a/python/vyos/ifconfig/ethernet.py b/python/vyos/ifconfig/ethernet.py
index 542de4f59..5b18926c9 100644
--- a/python/vyos/ifconfig/ethernet.py
+++ b/python/vyos/ifconfig/ethernet.py
@@ -40,6 +40,7 @@ class EthernetIf(Interface):
'bondable': True,
'broadcast': True,
'bridgeable': True,
+ 'eternal': '(lan|eth|eno|ens|enp|enx)[0-9]+$',
}
}
@@ -76,10 +77,6 @@ class EthernetIf(Interface):
},
}}
- def _delete(self):
- # Ethernet interfaces can not be removed
- pass
-
def get_driver_name(self):
"""
Return the driver name used by NIC. Some NICs don't support all
diff --git a/python/vyos/ifconfig/geneve.py b/python/vyos/ifconfig/geneve.py
index 0c1cdade9..145dc268c 100644
--- a/python/vyos/ifconfig/geneve.py
+++ b/python/vyos/ifconfig/geneve.py
@@ -35,6 +35,8 @@ class GeneveIf(Interface):
'vni': 0,
'remote': '',
}
+ options = Interface.options + \
+ ['vni', 'remote']
definition = {
**Interface.definition,
**{
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index 5b26f8bab..62c30dbf7 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -14,6 +14,7 @@
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
import os
+import re
import json
from copy import deepcopy
@@ -63,6 +64,7 @@ class Interface(Control):
'bondable': False,
'broadcast': False,
'bridgeable': False,
+ 'eternal': '',
}
_command_get = {
@@ -249,28 +251,14 @@ class Interface(Control):
self.del_addr(addr)
# ---------------------------------------------------------------------
- # A code refactoring is required as this type check is present as
- # Interface implement behaviour for one of it's sub-class.
-
- # It is required as the current pattern for vlan is:
- # Interface('name').remove() to delete an interface
- # The code should be modified to have a class method called connect and
- # have Interface.connect('name').remove()
-
- # each subclass should register within Interface the pattern for that
- # interface ie: (ethX, etc.) and use this to create an instance of
- # the right class (EthernetIf, ...)
-
- # Ethernet interfaces can not be removed
-
- # Commented out as nowhere in the code do we call Interface()
- # This would also cause an import loop
- # if self.__class__ == EthernetIf:
- # return
-
- # ---------------------------------------------------------------------
-
- self._delete()
+ # Any class can define an eternal regex in its definition
+ # interface matching the regex will not be deleted
+
+ eternal = self.definition['eternal']
+ if not eternal:
+ self._delete()
+ elif not re.match(eternal, self.ifname):
+ self._delete()
def _delete(self):
# NOTE (Improvement):
diff --git a/python/vyos/ifconfig/tunnel.py b/python/vyos/ifconfig/tunnel.py
index 690b61366..85c22b5b4 100644
--- a/python/vyos/ifconfig/tunnel.py
+++ b/python/vyos/ifconfig/tunnel.py
@@ -43,7 +43,7 @@ class _Tunnel(Interface):
**{
'section': 'tunnel',
'prefixes': ['tun',],
- 'bridgeable': True,
+ 'bridgeable': False,
},
}
@@ -135,6 +135,13 @@ class GREIf(_Tunnel):
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/ip/link_gre.c
"""
+ definition = {
+ **_Tunnel.definition,
+ **{
+ 'bridgeable': True,
+ },
+ }
+
ip = [IP4, IP6]
tunnel = IP4
@@ -160,6 +167,13 @@ class GRETapIf(_Tunnel):
# no multicast, ttl or tos for gretap
+ definition = {
+ **_Tunnel.definition,
+ **{
+ 'bridgeable': True,
+ },
+ }
+
ip = [IP4, ]
tunnel = IP4
diff --git a/python/vyos/ifconfig/vrrp.py b/python/vyos/ifconfig/vrrp.py
index 29b10dd9e..a872725b2 100644
--- a/python/vyos/ifconfig/vrrp.py
+++ b/python/vyos/ifconfig/vrrp.py
@@ -109,7 +109,7 @@ class VRRP(object):
return []
disabled = []
- config = json.loads(util.readfile(cls.location['vyos']))
+ config = json.loads(util.read_file(cls.location['vyos']))
# add disabled groups to the list
for group in config['vrrp_groups']: