diff options
author | Christian Breunig <christian@breunig.cc> | 2023-09-03 13:23:27 +0200 |
---|---|---|
committer | Christian Breunig <christian@breunig.cc> | 2023-09-03 14:32:10 +0200 |
commit | 6ef163baa783c4bbda06493347b845529ae6b3e4 (patch) | |
tree | 6a47d4fa27872ee56595203ce129d2f1493b7b16 /python/vyos/ifconfig/control.py | |
parent | 1ae9c4162dc13844ec0f028a51b4b2d111954196 (diff) | |
parent | e9c9d1a1e4f1bf876892b6e58f7288d36180889f (diff) | |
download | vyos-1x-6ef163baa783c4bbda06493347b845529ae6b3e4.tar.gz vyos-1x-6ef163baa783c4bbda06493347b845529ae6b3e4.zip |
Merge branch 'T5241-control-edition' of https://github.com/sever-sever/vyos-1x into netns
* 'T5241-control-edition' of https://github.com/sever-sever/vyos-1x:
T5241: Support netns for veth and dummy interfaces
Diffstat (limited to 'python/vyos/ifconfig/control.py')
-rw-r--r-- | python/vyos/ifconfig/control.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/python/vyos/ifconfig/control.py b/python/vyos/ifconfig/control.py index c8366cb58..7402da55a 100644 --- a/python/vyos/ifconfig/control.py +++ b/python/vyos/ifconfig/control.py @@ -1,4 +1,4 @@ -# Copyright 2019-2021 VyOS maintainers and contributors <maintainers@vyos.io> +# Copyright 2019-2023 VyOS maintainers and contributors <maintainers@vyos.io> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -49,6 +49,18 @@ class Control(Section): return popen(command, self.debug) def _cmd(self, command): + import re + if 'netns' in self.config: + # This command must be executed from default netns 'ip link set dev X netns X' + # exclude set netns cmd from netns to avoid: + # failed to run command: ip netns exec ns01 ip link set dev veth20 netns ns01 + pattern = r'ip link set dev (\S+) netns (\S+)' + matches = re.search(pattern, command) + if matches and matches.group(2) == self.config['netns']: + # Command already includes netns and matches desired namespace: + command = command + else: + command = f'ip netns exec {self.config["netns"]} {command}' return cmd(command, self.debug) def _get_command(self, config, name): |