Skip to main content

Create process in linux namespaces

Project description

Works with Linux namespaces througth glibc with pure python

Goals

There is so many beautiful tools like docker, rocket and vagga written on go and rust, but no one on python. I think that is because there is no easy way to works wit linux namespaces on python:

  • you can use asylum - project that looks like dead and with codebase hosted not on mainstream hub like github

  • or you can use python-libvirt bindings with big layer of abstraction

  • or just use native glibc library with ctypes

  • otherwise subprocess.Popen your choice

I want to change it: i want to create native python bindings to glibc with interface of python multiprocessing.Process.

Example

First simple example

from pyspaces import Container


def execute(argv):
    os.execvp(argv[0], argv)

cmd = "mount -t proc proc /proc; ps ax"
c = Container(target=execute, args=(('bash', '-c', cmd),),
              uid_map='0 1000 1',
              newpid=True, newuser=True, newns=True
              )
c.start()
print("PID of child created by clone() is %ld\n" % c.pid)
c.join()
print("Child returned: pid %s, status %s" % (c.pid, c.exitcode))
PID of child created by clone() is 15978

PID TTY      STAT   TIME COMMAND
1   pts/19   S+     0:00 bash -c mount -t proc proc /proc; ps ax
3   pts/19   R+     0:00 ps ax

Child returned: pid 15978, status 0

CLI

space -v execute --pid --fs --user --uid '0 1000 1' bash

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyspaces-1.1.2.tar.gz (6.3 kB view details)

Uploaded Source

File details

Details for the file pyspaces-1.1.2.tar.gz.

File metadata

  • Download URL: pyspaces-1.1.2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyspaces-1.1.2.tar.gz
Algorithm Hash digest
SHA256 74425fb148c22cfe4e7a90d06ed144212d7596be659a1f8fc30da7b9b2c9ce51
MD5 d59c7aee3ed330ff7e3c3ea925369b07
BLAKE2b-256 339f7ed121aec6cd62fca23d9a08c967e9b76b8823abc8d8f61a20e157189baa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page