Skip to content

Commit

Permalink
cmd/incus: Add admin cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Oct 5, 2023
1 parent 2c93ff2 commit 606591f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/incus/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func (c *cmdAdmin) Command() *cobra.Command {
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G(
`Manage incus daemon`))

// cluster
adminClusterCmd := cmdAdminCluster{global: c.global}
cmd.AddCommand(adminClusterCmd.Command())

// init
adminInitCmd := cmdAdminInit{global: c.global}
cmd.AddCommand(adminInitCmd.Command())
Expand Down
51 changes: 51 additions & 0 deletions cmd/incus/admin_cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//go:build linux

package main

import (
"fmt"
"os"
"os/exec"

cli "github.com/lxc/incus/internal/cmd"
"github.com/lxc/incus/internal/i18n"
"github.com/lxc/incus/shared/util"

"github.com/spf13/cobra"
)

type cmdAdminCluster struct {
global *cmdGlobal
}

func (c *cmdAdminCluster) Command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = usage("cluster")
cmd.Short = i18n.G("Low-level cluster administration commands")
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G(
`Low level administration tools for inspecting and recovering clusters.`))

cmd.Run = c.Run
return cmd
}

func (c *cmdAdminCluster) Run(cmd *cobra.Command, args []string) {
path, _ := exec.LookPath("incusd")
if path == "" {
if util.PathExists("/usr/lib/incus/incusd") {
path = "/usr/lib/incus/incusd"
} else if util.PathExists("/opt/incus/bin/incusd") {
path = "/opt/incus/bin/incusd"
}
}

if path == "" {
fmt.Println(i18n.G(`The "cluster" subcommand requires access to internal server data.
To do so, it's actually part of the "incusd" binary rather than "incus".
You can invoke it through "incusd cluster".`))
os.Exit(1)
}

doExec(path, []string{"incusd", "cluster"}, getEnviron())
}

0 comments on commit 606591f

Please sign in to comment.