From dc02d49ed936aae2540b4c1c56bf681c6188ec5d Mon Sep 17 00:00:00 2001 From: Kadin Sayani Date: Tue, 21 Jan 2025 09:28:25 -0700 Subject: [PATCH] lxc/image: Only get instance server when `--all-projects` flag is set Signed-off-by: Kadin Sayani --- lxc/image.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lxc/image.go b/lxc/image.go index 9c13033992f2..70a5fab81da5 100644 --- a/lxc/image.go +++ b/lxc/image.go @@ -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" @@ -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{ @@ -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 != "" { @@ -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()