LXD local pylxd.Client connection sees no containers while "lxc list" command lists a dozen

224 Views Asked by At

On a ubuntu 16.04 machine with lxd 2.21, the following code returns all my containers:

from pylxd import Client
client = Client()
client.containers.all()

On a ubuntu 18.04 machine with lxd 3.0.1, the same code returns an empty list

On both machines, the command lxc list returns many containers, for some reason the client connection on the newer lxd host is not "seeing" the containers.

1

There are 1 best solutions below

0
On

The solution was to set this environment variable:

export LXD_DIR=/var/lib/lxd

The api uses the socket /var/snap/lxd/common/lxd/unix.socket by default, and in my installation the proper socket to use is /var/lib/lxd/unix.socket

from pylxd import Client
os.environ["LXD_DIR"] = "/var/lib/lxd"
client = Client()
client.containers.all()