]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
python3: Add support for wlan device add
authorStéphane Graber <stgraber@ubuntu.com>
Tue, 25 Feb 2014 20:50:44 +0000 (15:50 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 25 Feb 2014 21:11:51 +0000 (16:11 -0500)
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 <gbeck@sernet.de>
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/python-lxc/lxc/__init__.py

index 9eb27b6c1a08a869839bef8a64520346c320e5a4..712eb48438d09d55a076ebafbe20e2fffd04bf96 100644 (file)
@@ -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