Skip to content

Commit

Permalink
lxc/image: Add GetImagesAllProjects and `GetImagesAllProjectsWithFi…
Browse files Browse the repository at this point in the history
…lter` 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 <[email protected]>
  • Loading branch information
kadinsayani committed Nov 29, 2024
1 parent 4a3c4a3 commit 003e928
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions client/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions client/simplestreams_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
9 changes: 2 additions & 7 deletions lxc/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand All @@ -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
}
Expand Down

0 comments on commit 003e928

Please sign in to comment.