Boutran
Boutran

Reputation: 10144

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

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.

Upvotes: 0

Views: 239

Answers (1)

Boutran
Boutran

Reputation: 10144

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()

Upvotes: 1

Related Questions