snakeoil.process.namespaces module

Support for Linux namespaces

snakeoil.process.namespaces.create_netns()[source]

Start a new net namespace

We will bring up the loopback interface, but that is all.

If functionality is not available, then it will return w/out doing anything.

snakeoil.process.namespaces.create_pidns()[source]

Start a new pid namespace

This will launch all the right manager processes. The child that returns will be isolated in a new pid namespace.

If functionality is not available, then it will return w/out doing anything.

Returns:

The last pid outside of the namespace.

snakeoil.process.namespaces.create_userns()[source]

Start a new user namespace

If functionality is not available, then it will return w/out doing anything.

snakeoil.process.namespaces.create_utsns(hostname=None)[source]

Start a new UTS namespace

If functionality is not available, then it will return w/out doing anything.

snakeoil.process.namespaces.setns(fd, nstype)[source]

Binding to the Linux setns system call. See setns(2) for details.

Parameters:
  • fd – An open file descriptor or path to one.

  • nstype – Namespace to enter; one of CLONE_*.

Raises:

OSError – if setns failed.

snakeoil.process.namespaces.simple_unshare(mount=True, uts=True, ipc=True, net=False, pid=False, user=False, hostname=None)[source]

Simpler helper for setting up namespaces quickly.

If support for any namespace type is not available, we’ll silently skip it.

Parameters:
  • mount – Create a mount namespace.

  • uts – Create a UTS namespace.

  • ipc – Create an IPC namespace.

  • net – Create a net namespace.

  • pid – Create a pid namespace.

  • user – Create a user namespace.

  • hostname – hostname to use for the UTS namespace

snakeoil.process.namespaces.unshare(flags)[source]

Binding to the Linux unshare system call. See unshare(2) for details.

Parameters:

flags – Namespaces to unshare; bitwise OR of CLONE_* flags.

Raises:

OSError – if unshare failed.