I have got a weird problem and I wonder whether others have the same…
I am trying to use the Python package python3-lxc
but it does not appear to connect to the LXC API.
I start a container and verify that it is running.
$ lxc list -c s mycontainer
+---------+
| STATE |
+---------+
| RUNNING |
+---------+
or
$ lxc info mycontainer
Name: mycontainer
Remote: unix://
Architecture: x86_64
Created: 2018/01/21 13:01 UTC
Status: Running
Type: persistent
Profiles: default
.
... more stuff
Then I use below sample code
# file name: lxctest.py
#!/usr/bin/python3
import lxc
import sys
c = lxc.Container("mycontainer")
if c.defined:
print("Container already exists", file=sys.stderr)
sys.exit(1)
else:
print("The container is NOT defined")
When I run it, I get The container is NOT defined whereas I should get Container already exists as response.
$ ./lxctest.py
The container is NOT defined
System details
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 17.10
Release: 17.10
Codename: artful
$ uname -a
Linux machinename 4.13.0-25-generic #29-Ubuntu SMP Mon Jan 8 21:14:41 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Used Snap to install LXD
sudo apt remove --purge lxd lxd-client
sudo groupadd --system lxd
sudo usermod -G lxd -a $USER
sudo snap install lxd
newgrp lxd
lxd init
Installed python3-lxc
$ apt-cache show python3-lxc
Package: python3-lxc
Architecture: amd64
Version: 2.1.0-0ubuntu1
Priority: optional
Section: python
Source: lxc
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 137
Depends: liblxc1 (= 2.1.0-0ubuntu1), python3 (<< 3.7), python3 (>= 3.6~), python3:any (>= 3.3.2-2~), libc6 (>= 2.4)
Recommends: lxc-templates (= 2.1.0-0ubuntu1)
Filename: pool/main/l/lxc/python3-lxc_2.1.0-0ubuntu1_amd64.deb
Size: 20666
MD5sum: 38fdb4fd7391c4011abd6a70b917afea
SHA1: 6e4f79cf0a0ad3c645f0489e9dc7782d69a6a934
SHA256: c5382a62b2f95cb9d2c3d658bad83c76c456fe59c47bd8db36e14d218d184564
Homepage: https://linuxcontainers.org
Description-en: Linux Containers userspace tools (Python 3.x bindings)
Containers are insulated areas inside a system, which have their own namespace
for filesystem, network, PID, IPC, CPU and memory allocation and which can be
created using the Control Group and Namespace features included in the Linux
kernel.
.
This package contains the Python 3.x bindings.
Description-md5: ee623a31db200104a7207d9de42b8f04
Supported: 9m