wwctl commands without NodeInfo
mostly remove Get and calls for the id Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
28a7b9fe84
commit
457c7c16b1
@@ -106,8 +106,8 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
if len(nodes) != 1 {
|
||||
return fmt.Errorf("no single node idendified with %s", nodename)
|
||||
}
|
||||
overlays := nodes[0].SystemOverlay.GetSlice()
|
||||
overlays = append(overlays, nodes[0].RuntimeOverlay.GetSlice()...)
|
||||
overlays := nodes[0].SystemOverlay
|
||||
overlays = append(overlays, nodes[0].RuntimeOverlay...)
|
||||
err = overlay.BuildOverlayIndir(nodes[0], overlays, path.Join(runDir, "nodeoverlay"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not build overlay: %s", err)
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package dfaults
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
fmt.Println(node.FallBackConf)
|
||||
return
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package dfaults
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
Use: "defaults",
|
||||
Short: "print defaults",
|
||||
Long: "This command prints the fallbacks which are used if defaults.conf isn't present",
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.NoArgs,
|
||||
Aliases: []string{"dfaults"},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package genconf
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/genconf/completions"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/genconf/dfaults"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/genconf/man"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/genconf/reference"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/genconf/warewulfconf"
|
||||
@@ -25,7 +24,6 @@ func init() {
|
||||
baseCmd.AddCommand(completions.GetCommand())
|
||||
baseCmd.AddCommand(man.GetCommand())
|
||||
baseCmd.AddCommand(reference.GetCommand())
|
||||
baseCmd.AddCommand(dfaults.GetCommand())
|
||||
baseCmd.AddCommand(warewulfconf.GetCommand())
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
type PrintHelper struct {
|
||||
|
||||
@@ -23,7 +23,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
ARG_LOOP:
|
||||
for _, arg := range args {
|
||||
for _, n := range nodes {
|
||||
if n.Kernel.Override.Get() == arg {
|
||||
if n.Kernel.Override == arg {
|
||||
wwlog.Error("Kernel is configured for nodes, skipping: %s", arg)
|
||||
continue ARG_LOOP
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 && !OptDetect {
|
||||
wwlog.Error("the '--detect' flag is needed, if no kernel version is suppiled")
|
||||
wwlog.Error("the '--detect' flag is needed, if no kernel version is supplied")
|
||||
os.Exit(1)
|
||||
}
|
||||
if OptDetect && (OptRoot == "" || OptContainer == "") {
|
||||
@@ -66,14 +66,10 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
//TODO: Don't loop through profiles, instead have a nodeDB function that goes directly to the map
|
||||
profiles, _ := nodeDB.FindAllProfiles()
|
||||
for _, profile := range profiles {
|
||||
wwlog.Debug("Looking for profile default: %s", profile.Id.Get())
|
||||
if profile.Id.Get() == "default" {
|
||||
wwlog.Debug("Looking for profile default: %s", profile.Id())
|
||||
if profile.Id() == "default" {
|
||||
wwlog.Debug("Found profile default, setting kernel version to: %s", args[0])
|
||||
profile.Kernel.Override.Set(args[0])
|
||||
err := nodeDB.ProfileUpdate(profile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to update node profile")
|
||||
}
|
||||
profile.Kernel.Override = args[0]
|
||||
}
|
||||
}
|
||||
err = nodeDB.Persist()
|
||||
|
||||
@@ -23,7 +23,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
nodemap := make(map[string]int)
|
||||
|
||||
for _, n := range nodes {
|
||||
nodemap[n.Kernel.Override.Get()]++
|
||||
nodemap[n.Kernel.Override]++
|
||||
}
|
||||
|
||||
fmt.Printf("%-35s %-25s %-6s\n", "KERNEL NAME", "KERNEL VERSION", "NODES")
|
||||
|
||||
@@ -20,17 +20,12 @@ the required type is returned
|
||||
*/
|
||||
func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) error {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
// run converters for different types
|
||||
for _, c := range vars.converters {
|
||||
if err := c(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// remove the UNDEF network as all network values are assigned
|
||||
// to this network
|
||||
if !node.ObjectIsEmpty(vars.nodeConf.NetDevs["UNDEF"]) {
|
||||
netDev := *vars.nodeConf.NetDevs["UNDEF"]
|
||||
vars.nodeConf.NetDevs[vars.netName] = &netDev
|
||||
fmt.Println("not empty")
|
||||
}
|
||||
delete(vars.nodeConf.NetDevs, "UNDEF")
|
||||
if vars.fsName != "" {
|
||||
@@ -56,6 +51,9 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("partition and disk must be specified")
|
||||
}
|
||||
delete(vars.nodeConf.Disks, "UNDEF")
|
||||
if len(vars.nodeConf.Profiles) == 0 {
|
||||
vars.nodeConf.Profiles = []string{"default"}
|
||||
}
|
||||
buffer, err := yaml.Marshal(vars.nodeConf)
|
||||
if err != nil {
|
||||
wwlog.Error("Can't marshall nodeInfo", err)
|
||||
|
||||
@@ -12,18 +12,17 @@ import (
|
||||
|
||||
// Holds the variables which are needed in CobraRunE
|
||||
type variables struct {
|
||||
netName string
|
||||
fsName string
|
||||
partName string
|
||||
diskName string
|
||||
nodeConf node.NodeConf
|
||||
converters []func() error
|
||||
netName string
|
||||
fsName string
|
||||
partName string
|
||||
diskName string
|
||||
nodeConf node.NodeConf
|
||||
}
|
||||
|
||||
// Returns the newly created command
|
||||
func GetCommand() *cobra.Command {
|
||||
vars := variables{}
|
||||
vars.nodeConf = node.NewConf()
|
||||
vars.nodeConf = node.NewNode("")
|
||||
baseCmd := &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "add [OPTIONS] NODENAME",
|
||||
@@ -33,7 +32,7 @@ func GetCommand() *cobra.Command {
|
||||
RunE: CobraRunE(&vars),
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
vars.converters = vars.nodeConf.CreateFlags(baseCmd, []string{"tagdel", "nettagdel", "ipmitagdel"})
|
||||
vars.nodeConf.CreateFlags(baseCmd)
|
||||
baseCmd.PersistentFlags().StringVar(&vars.netName, "netname", "default", "Set network name for network options")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.fsName, "fsname", "", "set the file system name which must match a partition name")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.partName, "partname", "", "set the partition name so it can be used by a file system")
|
||||
@@ -68,7 +67,7 @@ func GetCommand() *cobra.Command {
|
||||
nodeDB, _ := node.New()
|
||||
profiles, _ := nodeDB.FindAllProfiles()
|
||||
for _, profile := range profiles {
|
||||
list = append(list, profile.Id.Get())
|
||||
list = append(list, profile.Id())
|
||||
}
|
||||
return list, cobra.ShellCompDirectiveNoFileComp
|
||||
}); err != nil {
|
||||
|
||||
@@ -40,26 +40,26 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
for _, node := range nodes {
|
||||
|
||||
if node.Ipmi.Ipaddr.Get() == "" {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id.Get())
|
||||
if node.Ipmi.Ipaddr.IsUnspecified() {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id())
|
||||
continue
|
||||
}
|
||||
|
||||
ipmiCmd := power.IPMI{
|
||||
NodeName: node.Id.Get(),
|
||||
HostName: node.Ipmi.Ipaddr.Get(),
|
||||
Port: node.Ipmi.Port.Get(),
|
||||
User: node.Ipmi.UserName.Get(),
|
||||
Password: node.Ipmi.Password.Get(),
|
||||
NodeName: node.Id(),
|
||||
HostName: node.Ipmi.Ipaddr.String(),
|
||||
Port: node.Ipmi.Port,
|
||||
User: node.Ipmi.UserName,
|
||||
Password: node.Ipmi.Password,
|
||||
AuthType: "MD5",
|
||||
Interface: node.Ipmi.Interface.Get(),
|
||||
EscapeChar: node.Ipmi.EscapeChar.Get(),
|
||||
Interface: node.Ipmi.Interface,
|
||||
EscapeChar: node.Ipmi.EscapeChar,
|
||||
}
|
||||
|
||||
err := ipmiCmd.Console()
|
||||
|
||||
if err != nil {
|
||||
wwlog.Error("%s: Console problem", node.Id.Get())
|
||||
wwlog.Error("%s: Console problem", node.Id())
|
||||
returnErr = err
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
}
|
||||
|
||||
if !SetYes {
|
||||
var nodeList []node.NodeInfo
|
||||
var nodeList []node.NodeConf
|
||||
// The checks run twice in the prompt case.
|
||||
// Avoiding putting in a blocking prompt in an API.
|
||||
nodeList, err = apiNode.NodeDeleteParameterCheck(&ndp, false)
|
||||
|
||||
@@ -20,12 +20,8 @@ var (
|
||||
}
|
||||
|
||||
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
|
||||
nodes := nodeDB.ListAllNodes()
|
||||
return nodes, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
}
|
||||
SetYes bool
|
||||
|
||||
@@ -21,7 +21,7 @@ var (
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
var node_names []string
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
node_names = append(node_names, node.Id())
|
||||
}
|
||||
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
|
||||
@@ -21,7 +21,7 @@ var (
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
var node_names []string
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
node_names = append(node_names, node.Id())
|
||||
}
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
|
||||
@@ -67,10 +67,10 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
if importMap[line[0]] == nil {
|
||||
importMap[line[0]] = new(node.NodeConf)
|
||||
}
|
||||
ok := importMap[line[0]].SetLopt(records[0][j], line[j])
|
||||
if !(ok) {
|
||||
wwlog.Debug("Could not import %s\n", line[j])
|
||||
}
|
||||
// ok := importMap[line[0]].SetLopt(records[0][j], line[j])
|
||||
// if !(ok) {
|
||||
// wwlog.Debug("Could not import %s\n", line[j])
|
||||
// }
|
||||
}
|
||||
}
|
||||
yes := apiutil.ConfirmationPrompt(fmt.Sprintf("Are you sure you want to import %d nodes", len(importMap)))
|
||||
|
||||
@@ -34,7 +34,7 @@ func GetCommand() *cobra.Command {
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
var node_names []string
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
node_names = append(node_names, node.Id())
|
||||
}
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
|
||||
@@ -45,24 +45,24 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
results := make(chan power.IPMI, jobcount)
|
||||
|
||||
for _, node := range nodes {
|
||||
if node.Ipmi.Ipaddr.Get() == "" {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id.Get())
|
||||
if node.Ipmi.Ipaddr.IsUnspecified() {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id())
|
||||
continue
|
||||
}
|
||||
var ipmiInterface = "lan"
|
||||
if node.Ipmi.Interface.Get() != "" {
|
||||
ipmiInterface = node.Ipmi.Interface.Get()
|
||||
if node.Ipmi.Interface != "" {
|
||||
ipmiInterface = node.Ipmi.Interface
|
||||
}
|
||||
var ipmiPort = "623"
|
||||
if node.Ipmi.Port.Get() != "" {
|
||||
ipmiPort = node.Ipmi.Port.Get()
|
||||
if node.Ipmi.Port != "" {
|
||||
ipmiPort = node.Ipmi.Port
|
||||
}
|
||||
ipmiCmd := power.IPMI{
|
||||
NodeName: node.Id.Get(),
|
||||
HostName: node.Ipmi.Ipaddr.Get(),
|
||||
NodeName: node.Id(),
|
||||
HostName: node.Ipmi.Ipaddr.String(),
|
||||
Port: ipmiPort,
|
||||
User: node.Ipmi.UserName.Get(),
|
||||
Password: node.Ipmi.Password.Get(),
|
||||
User: node.Ipmi.UserName,
|
||||
Password: node.Ipmi.Password,
|
||||
Interface: ipmiInterface,
|
||||
AuthType: "MD5",
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ var (
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
var node_names []string
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
node_names = append(node_names, node.Id())
|
||||
}
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
apinode "github.com/warewulf/warewulf/internal/pkg/api/node"
|
||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||
"github.com/warewulf/warewulf/internal/pkg/api/util"
|
||||
"github.com/warewulf/warewulf/internal/pkg/hostlist"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
"gopkg.in/yaml.v2"
|
||||
@@ -15,39 +16,33 @@ import (
|
||||
|
||||
func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err error) {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
// run converters for different types
|
||||
for _, c := range vars.converters {
|
||||
if err := c(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// remove the default network as the all network values are assigned
|
||||
// to this network
|
||||
if !node.ObjectIsEmpty(vars.nodeConf.NetDevs["UNDEF"]) {
|
||||
netDev := *vars.nodeConf.NetDevs["UNDEF"]
|
||||
vars.nodeConf.NetDevs[vars.netName] = &netDev
|
||||
vars.nodeConf.NetDevs[vars.nodeAdd.Net] = &netDev
|
||||
}
|
||||
delete(vars.nodeConf.NetDevs, "UNDEF")
|
||||
if vars.fsName != "" {
|
||||
if !strings.HasPrefix(vars.fsName, "/dev") {
|
||||
if vars.fsName == vars.partName {
|
||||
vars.fsName = "/dev/disk/by-partlabel/" + vars.partName
|
||||
if vars.nodeAdd.FsName != "" {
|
||||
if !strings.HasPrefix(vars.nodeAdd.FsName, "/dev") {
|
||||
if vars.nodeAdd.FsName == vars.nodeAdd.PartName {
|
||||
vars.nodeAdd.FsName = "/dev/disk/by-partlabel/" + vars.nodeAdd.PartName
|
||||
} else {
|
||||
return fmt.Errorf("filesystems need to have a underlying blockdev")
|
||||
}
|
||||
}
|
||||
fs := *vars.nodeConf.FileSystems["UNDEF"]
|
||||
vars.nodeConf.FileSystems[vars.fsName] = &fs
|
||||
vars.nodeConf.FileSystems[vars.nodeAdd.FsName] = &fs
|
||||
}
|
||||
delete(vars.nodeConf.FileSystems, "UNDEF")
|
||||
if vars.diskName != "" && vars.partName != "" {
|
||||
if vars.nodeAdd.DiskName != "" && vars.nodeAdd.PartName != "" {
|
||||
prt := *vars.nodeConf.Disks["UNDEF"].Partitions["UNDEF"]
|
||||
vars.nodeConf.Disks["UNDEF"].Partitions[vars.partName] = &prt
|
||||
vars.nodeConf.Disks["UNDEF"].Partitions[vars.nodeAdd.PartName] = &prt
|
||||
delete(vars.nodeConf.Disks["UNDEF"].Partitions, "UNDEF")
|
||||
dsk := *vars.nodeConf.Disks["UNDEF"]
|
||||
vars.nodeConf.Disks[vars.diskName] = &dsk
|
||||
vars.nodeConf.Disks[vars.nodeAdd.DiskName] = &dsk
|
||||
}
|
||||
if (vars.diskName != "") != (vars.partName != "") {
|
||||
if (vars.nodeAdd.DiskName != "") != (vars.nodeAdd.PartName != "") {
|
||||
return fmt.Errorf("partition and disk must be specified")
|
||||
}
|
||||
delete(vars.nodeConf.Disks, "UNDEF")
|
||||
@@ -56,23 +51,30 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err err
|
||||
return fmt.Errorf("can not marshall nodeInfo: %s", err)
|
||||
}
|
||||
wwlog.Debug("sending following values: %s", string(buffer))
|
||||
set := wwapiv1.NodeSetParameter{
|
||||
NodeConfYaml: string(buffer[:]),
|
||||
args = hostlist.Expand(args)
|
||||
set := wwapiv1.ConfSetParameter{
|
||||
NodeConfYaml: string(buffer),
|
||||
|
||||
NetdevDelete: vars.setNetDevDel,
|
||||
PartitionDelete: vars.setPartDel,
|
||||
DiskDelete: vars.setDiskDel,
|
||||
FilesystemDelete: vars.setFsDel,
|
||||
AllNodes: vars.setNodeAll,
|
||||
NetdevDelete: vars.nodeDel.NetDel,
|
||||
PartitionDelete: vars.nodeDel.PartDel,
|
||||
DiskDelete: vars.nodeDel.DiskDel,
|
||||
FilesystemDelete: vars.nodeDel.FsDel,
|
||||
TagAdd: vars.nodeAdd.TagsAdd,
|
||||
TagDel: vars.nodeDel.TagsDel,
|
||||
NetTagAdd: vars.nodeAdd.NetTagsAdd,
|
||||
NetTagDel: vars.nodeDel.NetTagsDel,
|
||||
IpmiTagAdd: vars.nodeAdd.IpmiTagsAdd,
|
||||
IpmiTagDel: vars.nodeDel.IpmiTagsDel,
|
||||
AllConfs: vars.setNodeAll,
|
||||
Force: vars.setForce,
|
||||
NodeNames: args,
|
||||
ConfList: args,
|
||||
}
|
||||
|
||||
if !vars.setYes {
|
||||
var nodeCount uint
|
||||
// The checks run twice in the prompt case.
|
||||
// Avoiding putting in a blocking prompt in an API.
|
||||
_, nodeCount, err = apinode.NodeSetParameterCheck(&set, false)
|
||||
_, nodeCount, err = apinode.NodeSetParameterCheck(&set)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -11,24 +11,17 @@ import (
|
||||
)
|
||||
|
||||
type variables struct {
|
||||
setNetDevDel string
|
||||
setDiskDel string
|
||||
setPartDel string
|
||||
setFsDel string
|
||||
netName string
|
||||
partName string
|
||||
diskName string
|
||||
fsName string
|
||||
setNodeAll bool
|
||||
setYes bool
|
||||
setForce bool
|
||||
nodeConf node.NodeConf
|
||||
converters []func() error
|
||||
setNodeAll bool
|
||||
setYes bool
|
||||
setForce bool
|
||||
nodeConf node.NodeConf
|
||||
nodeDel node.NodeConfDel
|
||||
nodeAdd node.NodeConfAdd
|
||||
}
|
||||
|
||||
func GetCommand() *cobra.Command {
|
||||
vars := variables{}
|
||||
vars.nodeConf = node.NewConf()
|
||||
vars.nodeConf = node.NewNode("")
|
||||
baseCmd := &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "set [OPTIONS] PATTERN",
|
||||
@@ -43,25 +36,15 @@ func GetCommand() *cobra.Command {
|
||||
}
|
||||
|
||||
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
|
||||
nodes := nodeDB.ListAllNodes()
|
||||
return nodes, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
}
|
||||
|
||||
vars.converters = vars.nodeConf.CreateFlags(baseCmd, []string{})
|
||||
baseCmd.PersistentFlags().StringVarP(&vars.setNetDevDel, "netdel", "D", "", "Delete the node's network device")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.netName, "netname", "default", "Set network name for network options")
|
||||
vars.nodeConf.CreateFlags(baseCmd)
|
||||
vars.nodeAdd.CreateAddFlags(baseCmd)
|
||||
vars.nodeDel.CreateDelFlags(baseCmd)
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.setNodeAll, "all", "a", false, "Set all nodes")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.fsName, "fsname", "", "set the file system name which must match a partition name")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.partName, "partname", "", "set the partition name so it can be used by a file system")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.diskName, "diskname", "", "set disk device name for the partition")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.setDiskDel, "diskdel", "", "delete the disk from the configuration")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.setPartDel, "partdel", "", "delete the partition from the configuration")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.setFsDel, "fsdel", "", "delete the partition from the configuration")
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.setYes, "yes", "y", false, "Set 'yes' to all questions asked")
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.setForce, "force", "f", false, "Force configuration (even on error)")
|
||||
// register the command line completions
|
||||
@@ -94,7 +77,7 @@ func GetCommand() *cobra.Command {
|
||||
nodeDB, _ := node.New()
|
||||
profiles, _ := nodeDB.FindAllProfiles()
|
||||
for _, profile := range profiles {
|
||||
list = append(list, profile.Id.Get())
|
||||
list = append(list, profile.Id())
|
||||
}
|
||||
return list, cobra.ShellCompDirectiveNoFileComp
|
||||
}); err != nil {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||
"github.com/warewulf/warewulf/internal/pkg/hostlist"
|
||||
@@ -19,22 +20,20 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
controller := warewulfconf.Get()
|
||||
nodeDB, err := node.New()
|
||||
if err != nil {
|
||||
wwlog.Error("Could not open node configuration: %s", err)
|
||||
os.Exit(1)
|
||||
return errors.Wrap(err, "couldn't open node configuration")
|
||||
}
|
||||
|
||||
nodes, err := nodeDB.FindAllNodes()
|
||||
db, err := nodeDB.FindAllNodes()
|
||||
if err != nil {
|
||||
wwlog.Error("Could not get node list: %s", err)
|
||||
os.Exit(1)
|
||||
return errors.Wrap(err, "could not get node list")
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
args = hostlist.Expand(args)
|
||||
nodes = node.FilterByName(nodes, args)
|
||||
db = node.FilterByName(db, args)
|
||||
|
||||
if len(nodes) < len(args) {
|
||||
return errors.New("Failed to find nodes")
|
||||
if len(db) < len(args) {
|
||||
return errors.New("failed to find nodes")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,26 +50,23 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
if len(OverlayNames) == 0 {
|
||||
// TODO: should this behave the same as OverlayDir == "", and build default
|
||||
// set to overlays?
|
||||
return errors.New("Must specify overlay(s) to build")
|
||||
return errors.New("must specify overlay(s) to build")
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
if len(nodes) != 1 {
|
||||
return errors.New("Must specify one node to build overlay")
|
||||
if len(db) != 1 {
|
||||
return errors.New("nust specify one node to build overlay")
|
||||
}
|
||||
|
||||
for _, node := range nodes {
|
||||
for _, node := range db {
|
||||
return overlay.BuildOverlayIndir(node, OverlayNames, OverlayDir)
|
||||
}
|
||||
} else {
|
||||
// TODO this seems different than what is set in BuildHostOverlay
|
||||
var host node.NodeInfo
|
||||
var idEntry node.Entry
|
||||
hostname, _ := os.Hostname()
|
||||
wwlog.Info("Building overlay for host: %s", hostname)
|
||||
idEntry.Set(hostname)
|
||||
host.Id = idEntry
|
||||
return overlay.BuildOverlayIndir(host, OverlayNames, OverlayDir)
|
||||
node := node.NewNode(hostname)
|
||||
wwlog.Info("building overlay for host: %s", hostname)
|
||||
return overlay.BuildOverlayIndir(node, OverlayNames, OverlayDir)
|
||||
|
||||
}
|
||||
|
||||
@@ -88,9 +84,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
defer syscall.Umask(oldMask)
|
||||
|
||||
if len(OverlayNames) > 0 {
|
||||
err = overlay.BuildSpecificOverlays(nodes, OverlayNames)
|
||||
err = overlay.BuildSpecificOverlays(db, OverlayNames)
|
||||
} else {
|
||||
err = overlay.BuildAllOverlays(nodes)
|
||||
err = overlay.BuildAllOverlays(db)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -24,7 +24,7 @@ var (
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
var node_names []string
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
node_names = append(node_names, node.Id())
|
||||
}
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
|
||||
@@ -78,12 +78,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var updateNodes []node.NodeInfo
|
||||
var updateNodes []node.NodeConf
|
||||
|
||||
for _, node := range nodes {
|
||||
if node.SystemOverlay.Get() == overlayName {
|
||||
if util.InSlice(node.SystemOverlay, overlayName) {
|
||||
updateNodes = append(updateNodes, node)
|
||||
} else if node.RuntimeOverlay.Get() == overlayName {
|
||||
} else if util.InSlice(node.RuntimeOverlay, overlayName) {
|
||||
updateNodes = append(updateNodes, node)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
wwlog.Output("%s", string(f))
|
||||
} else {
|
||||
if !util.IsFile(overlayFile) {
|
||||
wwlog.Debug("%s is not a file", overlayFile)
|
||||
err := errors.New("Not a file")
|
||||
wwlog.Error("%s: %s:%s", err, overlayName, fileName)
|
||||
return err
|
||||
err := errors.New("Not a file")
|
||||
wwlog.Error("%s: %s:%s", err, overlayName, fileName)
|
||||
return err
|
||||
@@ -56,33 +58,23 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
if filepath.Ext(overlayFile) != ".ww" {
|
||||
wwlog.Warn("%s lacks the '.ww' suffix, will not be rendered in an overlay", fileName)
|
||||
}
|
||||
|
||||
nodeDB, err := node.New()
|
||||
if err != nil {
|
||||
wwlog.Error("Could not open node configuration: %s", err)
|
||||
return err
|
||||
}
|
||||
nodes, err := nodeDB.FindAllNodes()
|
||||
nodeConf, err := nodeDB.GetNode(NodeName)
|
||||
if err == node.ErrNotFound {
|
||||
hostName, err := os.Hostname()
|
||||
if err != nil {
|
||||
wwlog.Error("Could not get host name: %s", err)
|
||||
}
|
||||
nodeConf = node.NewNode(hostName)
|
||||
nodeConf.ClusterName = hostName
|
||||
}
|
||||
tstruct, err := overlay.InitStruct(nodeConf)
|
||||
if err != nil {
|
||||
wwlog.Error("Could not get node list: %s", err)
|
||||
return err
|
||||
}
|
||||
filteredNodes := node.FilterByName(nodes, []string{NodeName})
|
||||
if hostName, err := os.Hostname(); err != nil {
|
||||
wwlog.Error("Could not get host name: %s", err)
|
||||
} else if len(filteredNodes) == 0 && (NodeName == "host" || NodeName == hostName) {
|
||||
// rendering the host template
|
||||
hostNodeInfo := new(node.NodeInfo)
|
||||
hostNodeInfo.Id.Set(hostName)
|
||||
hostNodeInfo.ClusterName.Set(hostName)
|
||||
filteredNodes = append(filteredNodes, *hostNodeInfo)
|
||||
} else if len(filteredNodes) != 1 {
|
||||
err := errors.New("Not a single node")
|
||||
wwlog.Error("%s: %v", err, NodeName)
|
||||
return err
|
||||
}
|
||||
|
||||
tstruct := overlay.InitStruct(&filteredNodes[0])
|
||||
tstruct.BuildSource = overlayFile
|
||||
buffer, backupFile, writeFile, err := overlay.RenderTemplateFile(overlayFile, tstruct)
|
||||
if err != nil {
|
||||
|
||||
@@ -38,7 +38,7 @@ func init() {
|
||||
baseCmd.PersistentFlags().StringVarP(&NodeName, "render", "r", "", "node used for the variables in the template")
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("render", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
nodeDB, _ := node.New()
|
||||
return nodeDB.NodeList(), cobra.ShellCompDirectiveNoFileComp
|
||||
return nodeDB.ListAllNodes(), cobra.ShellCompDirectiveNoFileComp
|
||||
}); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
@@ -43,24 +43,24 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
for _, node := range nodes {
|
||||
|
||||
if node.Ipmi.Ipaddr.Get() == "" {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id.Get())
|
||||
if node.Ipmi.Ipaddr.IsUnspecified() {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id())
|
||||
continue
|
||||
}
|
||||
var ipmiInterface = "lan"
|
||||
if node.Ipmi.Interface.Get() != "" {
|
||||
ipmiInterface = node.Ipmi.Interface.Get()
|
||||
if node.Ipmi.Interface != "" {
|
||||
ipmiInterface = node.Ipmi.Interface
|
||||
}
|
||||
var ipmiPort = "623"
|
||||
if node.Ipmi.Port.Get() != "" {
|
||||
ipmiPort = node.Ipmi.Port.Get()
|
||||
if node.Ipmi.Port != "" {
|
||||
ipmiPort = node.Ipmi.Port
|
||||
}
|
||||
ipmiCmd := power.IPMI{
|
||||
NodeName: node.Id.Get(),
|
||||
HostName: node.Ipmi.Ipaddr.Get(),
|
||||
NodeName: node.Id(),
|
||||
HostName: node.Ipmi.Ipaddr.String(),
|
||||
Port: ipmiPort,
|
||||
User: node.Ipmi.UserName.Get(),
|
||||
Password: node.Ipmi.Password.Get(),
|
||||
User: node.Ipmi.UserName,
|
||||
Password: node.Ipmi.Password,
|
||||
Interface: ipmiInterface,
|
||||
AuthType: "MD5",
|
||||
}
|
||||
|
||||
@@ -43,24 +43,24 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
for _, node := range nodes {
|
||||
|
||||
if node.Ipmi.Ipaddr.Get() == "" {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id.Get())
|
||||
if node.Ipmi.Ipaddr.IsUnspecified() {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id())
|
||||
continue
|
||||
}
|
||||
var ipmiInterface = "lan"
|
||||
if node.Ipmi.Interface.Get() != "" {
|
||||
ipmiInterface = node.Ipmi.Interface.Get()
|
||||
if node.Ipmi.Interface != "" {
|
||||
ipmiInterface = node.Ipmi.Interface
|
||||
}
|
||||
var ipmiPort = "623"
|
||||
if node.Ipmi.Port.Get() != "" {
|
||||
ipmiPort = node.Ipmi.Port.Get()
|
||||
if node.Ipmi.Port != "" {
|
||||
ipmiPort = node.Ipmi.Port
|
||||
}
|
||||
ipmiCmd := power.IPMI{
|
||||
NodeName: node.Id.Get(),
|
||||
HostName: node.Ipmi.Ipaddr.Get(),
|
||||
NodeName: node.Id(),
|
||||
HostName: node.Ipmi.Ipaddr.String(),
|
||||
Port: ipmiPort,
|
||||
User: node.Ipmi.UserName.Get(),
|
||||
Password: node.Ipmi.Password.Get(),
|
||||
User: node.Ipmi.UserName,
|
||||
Password: node.Ipmi.Password,
|
||||
Interface: ipmiInterface,
|
||||
AuthType: "MD5",
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ var (
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
var node_names []string
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
node_names = append(node_names, node.Id())
|
||||
}
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
|
||||
@@ -43,24 +43,24 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
for _, node := range nodes {
|
||||
|
||||
if node.Ipmi.Ipaddr.Get() == "" {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id.Get())
|
||||
if node.Ipmi.Ipaddr.IsUnspecified() {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id())
|
||||
continue
|
||||
}
|
||||
var ipmiInterface = "lan"
|
||||
if node.Ipmi.Interface.Get() != "" {
|
||||
ipmiInterface = node.Ipmi.Interface.Get()
|
||||
if node.Ipmi.Interface != "" {
|
||||
ipmiInterface = node.Ipmi.Interface
|
||||
}
|
||||
var ipmiPort = "623"
|
||||
if node.Ipmi.Port.Get() != "" {
|
||||
ipmiPort = node.Ipmi.Port.Get()
|
||||
if node.Ipmi.Port != "" {
|
||||
ipmiPort = node.Ipmi.Port
|
||||
}
|
||||
ipmiCmd := power.IPMI{
|
||||
NodeName: node.Id.Get(),
|
||||
HostName: node.Ipmi.Ipaddr.Get(),
|
||||
NodeName: node.Id(),
|
||||
HostName: node.Ipmi.Ipaddr.String(),
|
||||
Port: ipmiPort,
|
||||
User: node.Ipmi.UserName.Get(),
|
||||
Password: node.Ipmi.Password.Get(),
|
||||
User: node.Ipmi.UserName,
|
||||
Password: node.Ipmi.Password,
|
||||
Interface: ipmiInterface,
|
||||
AuthType: "MD5",
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ var (
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
var node_names []string
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
node_names = append(node_names, node.Id())
|
||||
}
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
|
||||
@@ -43,24 +43,24 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
for _, node := range nodes {
|
||||
|
||||
if node.Ipmi.Ipaddr.Get() == "" {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id.Get())
|
||||
if node.Ipmi.Ipaddr.IsUnspecified() {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id())
|
||||
continue
|
||||
}
|
||||
var ipmiInterface = "lan"
|
||||
if node.Ipmi.Interface.Get() != "" {
|
||||
ipmiInterface = node.Ipmi.Interface.Get()
|
||||
if node.Ipmi.Interface != "" {
|
||||
ipmiInterface = node.Ipmi.Interface
|
||||
}
|
||||
var ipmiPort = "623"
|
||||
if node.Ipmi.Port.Get() != "" {
|
||||
ipmiPort = node.Ipmi.Port.Get()
|
||||
if node.Ipmi.Port != "" {
|
||||
ipmiPort = node.Ipmi.Port
|
||||
}
|
||||
ipmiCmd := power.IPMI{
|
||||
NodeName: node.Id.Get(),
|
||||
HostName: node.Ipmi.Ipaddr.Get(),
|
||||
NodeName: node.Id(),
|
||||
HostName: node.Ipmi.Ipaddr.String(),
|
||||
Port: ipmiPort,
|
||||
User: node.Ipmi.UserName.Get(),
|
||||
Password: node.Ipmi.Password.Get(),
|
||||
User: node.Ipmi.UserName,
|
||||
Password: node.Ipmi.Password,
|
||||
Interface: ipmiInterface,
|
||||
AuthType: "MD5",
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ var (
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
var node_names []string
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
node_names = append(node_names, node.Id())
|
||||
}
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
|
||||
@@ -43,24 +43,24 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
for _, node := range nodes {
|
||||
|
||||
if node.Ipmi.Ipaddr.Get() == "" {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id.Get())
|
||||
if node.Ipmi.Ipaddr.IsUnspecified() {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id())
|
||||
continue
|
||||
}
|
||||
var ipmiInterface = "lan"
|
||||
if node.Ipmi.Interface.Get() != "" {
|
||||
ipmiInterface = node.Ipmi.Interface.Get()
|
||||
if node.Ipmi.Interface != "" {
|
||||
ipmiInterface = node.Ipmi.Interface
|
||||
}
|
||||
var ipmiPort = "623"
|
||||
if node.Ipmi.Port.Get() != "" {
|
||||
ipmiPort = node.Ipmi.Port.Get()
|
||||
if node.Ipmi.Port != "" {
|
||||
ipmiPort = node.Ipmi.Port
|
||||
}
|
||||
ipmiCmd := power.IPMI{
|
||||
NodeName: node.Id.Get(),
|
||||
HostName: node.Ipmi.Ipaddr.Get(),
|
||||
NodeName: node.Id(),
|
||||
HostName: node.Ipmi.Ipaddr.String(),
|
||||
Port: ipmiPort,
|
||||
User: node.Ipmi.UserName.Get(),
|
||||
Password: node.Ipmi.Password.Get(),
|
||||
User: node.Ipmi.UserName,
|
||||
Password: node.Ipmi.Password,
|
||||
Interface: ipmiInterface,
|
||||
AuthType: "MD5",
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ var (
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
var node_names []string
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
node_names = append(node_names, node.Id())
|
||||
}
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
|
||||
@@ -43,24 +43,24 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
for _, node := range nodes {
|
||||
|
||||
if node.Ipmi.Ipaddr.Get() == "" {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id.Get())
|
||||
if node.Ipmi.Ipaddr.IsUnspecified() {
|
||||
wwlog.Error("%s: No IPMI IP address", node.Id())
|
||||
continue
|
||||
}
|
||||
var ipmiInterface = "lan"
|
||||
if node.Ipmi.Interface.Get() != "" {
|
||||
ipmiInterface = node.Ipmi.Interface.Get()
|
||||
if node.Ipmi.Interface != "" {
|
||||
ipmiInterface = node.Ipmi.Interface
|
||||
}
|
||||
var ipmiPort = "623"
|
||||
if node.Ipmi.Port.Get() != "" {
|
||||
ipmiPort = node.Ipmi.Port.Get()
|
||||
if node.Ipmi.Port != "" {
|
||||
ipmiPort = node.Ipmi.Port
|
||||
}
|
||||
ipmiCmd := power.IPMI{
|
||||
NodeName: node.Id.Get(),
|
||||
HostName: node.Ipmi.Ipaddr.Get(),
|
||||
NodeName: node.Id(),
|
||||
HostName: node.Ipmi.Ipaddr.String(),
|
||||
Port: ipmiPort,
|
||||
User: node.Ipmi.UserName.Get(),
|
||||
Password: node.Ipmi.Password.Get(),
|
||||
User: node.Ipmi.UserName,
|
||||
Password: node.Ipmi.Password,
|
||||
Interface: ipmiInterface,
|
||||
AuthType: "MD5",
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ var (
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
var node_names []string
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
node_names = append(node_names, node.Id())
|
||||
}
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
|
||||
@@ -2,7 +2,6 @@ package add
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
apiprofile "github.com/warewulf/warewulf/internal/pkg/api/profile"
|
||||
@@ -12,24 +11,10 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||
"github.com/warewulf/warewulf/internal/pkg/api/util"
|
||||
)
|
||||
|
||||
func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err error) {
|
||||
return func(cmd *cobra.Command, args []string) (err error) {
|
||||
// run converters for different types
|
||||
for _, c := range vars.Converters {
|
||||
if err := c(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// remove the default network as the all network values are assigned
|
||||
// to this network
|
||||
if vars.netName != "" {
|
||||
netDev := *vars.profileConf.NetDevs["UNDEF"]
|
||||
vars.profileConf.NetDevs[vars.netName] = &netDev
|
||||
delete(vars.profileConf.NetDevs, "UNDEF")
|
||||
}
|
||||
// remove the UNDEF network as all network values are assigned
|
||||
// to this network
|
||||
if !node.ObjectIsEmpty(vars.profileConf.NetDevs["UNDEF"]) {
|
||||
@@ -60,33 +45,16 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err err
|
||||
return fmt.Errorf("partition and disk must be specified")
|
||||
}
|
||||
delete(vars.profileConf.Disks, "UNDEF")
|
||||
|
||||
buffer, err := yaml.Marshal(vars.profileConf)
|
||||
if err != nil {
|
||||
wwlog.Error("Cant marshall nodeInfo", err)
|
||||
os.Exit(1)
|
||||
wwlog.Error("Can't marshall nodeInfo", err)
|
||||
return err
|
||||
}
|
||||
set := wwapiv1.ProfileSetParameter{
|
||||
set := wwapiv1.NodeAddParameter{
|
||||
NodeConfYaml: string(buffer[:]),
|
||||
NetdevDelete: vars.SetNetDevDel,
|
||||
AllProfiles: vars.SetNodeAll,
|
||||
Force: vars.SetForce,
|
||||
ProfileNames: args,
|
||||
NodeNames: args,
|
||||
Force: true,
|
||||
}
|
||||
|
||||
if !vars.SetYes {
|
||||
// The checks run twice in the prompt case.
|
||||
// Avoiding putting in a blocking prompt in an API.
|
||||
_, _, err = apiprofile.ProfileSetParameterCheck(&set, false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
yes := util.ConfirmationPrompt(fmt.Sprintf("Are you sure you add the profile %s", args))
|
||||
if !yes {
|
||||
return
|
||||
}
|
||||
}
|
||||
return apiprofile.AddProfile(&set)
|
||||
return apiprofile.ProfileAdd(&set)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,12 @@ type variables struct {
|
||||
fsName string
|
||||
partName string
|
||||
diskName string
|
||||
ProfileConf node.NodeConf
|
||||
Converters []func() error
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
vars := variables{}
|
||||
vars.profileConf = node.NewConf()
|
||||
vars.profileConf = node.NewNode("")
|
||||
baseCmd := &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "add PROFILE",
|
||||
@@ -37,8 +35,7 @@ func GetCommand() *cobra.Command {
|
||||
RunE: CobraRunE(&vars),
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
vars.Converters = vars.profileConf.CreateFlags(baseCmd,
|
||||
[]string{"ipaddr", "ipaddr6", "ipmiaddr", "profile"})
|
||||
vars.profileConf.CreateFlags(baseCmd)
|
||||
baseCmd.PersistentFlags().StringVar(&vars.netName, "netname", "", "Set network name for network options")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.fsName, "fsname", "", "set the file system name which must match a partition name")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.partName, "partname", "", "set the partition name so it can be used by a file system")
|
||||
|
||||
@@ -29,21 +29,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
wwlog.Error("Could not load all profiles: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, r := range args {
|
||||
for _, p := range profiles {
|
||||
if p.Id.Get() == r {
|
||||
if p.Id() == r {
|
||||
nodes, err := nodeDB.FindAllNodes()
|
||||
if err != nil {
|
||||
wwlog.Error("Could not load all nodes: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, n := range nodes {
|
||||
for _, np := range n.Profiles.GetSlice() {
|
||||
for i, np := range n.Profiles {
|
||||
if np == r {
|
||||
wwlog.Verbose("Removing profile from node %s: %s", n.Id.Get(), r)
|
||||
n.Profiles.SliceRemoveElement(r)
|
||||
err := nodeDB.NodeUpdate(n)
|
||||
wwlog.Verbose("Removing profile from node %s: %s", n.Id(), r)
|
||||
n.Profiles = append(n.Profiles[:i], n.Profiles[i+1:]...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to update node")
|
||||
}
|
||||
@@ -57,7 +55,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
for _, r := range args {
|
||||
var found bool
|
||||
for _, p := range profiles {
|
||||
if p.Id.Get() == r {
|
||||
if p.Id() == r {
|
||||
count++
|
||||
found = true
|
||||
err := nodeDB.DelProfile(r)
|
||||
@@ -68,13 +66,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if !found {
|
||||
fmt.Fprintf(os.Stderr, "Profile not found: %s\n", r)
|
||||
wwlog.Warn("Profile not found: %s", r)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if count == 0 {
|
||||
fmt.Fprintf(os.Stderr, "No profiles found\n")
|
||||
os.Exit(1)
|
||||
wwlog.Warn("No profiles found")
|
||||
return nil
|
||||
}
|
||||
|
||||
if SetYes {
|
||||
@@ -83,10 +82,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
return errors.Wrap(err, "failed to persist nodedb")
|
||||
}
|
||||
} else {
|
||||
q := fmt.Sprintf("Are you sure you want to delete %d profile(s)", count)
|
||||
|
||||
prompt := promptui.Prompt{
|
||||
Label: q,
|
||||
Label: fmt.Sprintf("Are you sure you want to delete %d profile(s)", count),
|
||||
IsConfirm: true,
|
||||
}
|
||||
|
||||
|
||||
@@ -19,12 +19,7 @@ var (
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
nodeDB, _ := node.New()
|
||||
profiles, _ := nodeDB.FindAllProfiles()
|
||||
var p_names []string
|
||||
for _, profile := range profiles {
|
||||
p_names = append(p_names, profile.Id.Get())
|
||||
}
|
||||
return p_names, cobra.ShellCompDirectiveNoFileComp
|
||||
return nodeDB.ListAllProfiles(), cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
}
|
||||
SetYes bool
|
||||
|
||||
@@ -20,7 +20,7 @@ var (
|
||||
profiles, _ := nodeDB.FindAllProfiles()
|
||||
var p_names []string
|
||||
for _, profile := range profiles {
|
||||
p_names = append(p_names, profile.Id.Get())
|
||||
p_names = append(p_names, profile.Id())
|
||||
}
|
||||
return p_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
|
||||
@@ -27,7 +27,6 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err err
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if len(profileInfo.Output) > 0 {
|
||||
if vars.showYaml || vars.showJson {
|
||||
wwlog.Info(profileInfo.Output[0])
|
||||
|
||||
@@ -21,7 +21,7 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err err
|
||||
// to this network
|
||||
if !node.ObjectIsEmpty(vars.profileConf.NetDevs["UNDEF"]) {
|
||||
netDev := *vars.profileConf.NetDevs["UNDEF"]
|
||||
vars.profileConf.NetDevs[vars.netName] = &netDev
|
||||
vars.profileConf.NetDevs[vars.profileAdd.Net] = &netDev
|
||||
}
|
||||
delete(vars.profileConf.NetDevs, "UNDEF")
|
||||
if vars.fsName != "" {
|
||||
@@ -53,22 +53,29 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err err
|
||||
os.Exit(1)
|
||||
}
|
||||
wwlog.Debug("sending following values: %s", string(buffer))
|
||||
set := wwapiv1.ProfileSetParameter{
|
||||
set := wwapiv1.ConfSetParameter{
|
||||
NodeConfYaml: string(buffer[:]),
|
||||
NetdevDelete: vars.setNetDevDel,
|
||||
PartitionDelete: vars.setPartDel,
|
||||
DiskDelete: vars.setDiskDel,
|
||||
FilesystemDelete: vars.setFsDel,
|
||||
AllProfiles: vars.setNodeAll,
|
||||
Force: vars.setForce,
|
||||
ProfileNames: args,
|
||||
TagAdd: vars.profileAdd.TagsAdd,
|
||||
TagDel: vars.profileDel.TagsDel,
|
||||
NetTagAdd: vars.profileAdd.NetTagsAdd,
|
||||
NetTagDel: vars.profileDel.NetTagsDel,
|
||||
IpmiTagAdd: vars.profileAdd.IpmiTagsAdd,
|
||||
IpmiTagDel: vars.profileDel.IpmiTagsDel,
|
||||
|
||||
AllConfs: vars.setNodeAll,
|
||||
Force: vars.setForce,
|
||||
ConfList: args,
|
||||
}
|
||||
|
||||
if !vars.setYes {
|
||||
var profileCount uint
|
||||
// The checks run twice in the prompt case.
|
||||
// Avoiding putting in a blocking prompt in an API.
|
||||
_, profileCount, err = apiprofile.ProfileSetParameterCheck(&set, false)
|
||||
_, profileCount, err = apiprofile.ProfileSetParameterCheck(&set)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -18,17 +18,17 @@ type variables struct {
|
||||
setNodeAll bool
|
||||
setYes bool
|
||||
setForce bool
|
||||
netName string
|
||||
partName string
|
||||
diskName string
|
||||
fsName string
|
||||
profileConf node.NodeConf
|
||||
converters []func() error
|
||||
profileDel node.NodeConfDel
|
||||
profileAdd node.NodeConfAdd
|
||||
}
|
||||
|
||||
func GetCommand() *cobra.Command {
|
||||
vars := variables{}
|
||||
vars.profileConf = node.NewConf()
|
||||
vars.profileConf = node.NewNode("")
|
||||
|
||||
baseCmd := &cobra.Command{
|
||||
Use: "set [OPTIONS] [PROFILE ...]",
|
||||
@@ -44,28 +44,14 @@ func GetCommand() *cobra.Command {
|
||||
}
|
||||
|
||||
nodeDB, _ := node.New()
|
||||
profiles, _ := nodeDB.FindAllProfiles()
|
||||
var p_names []string
|
||||
for _, profile := range profiles {
|
||||
p_names = append(p_names, profile.Id.Get())
|
||||
}
|
||||
return p_names, cobra.ShellCompDirectiveNoFileComp
|
||||
profiles := nodeDB.ListAllProfiles()
|
||||
return profiles, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
}
|
||||
vars.profileConf = node.NewConf()
|
||||
vars.converters = vars.profileConf.CreateFlags(baseCmd,
|
||||
[]string{"ipaddr", "ipaddr6", "ipmiaddr", "profile"})
|
||||
baseCmd.PersistentFlags().StringVar(&vars.netName, "netname", "default", "Set network name for network options")
|
||||
baseCmd.PersistentFlags().StringVarP(&vars.setNetDevDel, "netdel", "D", "", "Delete the node's network device")
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.setNodeAll, "all", "a", false, "Set all nodes")
|
||||
vars.profileConf.CreateFlags(baseCmd)
|
||||
vars.profileDel.CreateDelFlags(baseCmd)
|
||||
vars.profileAdd.CreateAddFlags(baseCmd)
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.setYes, "yes", "y", false, "Set 'yes' to all questions asked")
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.setForce, "force", "f", false, "Force configuration (even on error)")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.fsName, "fsname", "", "set the file system name which must match a partition name")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.partName, "partname", "", "set the partition name so it can be used by a file system")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.diskName, "diskname", "", "set disk device name for the partition")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.setDiskDel, "diskdel", "", "delete the disk from the configuration")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.setPartDel, "partdel", "", "delete the partition from the configuration")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.setFsDel, "fsdel", "", "delete the from the configuration")
|
||||
// register the command line completions
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("container", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
list, _ := container.ListSources()
|
||||
|
||||
@@ -41,24 +41,24 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
for _, node := range nodes {
|
||||
var primaryNet string
|
||||
for netName := range node.NetDevs {
|
||||
if node.NetDevs[netName].Primary.GetB() {
|
||||
if node.NetDevs[netName].Primary() {
|
||||
primaryNet = netName
|
||||
break
|
||||
}
|
||||
}
|
||||
if primaryNet == "" {
|
||||
wwlog.Error("%s: Primary network device doesn't exist\n", node.Id.Get())
|
||||
wwlog.Error("%s: Primary network device doesn't exist\n", node.Id())
|
||||
continue
|
||||
}
|
||||
if node.NetDevs[primaryNet].Ipaddr.Get() == "" {
|
||||
wwlog.Error("%s: Primary network IP address not configured\n", node.Id.Get())
|
||||
if node.NetDevs[primaryNet].Ipaddr.IsUnspecified() {
|
||||
wwlog.Error("%s: Primary network IP address not configured\n", node.Id())
|
||||
continue
|
||||
}
|
||||
|
||||
nodename := node.Id.Print()
|
||||
nodename := node.Id()
|
||||
var command []string
|
||||
|
||||
command = append(command, node.NetDevs[primaryNet].Ipaddr.Get())
|
||||
command = append(command, node.NetDevs[primaryNet].Ipaddr.String())
|
||||
command = append(command, args[1:]...)
|
||||
|
||||
batchpool.Submit(func() {
|
||||
|
||||
@@ -22,7 +22,7 @@ var (
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
var node_names []string
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
node_names = append(node_names, node.Id())
|
||||
}
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user