Coder Social home page Coder Social logo

lxc / python2-lxc Goto Github PK

View Code? Open in Web Editor NEW
50.0 13.0 28.0 32 KB

Python 2.7 binding for liblxc (similar to the better supported python3-lxc)

Home Page: https://linuxcontainers.org/lxc

License: GNU Lesser General Public License v2.1

C 74.72% Python 25.28%
python lxc containers

python2-lxc's Issues

set_config_item() always returns False (unicode issue)

Python 2.7.8
Debian Wheezy - 3.2.0-4-amd64

Issue

Setting a variable with set_config_item() returns False unconditionally

Explanation

https://github.com/lxc/python2-lxc/blob/master/lxc/__init__.py#L385

This issue is due to:

  • the value to be set is unicode or ascii depending on what is fed to the method
  • the new_value being returned by get_config_item() is unicode

The following branch then does not work, since in python2 isinstance(<type 'unicode'>, str) returns False, the new value is discarded and the previous value set again.

if (isinstance(value, str) and isinstance(new_value, str) and
                value == new_value): <- Path that should be taken
            return True
            [...]
        elif old_value: <- Path always taken
            set_key(key, old_value)
            return False
        else:
            self.clear_config_item(key)
            return False

Proposed fix

  • Cast the value to be set to unicode()
  • Change isinstance(value, str) to isinstance(value, unicode) in the branch

Could you please branch the project?

Right now there is only one master branch. If the code is stable enough, is it possible for you to branch it like the python3 module? The reason is that I need a stable deployment process to ping to a specific version/branch. Many thanks!

python3 support

Ansible task run with python3 interpreter fails when the lxc_container module is involved:

name 'xrange' is not defined

The complete log:

fatal: [x.x.x.x]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to x.x.x.x closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_6mkfkgb_/ansible_module_lxc_container.py\", line 1767, in <module>\r\n    main()\r\n  File \"/tmp/ansible_6mkfkgb_/ansible_module_lxc_container.py\", line 1761, in main\r\n    lxc_manage.run()\r\n  File \"/tmp/ansible_6mkfkgb_/ansible_module_lxc_container.py\", line 1641, in run\r\n    action()\r\n  File \"/tmp/ansible_6mkfkgb_/ansible_module_lxc_container.py\", line 1161, in _started\r\n    elif not self._container_startup():\r\n  File \"/tmp/ansible_6mkfkgb_/ansible_module_lxc_container.py\", line 961, in _container_startup\r\n    for _ in xrange(timeout):\r\nNameError: name 'xrange' is not defined\r\n", "msg": "MODULE FAILURE", "rc": 0}

Upload to pypi

Please, make it available on the pypi platform. As this is the official binding for python2 other projects as Ansible use it (for lxc_container module), but there's no way just to make it all work out of the box. No way to include this library as a dependency for apt or pip.
Thanks.

python2-lxc cannot be installed on MacOS

At this moment it seems impossible to install python2-lxc on MacOS because there is no brew package that would install the header files needed by the package.

The lxc package does not contain them Homebrew/brew#5326 (comment)

Another alternative would be to start bulding and publishign binary wheels.

Segfault with custom config-path on debian stretch

You can set an alternative default path in /etc/lxc/lxc.conf and it will pick that up and use it. You can specify a path for list_containers() and that works too. If you try to create a Container object then you get a segmentation fault. The value you provide for the path makes no difference (can be '/var/lib/lxc' or '/foo/bar').

I tested this as root.

The Python 3 version of this library works OK.

I could reproduce this with the debian package and installing via pip (which compiled against liblxc1 headers). Also with the package on ubuntu 18.04

Apologies for not providing a patch but Python is not my area of expertise and my guess is that this lies somewhere in the binding of the pathname to the C library.

# python
Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxc
>>> lxc.list_containers(config_path='/var/lib/lxc')
(u'elm', u'jessie-0', u'munin-test')
>>> c1=lxc.Container(name=u'elm')
>>> c2=lxc.Container(name=u'elm', config_path=u'/var/lib/lxc')
Segmentation fault

Document the dependencies

Can you please document the dependencies of this project? Guessing from the errors below, at least the Python and LXC development libraries (aka python-dev/python-devel and lxc-dev/lxc-devel) are needed.

$ pip install lxc-python2
Collecting lxc-python2
  Using cached lxc-python2-0.1.zip
Installing collected packages: lxc-python2
  Running setup.py install for lxc-python2
    Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-ivXpM7/lxc-python2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-U4pDvj-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    creating build/lib.linux-x86_64-2.7/lxc
    copying lxc/__init__.py -> build/lib.linux-x86_64-2.7/lxc
    running build_ext
    building '_lxc' extension
    creating build/temp.linux-x86_64-2.7
    gcc -pthread -fno-strict-aliasing -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC -I/usr/include/python2.7 -c lxc.c -o build/temp.linux-x86_64-2.7/lxc.o
    lxc.c:25:20: fatal error: Python.h: No such file or directory
     #include <Python.h>
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-ivXpM7/lxc-python2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-U4pDvj-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-ivXpM7/lxc-python2
$ pip install lxc-python2
Collecting lxc-python2
  Using cached lxc-python2-0.1.zip
