From 8819cefaac0ef7009e02ec00ebfdcd2945c1692d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Wed, 25 Oct 2023 15:06:41 -0400 Subject: [PATCH] cmd/incus: Use api.ProjectDefaultName MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber --- cmd/incus/admin_init_auto.go | 2 +- cmd/incus/admin_init_dump.go | 6 +++--- cmd/incus/admin_init_interactive.go | 2 +- cmd/incus/cluster.go | 4 ++-- cmd/incus/config_trust.go | 4 ++-- cmd/incus/main.go | 3 ++- cmd/incus/network_allocations.go | 2 +- cmd/incus/project.go | 2 +- cmd/incus/remote.go | 2 +- 9 files changed, 14 insertions(+), 13 deletions(-) diff --git a/cmd/incus/admin_init_auto.go b/cmd/incus/admin_init_auto.go index 0582d6c29..f04f2cd1d 100644 --- a/cmd/incus/admin_init_auto.go +++ b/cmd/incus/admin_init_auto.go @@ -151,7 +151,7 @@ func (c *cmdAdminInit) RunAuto(cmd *cobra.Command, args []string, d incus.Instan // Define the new network network := api.InitNetworksProjectPost{} network.Name = fmt.Sprintf("incusbr%d", idx) - network.Project = "default" + network.Project = api.ProjectDefaultName config.Networks = append(config.Networks, network) // Add it to the profile diff --git a/cmd/incus/admin_init_dump.go b/cmd/incus/admin_init_dump.go index b4fd6ce61..4da2011d8 100644 --- a/cmd/incus/admin_init_dump.go +++ b/cmd/incus/admin_init_dump.go @@ -23,9 +23,9 @@ func (c *cmdAdminInit) RunDump(d incus.InstanceServer) error { // Only retrieve networks in the default project as the preseed format doesn't support creating // projects at this time. - networks, err := d.UseProject("default").GetNetworks() + networks, err := d.UseProject(api.ProjectDefaultName).GetNetworks() if err != nil { - return fmt.Errorf(i18n.G("Failed to retrieve current server network configuration for project %q: %w"), "default", err) + return fmt.Errorf(i18n.G("Failed to retrieve current server network configuration for project %q: %w"), api.ProjectDefaultName, err) } for _, network := range networks { @@ -39,7 +39,7 @@ func (c *cmdAdminInit) RunDump(d incus.InstanceServer) error { networksPost.Description = network.Description networksPost.Name = network.Name networksPost.Type = network.Type - networksPost.Project = "default" + networksPost.Project = api.ProjectDefaultName config.Networks = append(config.Networks, networksPost) } diff --git a/cmd/incus/admin_init_interactive.go b/cmd/incus/admin_init_interactive.go index 6a0de08b3..3a8278fca 100644 --- a/cmd/incus/admin_init_interactive.go +++ b/cmd/incus/admin_init_interactive.go @@ -339,7 +339,7 @@ func (c *cmdAdminInit) askNetworking(config *api.InitPreseed, d incus.InstanceSe // Define the network net := api.InitNetworksProjectPost{} net.Config = map[string]string{} - net.Project = "default" + net.Project = api.ProjectDefaultName // Network name net.Name, err = c.global.asker.AskString(i18n.G("What should the new bridge be called?")+" [default=incusbr0]: ", "incusbr0", validate.IsNetworkName) diff --git a/cmd/incus/cluster.go b/cmd/incus/cluster.go index 8805e45e3..4394e971a 100644 --- a/cmd/incus/cluster.go +++ b/cmd/incus/cluster.go @@ -902,7 +902,7 @@ func (c *cmdClusterListTokens) Run(cmd *cobra.Command, args []string) error { } // Get the cluster member join tokens. Use default project as join tokens are created in default project. - ops, err := resource.server.UseProject("default").GetOperations() + ops, err := resource.server.UseProject(api.ProjectDefaultName).GetOperations() if err != nil { return err } @@ -996,7 +996,7 @@ func (c *cmdClusterRevokeToken) Run(cmd *cobra.Command, args []string) error { } // Get the cluster member join tokens. Use default project as join tokens are created in default project. - ops, err := resource.server.UseProject("default").GetOperations() + ops, err := resource.server.UseProject(api.ProjectDefaultName).GetOperations() if err != nil { return err } diff --git a/cmd/incus/config_trust.go b/cmd/incus/config_trust.go index 96d53de8b..ce96bd6c5 100644 --- a/cmd/incus/config_trust.go +++ b/cmd/incus/config_trust.go @@ -497,7 +497,7 @@ func (c *cmdConfigTrustListTokens) Run(cmd *cobra.Command, args []string) error resource := resources[0] // Get the certificate add tokens. Use default project as join tokens are created in default project. - ops, err := resource.server.UseProject("default").GetOperations() + ops, err := resource.server.UseProject(api.ProjectDefaultName).GetOperations() if err != nil { return err } @@ -638,7 +638,7 @@ func (c *cmdConfigTrustRevokeToken) Run(cmd *cobra.Command, args []string) error resource := resources[0] // Get the certificate add tokens. Use default project as certificate add tokens are created in default project. - ops, err := resource.server.UseProject("default").GetOperations() + ops, err := resource.server.UseProject(api.ProjectDefaultName).GetOperations() if err != nil { return err } diff --git a/cmd/incus/main.go b/cmd/incus/main.go index afcaeeb8b..ac972b8fc 100644 --- a/cmd/incus/main.go +++ b/cmd/incus/main.go @@ -15,6 +15,7 @@ import ( "github.com/lxc/incus/internal/i18n" internalUtil "github.com/lxc/incus/internal/util" "github.com/lxc/incus/internal/version" + "github.com/lxc/incus/shared/api" config "github.com/lxc/incus/shared/cliconfig" "github.com/lxc/incus/shared/logger" "github.com/lxc/incus/shared/util" @@ -380,7 +381,7 @@ func (c *cmdGlobal) PreRun(cmd *cobra.Command, args []string) error { // Detect usable project. names, err := d.GetProjectNames() if err == nil { - if len(names) == 1 && names[0] != "default" { + if len(names) == 1 && names[0] != api.ProjectDefaultName { remote := c.conf.Remotes["local"] remote.Project = names[0] c.conf.Remotes["local"] = remote diff --git a/cmd/incus/network_allocations.go b/cmd/incus/network_allocations.go index ff05bfef7..f1976fbe2 100644 --- a/cmd/incus/network_allocations.go +++ b/cmd/incus/network_allocations.go @@ -55,7 +55,7 @@ func (c *cmdNetworkListAllocations) Command() *cobra.Command { cmd.RunE = c.Run cmd.Flags().StringVarP(&c.flagFormat, "format", "f", "table", i18n.G("Format (csv|json|table|yaml|compact)")+"``") - cmd.Flags().StringVarP(&c.flagProject, "project", "p", "default", i18n.G("Run again a specific project")) + cmd.Flags().StringVarP(&c.flagProject, "project", "p", api.ProjectDefaultName, i18n.G("Run again a specific project")) cmd.Flags().BoolVar(&c.flagAllProjects, "all-projects", false, i18n.G("Run against all projects")) return cmd } diff --git a/cmd/incus/project.go b/cmd/incus/project.go index a470222c0..aaa07aef4 100644 --- a/cmd/incus/project.go +++ b/cmd/incus/project.go @@ -448,7 +448,7 @@ func (c *cmdProjectList) Run(cmd *cobra.Command, args []string) error { currentProject := conf.Remotes[remoteName].Project if currentProject == "" { - currentProject = "default" + currentProject = api.ProjectDefaultName } data := [][]string{} diff --git a/cmd/incus/remote.go b/cmd/incus/remote.go index ab5511e2d..d14ae6e6e 100644 --- a/cmd/incus/remote.go +++ b/cmd/incus/remote.go @@ -126,7 +126,7 @@ func (c *cmdRemoteAdd) findProject(d incus.InstanceServer, project string) (stri } // Deal with multiple projects. - if util.ValueInSlice("default", names) { + if util.ValueInSlice(api.ProjectDefaultName, names) { // If we have access to the default project, use it. return "", nil }