Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/unreleased/Added-20250312-124859.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Added
body: New command `ydbops nodes list`
time: 2025-03-12T12:48:59.010415078+03:00
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ydbops
vendor
bin
/.vscode/
29 changes: 29 additions & 0 deletions cmd/nodes/list/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package list

import (
"github.com/spf13/cobra"

"github.com/ydb-platform/ydbops/pkg/cli"
"github.com/ydb-platform/ydbops/pkg/cmdutil"
)

func New(f cmdutil.Factory) *cobra.Command {
opts := &Options{}

cmd := cli.SetDefaultsOn(&cobra.Command{
Use: "list",
Short: "List the cluster nodes",
Long: `ydbops cluster list:
Obtain the list of cluster nodes from the Configuration Management System.`,
PreRunE: cli.PopulateProfileDefaultsAndValidate(
f.GetBaseOptions(), opts,
),
RunE: func(cmd *cobra.Command, args []string) error {
return opts.Run(f)
},
})

opts.DefineFlags(cmd.PersistentFlags())

return cmd
}
40 changes: 40 additions & 0 deletions cmd/nodes/list/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package list

import (
"fmt"

"github.com/spf13/pflag"

"github.com/ydb-platform/ydbops/pkg/cmdutil"
)

type Options struct {
}

func (o *Options) DefineFlags(fs *pflag.FlagSet) {
}

func (o *Options) Validate() error {
return nil
}

func (o *Options) Run(f cmdutil.Factory) error {
nodes, err := f.GetCMSClient().Nodes()
if err != nil {
return err
}

fmt.Printf("--- begin nodes ---\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need it? Probably, it's better to return as JSON?

for _, node := range nodes {
nodeType := "UNKNOWN"
if node.GetStorage() != nil {
nodeType = "STORAGE"
} else if node.GetDynamic() != nil {
nodeType = "DATABASE"
}
fmt.Printf("%d\t%s:%d\t%s\n", node.GetNodeId(), node.GetHost(), node.GetPort(), nodeType)
}
fmt.Printf("--- end nodes ---\n")

return nil
}
25 changes: 25 additions & 0 deletions cmd/nodes/nodes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cluster

import (
"github.com/spf13/cobra"

"github.com/ydb-platform/ydbops/cmd/nodes/list"
"github.com/ydb-platform/ydbops/pkg/cli"
"github.com/ydb-platform/ydbops/pkg/cmdutil"
)

func New(f cmdutil.Factory) *cobra.Command {
cmd := cli.SetDefaultsOn(&cobra.Command{
Use: "nodes",
Short: "Node operations with the Cluster Management System",
Long: `ydbops nodes [command]:
Perform node operations.`,
RunE: cli.RequireSubcommand,
})

cmd.AddCommand(
list.New(f),
)

return cmd
}
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go.uber.org/zap/zapcore"

"github.com/ydb-platform/ydbops/cmd/maintenance"
nodes "github.com/ydb-platform/ydbops/cmd/nodes"
"github.com/ydb-platform/ydbops/cmd/restart"
"github.com/ydb-platform/ydbops/cmd/run"
"github.com/ydb-platform/ydbops/cmd/version"
Expand Down Expand Up @@ -95,6 +96,7 @@ func NewRootCommand(
func InitRootCommandTree(root *cobra.Command, f cmdutil.Factory) {
root.AddCommand(
restart.New(f),
nodes.New(f),
maintenance.New(f),
run.New(f),
version.New(),
Expand Down
Loading