From 275937e966eb34e9a18b6ee0aba94f15bbdbdd0d Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 28 Sep 2021 12:22:34 +0200 Subject: [PATCH] dynamic nouns for 'wwctl power' --- internal/app/wwctl/power/off/root.go | 14 ++++++++++++++ internal/app/wwctl/power/on/root.go | 14 ++++++++++++++ internal/app/wwctl/power/reset/root.go | 14 ++++++++++++++ internal/app/wwctl/power/soft/root.go | 14 ++++++++++++++ internal/app/wwctl/power/status/root.go | 14 ++++++++++++++ 5 files changed, 70 insertions(+) diff --git a/internal/app/wwctl/power/off/root.go b/internal/app/wwctl/power/off/root.go index 520ba12a..0b98bed1 100644 --- a/internal/app/wwctl/power/off/root.go +++ b/internal/app/wwctl/power/off/root.go @@ -1,6 +1,7 @@ package poweroff import ( + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/spf13/cobra" ) @@ -10,6 +11,19 @@ var ( Short: "Power off the given node(s)", Long: "This command will shutdown the power to a given set of nodes.", RunE: CobraRunE, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if len(args) != 0 { + return nil, cobra.ShellCompDirectiveNoFileComp + } + + nodeDB, _ := node.New() + nodes, _ := nodeDB.FindAllNodes() + var node_names []string + for _, node := range nodes { + node_names = append(node_names, node.Id.Get()) + } + return node_names, cobra.ShellCompDirectiveNoFileComp + }, } ) diff --git a/internal/app/wwctl/power/on/root.go b/internal/app/wwctl/power/on/root.go index 4da9b3e5..7918299a 100644 --- a/internal/app/wwctl/power/on/root.go +++ b/internal/app/wwctl/power/on/root.go @@ -1,6 +1,7 @@ package poweron import ( + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/spf13/cobra" ) @@ -10,6 +11,19 @@ var ( Short: "Power on the given node(s)", Long: "This command will power on a given set of nodes.", RunE: CobraRunE, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if len(args) != 0 { + return nil, cobra.ShellCompDirectiveNoFileComp + } + + nodeDB, _ := node.New() + nodes, _ := nodeDB.FindAllNodes() + var node_names []string + for _, node := range nodes { + node_names = append(node_names, node.Id.Get()) + } + return node_names, cobra.ShellCompDirectiveNoFileComp + }, } ) diff --git a/internal/app/wwctl/power/reset/root.go b/internal/app/wwctl/power/reset/root.go index a55d780d..6622de8e 100644 --- a/internal/app/wwctl/power/reset/root.go +++ b/internal/app/wwctl/power/reset/root.go @@ -1,6 +1,7 @@ package powerreset import ( + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/spf13/cobra" ) @@ -10,6 +11,19 @@ var ( Short: "Issue a reset to the given node(s)", Long: "This command will issue a reset to the given set of nodes.", RunE: CobraRunE, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if len(args) != 0 { + return nil, cobra.ShellCompDirectiveNoFileComp + } + + nodeDB, _ := node.New() + nodes, _ := nodeDB.FindAllNodes() + var node_names []string + for _, node := range nodes { + node_names = append(node_names, node.Id.Get()) + } + return node_names, cobra.ShellCompDirectiveNoFileComp + }, } ) diff --git a/internal/app/wwctl/power/soft/root.go b/internal/app/wwctl/power/soft/root.go index 41813cb6..af13114c 100644 --- a/internal/app/wwctl/power/soft/root.go +++ b/internal/app/wwctl/power/soft/root.go @@ -1,6 +1,7 @@ package powersoft import ( + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/spf13/cobra" ) @@ -10,6 +11,19 @@ var ( Short: "Gracefully shuts down the given node(s)", Long: "This command will gracefully shutdown the given set of nodes.", RunE: CobraRunE, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if len(args) != 0 { + return nil, cobra.ShellCompDirectiveNoFileComp + } + + nodeDB, _ := node.New() + nodes, _ := nodeDB.FindAllNodes() + var node_names []string + for _, node := range nodes { + node_names = append(node_names, node.Id.Get()) + } + return node_names, cobra.ShellCompDirectiveNoFileComp + }, } ) diff --git a/internal/app/wwctl/power/status/root.go b/internal/app/wwctl/power/status/root.go index 60eb2d20..454165e5 100644 --- a/internal/app/wwctl/power/status/root.go +++ b/internal/app/wwctl/power/status/root.go @@ -1,6 +1,7 @@ package powerstatus import ( + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/spf13/cobra" ) @@ -10,6 +11,19 @@ var ( Short: "Show power status for the given node(s)", Long: "This command will show the power status of a given set of nodes.", RunE: CobraRunE, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if len(args) != 0 { + return nil, cobra.ShellCompDirectiveNoFileComp + } + + nodeDB, _ := node.New() + nodes, _ := nodeDB.FindAllNodes() + var node_names []string + for _, node := range nodes { + node_names = append(node_names, node.Id.Get()) + } + return node_names, cobra.ShellCompDirectiveNoFileComp + }, } )