mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
add uncloud machine token command to print machine token to add machine to cluster
This commit is contained in:
@@ -22,7 +22,7 @@ func NewInitCommand() *cobra.Command {
|
||||
opts := initOptions{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Initialise a new cluster that consists of the local or remote machine",
|
||||
Short: "Initialise a new cluster that consists of the local or remote machine.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
netPrefix, err := netip.ParsePrefix(opts.network)
|
||||
if err != nil {
|
||||
|
||||
@@ -12,6 +12,7 @@ func NewRootCommand() *cobra.Command {
|
||||
cmd.AddCommand(
|
||||
NewAddCommand(),
|
||||
NewInitCommand(),
|
||||
NewTokenCommand(),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"uncloud/internal/machine"
|
||||
"uncloud/internal/machine/daemon"
|
||||
)
|
||||
|
||||
type tokenOptions struct {
|
||||
dataDir string
|
||||
}
|
||||
|
||||
func NewTokenCommand() *cobra.Command {
|
||||
opts := tokenOptions{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "token",
|
||||
Short: "Print the local machine's token for adding it to a cluster.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
token, err := daemon.MachineToken(opts.dataDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get machine token: %w", err)
|
||||
}
|
||||
tokenStr, err := token.String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("encode machine token: %w", err)
|
||||
}
|
||||
fmt.Println(tokenStr)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&opts.dataDir, "data-dir", "d", machine.DefaultDataDir,
|
||||
"Directory for storing persistent machine state")
|
||||
_ = cmd.MarkFlagDirname("data-dir")
|
||||
|
||||
return cmd
|
||||
}
|
||||
Reference in New Issue
Block a user