From b15c1c76dd433aa6de97df13cfa4022ae19d5a14 Mon Sep 17 00:00:00 2001 From: Kadin Sayani Date: Fri, 29 Nov 2024 16:25:48 -0700 Subject: [PATCH] LXC: Add `GetImagesAllProjects` and `GetImagesAllProjectsWithFilter` client functions and interfaces to `simplestreams_images.go` This commit fixes a regression introduced with support for fetching images across all projects by adding `GetImagesAllProjects` and `GetImagesAllProjectsWithFilter` functions to `client/simplestreams_images.go`, and moving their method signatures to the ImageServer interface. Signed-off-by: Kadin Sayani --- client/interfaces.go | 4 ++-- client/simplestreams_images.go | 10 ++++++++++ lxc/image.go | 9 ++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/client/interfaces.go b/client/interfaces.go index 392c51d33f66..dd1f36286c12 100644 --- a/client/interfaces.go +++ b/client/interfaces.go @@ -50,6 +50,8 @@ type ImageServer interface { GetImages() (images []api.Image, err error) GetImageFingerprints() (fingerprints []string, err error) GetImagesWithFilter(filters []string) (images []api.Image, err error) + GetImagesAllProjects() (images []api.Image, err error) + GetImagesAllProjectsWithFilter(filters []string) (images []api.Image, err error) GetImage(fingerprint string) (image *api.Image, ETag string, err error) GetImageFile(fingerprint string, req ImageFileRequest) (resp *ImageFileResponse, err error) @@ -243,8 +245,6 @@ type InstanceServer interface { UpdateImageAlias(name string, alias api.ImageAliasesEntryPut, ETag string) (err error) RenameImageAlias(name string, alias api.ImageAliasesEntryPost) (err error) DeleteImageAlias(name string) (err error) - GetImagesAllProjects() (images []api.Image, err error) - GetImagesAllProjectsWithFilter(filters []string) (images []api.Image, err error) // Network functions ("network" API extension) GetNetworkNames() (names []string, err error) diff --git a/client/simplestreams_images.go b/client/simplestreams_images.go index 863a8440efb9..9e4495ca8888 100644 --- a/client/simplestreams_images.go +++ b/client/simplestreams_images.go @@ -23,6 +23,11 @@ func (r *ProtocolSimpleStreams) GetImages() ([]api.Image, error) { return r.ssClient.ListImages() } +// GetImagesAllProjects returns a list of available images as Image structs. +func (r *ProtocolSimpleStreams) GetImagesAllProjects() ([]api.Image, error) { + return r.GetImages() +} + // GetImageFingerprints returns a list of available image fingerprints. func (r *ProtocolSimpleStreams) GetImageFingerprints() ([]string, error) { // Get all the images from simplestreams @@ -45,6 +50,11 @@ func (r *ProtocolSimpleStreams) GetImagesWithFilter(filters []string) ([]api.Ima return nil, fmt.Errorf("GetImagesWithFilter is not supported by the simplestreams protocol") } +// GetImagesAllProjectsWithFilter returns an error indicating compatibility with the simplestreams protocol. +func (r *ProtocolSimpleStreams) GetImagesAllProjectsWithFilter(filters []string) ([]api.Image, error) { + return nil, fmt.Errorf("GetImagesAllProjectsWithFilter is not supported by the simplestreams protocol") +} + // GetImage returns an Image struct for the provided fingerprint. func (r *ProtocolSimpleStreams) GetImage(fingerprint string) (*api.Image, string, error) { image, err := r.ssClient.GetImage(fingerprint) diff --git a/lxc/image.go b/lxc/image.go index 70825fdb9cd3..1563d9a3c741 100644 --- a/lxc/image.go +++ b/lxc/image.go @@ -1353,11 +1353,6 @@ func (c *cmdImageList) run(cmd *cobra.Command, args []string) error { return err } - d, err := c.global.conf.GetInstanceServer(remoteName) - if err != nil { - return err - } - // Process the filters filters := []string{} if name != "" { @@ -1378,9 +1373,9 @@ func (c *cmdImageList) run(cmd *cobra.Command, args []string) error { var allImages, images []api.Image if c.flagAllProjects { - allImages, err = d.GetImagesAllProjectsWithFilter(serverFilters) + allImages, err = remoteServer.GetImagesAllProjectsWithFilter(serverFilters) if err != nil { - allImages, err = d.GetImagesAllProjects() + allImages, err = remoteServer.GetImagesAllProjects() if err != nil { return err }