From: Stéphane Graber Date: Tue, 25 Feb 2014 20:50:44 +0000 (-0500) Subject: python3: Add support for wlan device add X-Git-Tag: lxc-1.1.0.alpha1~267 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff100440079feecd62c832d8abab88686e1b7f8c;p=thirdparty%2Flxc.git python3: Add support for wlan device add 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 --- 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