Installing collected packages: lxc-python2
  Running setup.py install for lxc-python2
    Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-8Nfx30/lxc-python2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-l7QFQg-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    creating build/lib.linux-x86_64-2.7/lxc
    copying lxc/__init__.py -> build/lib.linux-x86_64-2.7/lxc
    running build_ext
    building '_lxc' extension
    creating build/temp.linux-x86_64-2.7
    gcc -pthread -fno-strict-aliasing -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC -I/usr/include/python2.7 -c lxc.c -o build/temp.linux-x86_64-2.7/lxc.o
    lxc.c:27:30: fatal error: lxc/lxccontainer.h: No such file or directory
     #include <lxc/lxccontainer.h>
                                  ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-8Nfx30/lxc-python2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-l7QFQg-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-8Nfx30/lxc-python2

Issue running with unprivilege containers

Hi,

I'm trying to use ansible to create lxc unprivileged containers.
It uses python2-lxc but i can't seem to find a way to pass the -t download
option for the create execution.

My example execution runs:

/usr/bin/lxc-create --name test001 --config ~/.config/lxc/default.conf --template ubuntu --bdev dir --logfile /home/rramos/lxc-test001.log --logpriority INFO -- -d ubuntu -r xenial -a amd64

but it should run:

/usr/bin/lxc-create -t download --name test001 --config ~/.config/lxc/default.conf  --logfile /home/rramos/lxc-test001.log --logpriority INFO -- -d ubuntu -r xenial -a amd64

Is there a way to indicate the create method that should run in unpriviledge mode ?

Info on setting unprivileged-containers:

Python 2.7 bindings broke with recent Ubuntu update for liblxc1

I'm afraid the Python 2.7 bindings are broken with some recent update for liblxc1 on Ubuntu. I can't give the exact date or version when this started happening, but I know the following worked a few months ago, and now it no longer does:

IPython 2.3.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import lxc

In [2]: container = lxc.Container("mycontainer")

In [3]: container.get_ips()
Segmentation fault

If I run the same thing in ipython3, using the in-tree Python 3 bindings, all is well.

Now I realize this is probably really low priority, but as it happens that this breakage blocks the inclusion of an otherwise very useful LXC connection plugin for Ansible; see ansible/ansible#13145 for details.

Ansible, for "reasons" explained here, can't run in a Python 3-only environment. Which is silly and not lxc's problem, but if we could get this module to work again in Python 2.7, that would be a huge win.

Any thoughts on the above, @stgraber? I'd much appreciate your feedback. Thanks!

LXC 1.1.3

Hi,

I use the lxc stable ppa on Ubuntu trusty. Since LXC 1.1.3 i can't create container:

The template args failed,

# ps ax | grep 17958
/bin/sh /usr/share/lxc/templates/lxc-download --path=/var/lib/lxc/ubuntu-trusty-amd64-default --name=ubuntu-trusty-amd64-default --rootfs=/var/lib/lxc/ubuntu-trusty-amd64-default/rootfs  н??L?

The source arguments is {"dist": "ubuntu", "release": "trusty", "arch": "amd64", "variant": "default"}
The final arguments is н??L?

Thanks,

Include license file

It would be nice if a license file was included in the source explicitly. It would help downstream packagers in providing this to their users ;)

Dependencies ?

Hi,

I tried to install your module via pip in order to manage lxc containers through ansible. I guessed I needed the pyhton-dev (and lxc obviously) package, but everytime I

pip install lxc-python2

I run into this error

lxc.c:27:30: fatal error: lxc/lxccontainer.h: No such file or directory

Am I missing something ?

PS : environment is a vagrant VM running debian jessie (debian/jessie64)

Ansible Extras support for LXC 2?

does this work for Ansible 2 on Xenial and LXC 2?

TASK [ansible-role-lxc : Create a started container] ***************************
fatal: [arizblah.blahblah.net]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to find required executable lxc-create"}

set_config_item always appends

Invoking set_config_item appears to always append values rather than updating a matching key.

Once can recreate this with:

import lxc, subprocess
container = lxc.Container('foo')
container.set_config_path("/tmp")
subprocess.check_call("mkdir -p /tmp/foo".split())
subprocess.check_call("touch /tmp/foo/config".split())
container.set_config_item('lxc.utsname', 'foo')
container.set_config_item('lxc.utsname', 'bar')
container.save_config()
print subprocess.check_output("cat /tmp/foo/config".split())

Expect that config contain only:

lxc.utsname = foo

Actual Output:

lxc.utsname = foo
lxc.utsname = bar

Is this project up to date?

I tried to build it, ran into following error. Please help. Thanks!

$ python setup.py build
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/lxc
copying lxc/init.py -> build/lib.linux-x86_64-2.7/lxc
running build_ext
building '_lxc' extension
creating build/temp.linux-x86_64-2.7
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c lxc.c -o build/temp.linux-x86_64-2.7/lxc.o
lxc.c:27:30: fatal error: lxc/lxccontainer.h: No such file or directory
#include <lxc/lxccontainer.h>
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.