From ff100440079feecd62c832d8abab88686e1b7f8c Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Graber?= Date: Tue, 25 Feb 2014 15:50:44 -0500 Subject: [PATCH] python3: Add support for wlan device add MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit With this change it's now possible to add wlan devices to the container. This will track down the right phy device, move it to the right namespace (we don't care about its name), then if the user asked for a new device name for the actual interface, we attach to the container and rename the interface in there using attach. I have tested this to work with both Intel and Atheros NICs. This patch is based on the one provided to lxc-devel by Gregor Beck and has then been updated to do the device renaming as well as minor code style changes. Thanks! Reported-by: Gregor Beck Signed-off-by: Stéphane Graber Acked-by: Serge E. Hallyn --- src/python-lxc/lxc/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/python-lxc/lxc/__init__.py b/src/python-lxc/lxc/__init__.py index 9eb27b6c1..712eb4843 100644 --- a/src/python-lxc/lxc/__init__.py +++ b/src/python-lxc/lxc/__init__.py @@ -160,6 +160,26 @@ class Container(_lxc.Container): if not self.running: return False + if os.path.exists("/sys/class/net/%s/phy80211/name" % name): + with open("/sys/class/net/%s/phy80211/name" % name) as fd: + phy = fd.read().strip() + + if subprocess.call(['iw', 'phy', phy, 'set', 'netns', + str(self.init_pid)]) != 0: + return False + + if destname: + def rename_interface(args): + old, new = args + + return subprocess.call(['ip', 'link', 'set', + 'dev', old, 'name', new]) + + return self.attach_wait(rename_interface, (name, destname), + namespaces=(CLONE_NEWNET)) == 0 + + return True + if not destname: destname = name -- 2.47.2