Skip to content

Commit

Permalink
LXC: Fix lxc image list --all-projects (#14833)
Browse files Browse the repository at this point in the history
#14563 attempted to fix
#14561 by adding
`GetImagesAllProjects` and `GetImagesAllProjectsWithFilter` functions to
`client/simplestreams_images.go`, and moving their method signatures to
the `ImageServer` interface. Instead, we should only expand the
`InstanceServer` interface and correctly use the client functions when
`--all-projects` is set.
  • Loading branch information
tomponline authored Jan 24, 2025
2 parents 3d9323c + 0181755 commit 84be4ee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
4 changes: 2 additions & 2 deletions client/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ 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 @@ -245,6 +243,8 @@ 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: 0 additions & 10 deletions client/simplestreams_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ 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 @@ -50,11 +45,6 @@ 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: 7 additions & 2 deletions lxc/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -1373,9 +1373,14 @@ func (c *cmdImageList) run(cmd *cobra.Command, args []string) error {

var allImages []api.Image
if c.flagAllProjects {
allImages, err = remoteServer.GetImagesAllProjectsWithFilter(serverFilters)
instanceServer, ok := remoteServer.(lxd.InstanceServer)
if !ok {
return fmt.Errorf("--all-projects flag is not supported for this server")
}

allImages, err = instanceServer.GetImagesAllProjectsWithFilter(serverFilters)
if err != nil {
allImages, err = remoteServer.GetImagesAllProjects()
allImages, err = instanceServer.GetImagesAllProjects()
if err != nil {
return err
}
Expand Down

0 comments on commit 84be4ee

Please sign in to comment.