Lxd api: best way to retrieve images' fingerprint in a project

Hello everyone,

the lxd docs state, that images can be assigned to individual projects:

LXD supports projects as a way to split your LXD server. Each project holds its own set of instances and may also have its own images and profiles.

Right now, I am trying to fetch the fingerprints of all images that belong to a given project. The only way I found to access this information is by querying the /1.0/projects/{name} endpoint of the lxd api.

In the response one can see what entities make use of the project:

    "name": "foo",
    "used_by": [
    // ...

As shown, the used_by field includes images as well as profiles, instances etc. Iterating over the array and checking for the prefix /1.0/images/ seems a bit cumbersome in order to retrieve the fingerprint 0e60015346f06627f10580d56ac7fffd9ea775f6d4f25987217d5eed94910a20.

Is anyone aware of more elegant solution?

I dont think there is, all the key objects return a consistent used_by format.

Make one method that filters these lists by users access lists, that would be my suggestion (that’s what I do) .

GET /1.0/images?project=NAME

Thanks for your replies.

Querying this endpoint with the project parameter works:

lxc query /1.0/images?project=NAME

I should have noted that I’m using the Go lxd client to interact with the restful api. When looking at the image related functions for the client, i.e. GetImage*(), it does not seem to be possible to specify the project=NAME parameter when the client is retrieving an image.

Is this a functional limitation of the Go lxd client?

You should use .UseProject("project").GetImage()


Thank you. This worked great :+1:

1 Like