[lxc-devel] [PATCH] python3: Add support for wlan device add

Serge Hallyn serge.hallyn at ubuntu.com
Tue Feb 25 21:06:10 UTC 2014


Quoting Stéphane Graber (stgraber at ubuntu.com):
> 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 at sernet.de>
> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  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 9eb27b6..712eb48 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
>  
> -- 
> 1.9.0
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


More information about the lxc-devel mailing list