From 502448171a62aa809c07d19a3999df885a65f715 Mon Sep 17 00:00:00 2001
From: Viacheslav <v.gletenko@vyos.io>
Date: Tue, 23 Nov 2021 18:03:23 +0000
Subject: netns: T3829: Add netns set section in interface.py

---
 python/vyos/ifconfig/interface.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

(limited to 'python')

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'
-- 
cgit v1.2.3