1
0
mirror of https://github.com/lxc/incus.git synced 2026-02-05 18:45:46 +01:00

cmd/incus: Use api.ProjectDefaultName

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
This commit is contained in:
Stéphane Graber
2023-10-25 15:06:41 -04:00
parent 1c8bfd5bce
commit 8819cefaac
9 changed files with 14 additions and 13 deletions

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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
}

View File

@@ -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{}

View File

@@ -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
}