Skip to content

Commit

Permalink
lxc/image: Only get instance server when --all-projects flag is set
Browse files Browse the repository at this point in the history
Signed-off-by: Kadin Sayani <kadin.sayani@canonical.com>
  • Loading branch information
kadinsayani committed Jan 21, 2025
1 parent a02b39f commit dc02d49
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lxc/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"

"github.com/canonical/lxd/client"
lxd "github.com/canonical/lxd/client"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
cli "github.com/canonical/lxd/shared/cmd"
Expand Down Expand Up @@ -1130,8 +1130,10 @@ Column shorthand chars:
return cmd
}

const defaultImagesColumns = "lfpdatsu"
const defaultImagesColumnsAllProjects = "elfpdatsu"
const (
defaultImagesColumns = "lfpdatsu"
defaultImagesColumnsAllProjects = "elfpdatsu"
)

func (c *cmdImageList) parseColumns() ([]imageColumn, error) {
columnsShorthandMap := map[rune]imageColumn{
Expand Down Expand Up @@ -1353,11 +1355,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,6 +1375,11 @@ func (c *cmdImageList) run(cmd *cobra.Command, args []string) error {

var allImages []api.Image
if c.flagAllProjects {
d, err := c.global.conf.GetInstanceServer(remoteName)
if err != nil {
return fmt.Errorf("--all-projects flag is not supported for this server: %w", err)
}

allImages, err = d.GetImagesAllProjectsWithFilter(serverFilters)
if err != nil {
allImages, err = d.GetImagesAllProjects()
Expand Down

0 comments on commit dc02d49

Please sign in to comment.