Update CLI to all use the new expand bracket capability
This commit is contained in:
@@ -2,18 +2,23 @@ package add
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/hpcng/warewulf/pkg/hostlist"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
var count uint
|
||||
nodeDB, err := node.New()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to open node database")
|
||||
}
|
||||
|
||||
for _, a := range args {
|
||||
node_args := hostlist.Expand(args)
|
||||
|
||||
for _, a := range node_args {
|
||||
n, err := nodeDB.AddNode(a)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to add node")
|
||||
@@ -34,14 +39,16 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("you must include the '--netdev' option")
|
||||
}
|
||||
|
||||
NewIpaddr := util.IncrementIPv4(SetIpaddr, count)
|
||||
|
||||
if _, ok := n.NetDevs[SetNetDev]; !ok {
|
||||
var netdev node.NetDevEntry
|
||||
n.NetDevs[SetNetDev] = &netdev
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Id.Get(), SetNetDev, SetIpaddr)
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Id.Get(), SetNetDev, NewIpaddr)
|
||||
|
||||
n.NetDevs[SetNetDev].Ipaddr.Set(SetIpaddr)
|
||||
n.NetDevs[SetNetDev].Ipaddr.Set(NewIpaddr)
|
||||
n.NetDevs[SetNetDev].Default.SetB(true)
|
||||
err := nodeDB.NodeUpdate(n)
|
||||
if err != nil {
|
||||
@@ -123,7 +130,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
return errors.Wrap(err, "failed to update nodedb")
|
||||
}
|
||||
}
|
||||
|
||||
count++
|
||||
}
|
||||
|
||||
return errors.Wrap(nodeDB.Persist(), "failed to persist nodedb")
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/power"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/hpcng/warewulf/pkg/hostlist"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -25,6 +26,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
args = hostlist.Expand(args)
|
||||
|
||||
if len(args) > 0 {
|
||||
nodes = node.FilterByName(nodes, args)
|
||||
} else {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/hpcng/warewulf/pkg/hostlist"
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -27,6 +28,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
args = hostlist.Expand(args)
|
||||
|
||||
for _, r := range args {
|
||||
var match bool
|
||||
for _, n := range nodes {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/hpcng/warewulf/pkg/hostlist"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -26,6 +27,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
args = hostlist.Expand(args)
|
||||
|
||||
if ShowAll {
|
||||
for _, node := range node.FilterByName(nodes, args) {
|
||||
fmt.Printf("################################################################################\n")
|
||||
|
||||
@@ -15,7 +15,9 @@ var (
|
||||
baseCmd = &cobra.Command{
|
||||
Use: "node",
|
||||
Short: "Node management",
|
||||
Long: "Management of node settings",
|
||||
Long: "Management of node settings. All node ranges can use brackets to identify\n" +
|
||||
"node ranges. For example: n00[00-4].cluster[0-1] will identify the first 5 nodes\n" +
|
||||
"in cluster0 and cluster1.",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/power"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/hpcng/warewulf/pkg/hostlist"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -26,6 +27,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
args = hostlist.Expand(args)
|
||||
|
||||
if len(args) > 0 {
|
||||
nodes = node.FilterByName(nodes, args)
|
||||
} else {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfd"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/hpcng/warewulf/pkg/hostlist"
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -32,7 +33,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
if !SetNodeAll {
|
||||
if len(args) > 0 {
|
||||
nodes = node.FilterByName(nodes, args)
|
||||
nodes = node.FilterByName(nodes, hostlist.Expand(args))
|
||||
} else {
|
||||
//nolint:errcheck
|
||||
cmd.Usage()
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/power"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/hpcng/warewulf/pkg/hostlist"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -27,7 +28,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
nodes = node.FilterByName(nodes, args)
|
||||
nodes = node.FilterByName(nodes, hostlist.Expand(args))
|
||||
} else {
|
||||
//nolint:errcheck
|
||||
cmd.Usage()
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/power"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/hpcng/warewulf/pkg/hostlist"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -27,7 +28,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
nodes = node.FilterByName(nodes, args)
|
||||
nodes = node.FilterByName(nodes, hostlist.Expand(args))
|
||||
} else {
|
||||
//nolint:errcheck
|
||||
cmd.Usage()
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/power"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/hpcng/warewulf/pkg/hostlist"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -27,7 +28,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
nodes = node.FilterByName(nodes, args)
|
||||
nodes = node.FilterByName(nodes, hostlist.Expand(args))
|
||||
} else {
|
||||
//nolint:errcheck
|
||||
cmd.Usage()
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/power"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/hpcng/warewulf/pkg/hostlist"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -27,7 +28,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
nodes = node.FilterByName(nodes, args)
|
||||
nodes = node.FilterByName(nodes, hostlist.Expand(args))
|
||||
} else {
|
||||
//nolint:errcheck
|
||||
cmd.Usage()
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/power"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/hpcng/warewulf/pkg/hostlist"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -27,7 +28,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
nodes = node.FilterByName(nodes, args)
|
||||
nodes = node.FilterByName(nodes, hostlist.Expand(args))
|
||||
} else {
|
||||
//nolint:errcheck
|
||||
cmd.Usage()
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/power"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/hpcng/warewulf/pkg/hostlist"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -27,7 +28,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
nodes = node.FilterByName(nodes, args)
|
||||
nodes = node.FilterByName(nodes, hostlist.Expand(args))
|
||||
} else {
|
||||
//nolint:errcheck
|
||||
cmd.Usage()
|
||||
|
||||
Reference in New Issue
Block a user