summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorViacheslav <v.gletenko@vyos.io>2021-11-23 18:03:23 +0000
committerViacheslav <v.gletenko@vyos.io>2021-11-23 18:03:23 +0000
commit502448171a62aa809c07d19a3999df885a65f715 (patch)
treecf34d5003e1b1767ce67930c51f29d037f0966df /python
parent3d413c06621c3c299972380391285b456919deb5 (diff)
downloadvyos-1x-502448171a62aa809c07d19a3999df885a65f715.tar.gz
vyos-1x-502448171a62aa809c07d19a3999df885a65f715.zip
netns: T3829: Add netns set section in interface.py
Diffstat (limited to 'python')
-rwxr-xr-xpython/vyos/ifconfig/interface.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index 58d130ef6..50da2553a 100755
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -135,6 +135,9 @@ class Interface(Control):
'validate': assert_mtu,
'shellcmd': 'ip link set dev {ifname} mtu {value}',
},
+ 'netns': {
+ 'shellcmd': 'ip link set dev {ifname} netns {value}',
+ },
'vrf': {
'convert': lambda v: f'master {v}' if v else 'nomaster',
'shellcmd': 'ip link set dev {ifname} {value}',
@@ -512,6 +515,21 @@ class Interface(Control):
if prev_state == 'up':
self.set_admin_state('up')
+ def set_netns(self, netns):
+ """
+ Add/Remove interface from given NETNS.
+
+ Example:
+ >>> from vyos.ifconfig import Interface
+ >>> Interface('dum0').set_netns('foo')
+ """
+
+ #tmp = self.get_interface('netns')
+ #if tmp == netns:
+ # return None
+
+ self.set_interface('netns', netns)
+
def set_vrf(self, vrf):
"""
Add/Remove interface from given VRF instance.
@@ -1405,6 +1423,13 @@ class Interface(Control):
# checked before
self.set_vrf(config.get('vrf', ''))
+ # If interface attached to NETNS we shouldn't check all other settings
+ # As interface placed to separate logical stack
+ # Configure NETNS
+ if dict_search('netns', config) != None:
+ self.set_netns(config.get('netns', ''))
+ return
+
# Configure MSS value for IPv4 TCP connections
tmp = dict_search('ip.adjust_mss', config)
value = tmp if (tmp != None) else '0'