diff --git a/internal/app/wwctl/container/exec/child/main.go b/internal/app/wwctl/container/exec/child/main.go index c8cd5b8c..bfd500b4 100644 --- a/internal/app/wwctl/container/exec/child/main.go +++ b/internal/app/wwctl/container/exec/child/main.go @@ -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) diff --git a/internal/app/wwctl/genconf/dfaults/main.go b/internal/app/wwctl/genconf/dfaults/main.go deleted file mode 100644 index 97fe6991..00000000 --- a/internal/app/wwctl/genconf/dfaults/main.go +++ /dev/null @@ -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 -} diff --git a/internal/app/wwctl/genconf/dfaults/root.go b/internal/app/wwctl/genconf/dfaults/root.go deleted file mode 100644 index 9eadd58a..00000000 --- a/internal/app/wwctl/genconf/dfaults/root.go +++ /dev/null @@ -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 -} diff --git a/internal/app/wwctl/genconf/root.go b/internal/app/wwctl/genconf/root.go index e4df72a4..4a1e2544 100644 --- a/internal/app/wwctl/genconf/root.go +++ b/internal/app/wwctl/genconf/root.go @@ -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()) } diff --git a/internal/app/wwctl/helper/printhelper.go b/internal/app/wwctl/helper/printhelper.go index ada9d5fd..c86c7b1d 100644 --- a/internal/app/wwctl/helper/printhelper.go +++ b/internal/app/wwctl/helper/printhelper.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/olekukonko/tablewriter" + "github.com/warewulf/warewulf/internal/pkg/wwlog" ) type PrintHelper struct { diff --git a/internal/app/wwctl/kernel/delete/main.go b/internal/app/wwctl/kernel/delete/main.go index 86ea69a0..8ce35cbc 100644 --- a/internal/app/wwctl/kernel/delete/main.go +++ b/internal/app/wwctl/kernel/delete/main.go @@ -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 } diff --git a/internal/app/wwctl/kernel/imprt/main.go b/internal/app/wwctl/kernel/imprt/main.go index 55fd57f7..fc81bc7f 100644 --- a/internal/app/wwctl/kernel/imprt/main.go +++ b/internal/app/wwctl/kernel/imprt/main.go @@ -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() diff --git a/internal/app/wwctl/kernel/list/main.go b/internal/app/wwctl/kernel/list/main.go index 0d5022d6..831e3e82 100644 --- a/internal/app/wwctl/kernel/list/main.go +++ b/internal/app/wwctl/kernel/list/main.go @@ -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") diff --git a/internal/app/wwctl/node/add/main.go b/internal/app/wwctl/node/add/main.go index 4490d510..4a7bf298 100644 --- a/internal/app/wwctl/node/add/main.go +++ b/internal/app/wwctl/node/add/main.go @@ -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) diff --git a/internal/app/wwctl/node/add/root.go b/internal/app/wwctl/node/add/root.go index 9f37cf0e..5f462cf3 100644 --- a/internal/app/wwctl/node/add/root.go +++ b/internal/app/wwctl/node/add/root.go @@ -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 { diff --git a/internal/app/wwctl/node/console/main.go b/internal/app/wwctl/node/console/main.go index fe1c99d3..5d4686da 100644 --- a/internal/app/wwctl/node/console/main.go +++ b/internal/app/wwctl/node/console/main.go @@ -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 } diff --git a/internal/app/wwctl/node/delete/main.go b/internal/app/wwctl/node/delete/main.go index 9e0d43e4..40ad2554 100644 --- a/internal/app/wwctl/node/delete/main.go +++ b/internal/app/wwctl/node/delete/main.go @@ -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) diff --git a/internal/app/wwctl/node/delete/root.go b/internal/app/wwctl/node/delete/root.go index 7c3f99b1..2f8d7472 100644 --- a/internal/app/wwctl/node/delete/root.go +++ b/internal/app/wwctl/node/delete/root.go @@ -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 diff --git a/internal/app/wwctl/node/edit/root.go b/internal/app/wwctl/node/edit/root.go index 86958d33..66848c8e 100644 --- a/internal/app/wwctl/node/edit/root.go +++ b/internal/app/wwctl/node/edit/root.go @@ -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 diff --git a/internal/app/wwctl/node/export/root.go b/internal/app/wwctl/node/export/root.go index 65f31e65..e8f36419 100644 --- a/internal/app/wwctl/node/export/root.go +++ b/internal/app/wwctl/node/export/root.go @@ -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 }, diff --git a/internal/app/wwctl/node/imprt/main.go b/internal/app/wwctl/node/imprt/main.go index 50eab1d5..6ba9b793 100644 --- a/internal/app/wwctl/node/imprt/main.go +++ b/internal/app/wwctl/node/imprt/main.go @@ -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))) diff --git a/internal/app/wwctl/node/list/root.go b/internal/app/wwctl/node/list/root.go index 7447687a..05576105 100644 --- a/internal/app/wwctl/node/list/root.go +++ b/internal/app/wwctl/node/list/root.go @@ -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 }, diff --git a/internal/app/wwctl/node/sensors/main.go b/internal/app/wwctl/node/sensors/main.go index d4427804..08f31d40 100644 --- a/internal/app/wwctl/node/sensors/main.go +++ b/internal/app/wwctl/node/sensors/main.go @@ -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", } diff --git a/internal/app/wwctl/node/sensors/root.go b/internal/app/wwctl/node/sensors/root.go index 63c794fa..e67f48eb 100644 --- a/internal/app/wwctl/node/sensors/root.go +++ b/internal/app/wwctl/node/sensors/root.go @@ -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 }, diff --git a/internal/app/wwctl/node/set/main.go b/internal/app/wwctl/node/set/main.go index f3e76a80..e988cb45 100644 --- a/internal/app/wwctl/node/set/main.go +++ b/internal/app/wwctl/node/set/main.go @@ -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 } diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index b966a272..3e016e2a 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -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 { diff --git a/internal/app/wwctl/overlay/build/main.go b/internal/app/wwctl/overlay/build/main.go index 3f155350..fc867e18 100644 --- a/internal/app/wwctl/overlay/build/main.go +++ b/internal/app/wwctl/overlay/build/main.go @@ -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 { diff --git a/internal/app/wwctl/overlay/build/root.go b/internal/app/wwctl/overlay/build/root.go index 5ed2e3e1..e5adbc7b 100644 --- a/internal/app/wwctl/overlay/build/root.go +++ b/internal/app/wwctl/overlay/build/root.go @@ -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 }, diff --git a/internal/app/wwctl/overlay/imprt/main.go b/internal/app/wwctl/overlay/imprt/main.go index 1c559d70..dd2bc9ee 100644 --- a/internal/app/wwctl/overlay/imprt/main.go +++ b/internal/app/wwctl/overlay/imprt/main.go @@ -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) } } diff --git a/internal/app/wwctl/overlay/show/main.go b/internal/app/wwctl/overlay/show/main.go index 00fba29e..c64cd730 100644 --- a/internal/app/wwctl/overlay/show/main.go +++ b/internal/app/wwctl/overlay/show/main.go @@ -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 { diff --git a/internal/app/wwctl/overlay/show/root.go b/internal/app/wwctl/overlay/show/root.go index 3ff6d4d1..62464ef8 100644 --- a/internal/app/wwctl/overlay/show/root.go +++ b/internal/app/wwctl/overlay/show/root.go @@ -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) } diff --git a/internal/app/wwctl/power/cycle/main.go b/internal/app/wwctl/power/cycle/main.go index 16633f49..18894b3b 100644 --- a/internal/app/wwctl/power/cycle/main.go +++ b/internal/app/wwctl/power/cycle/main.go @@ -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", } diff --git a/internal/app/wwctl/power/off/main.go b/internal/app/wwctl/power/off/main.go index e9e62e95..28bf4924 100644 --- a/internal/app/wwctl/power/off/main.go +++ b/internal/app/wwctl/power/off/main.go @@ -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", } diff --git a/internal/app/wwctl/power/off/root.go b/internal/app/wwctl/power/off/root.go index de51baff..004ad427 100644 --- a/internal/app/wwctl/power/off/root.go +++ b/internal/app/wwctl/power/off/root.go @@ -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 }, diff --git a/internal/app/wwctl/power/on/main.go b/internal/app/wwctl/power/on/main.go index a8f2d0f6..c660d936 100644 --- a/internal/app/wwctl/power/on/main.go +++ b/internal/app/wwctl/power/on/main.go @@ -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", } diff --git a/internal/app/wwctl/power/on/root.go b/internal/app/wwctl/power/on/root.go index 0b1a686f..42c0ebf4 100644 --- a/internal/app/wwctl/power/on/root.go +++ b/internal/app/wwctl/power/on/root.go @@ -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 }, diff --git a/internal/app/wwctl/power/reset/main.go b/internal/app/wwctl/power/reset/main.go index b92f4c9a..1bbeb87b 100644 --- a/internal/app/wwctl/power/reset/main.go +++ b/internal/app/wwctl/power/reset/main.go @@ -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", } diff --git a/internal/app/wwctl/power/reset/root.go b/internal/app/wwctl/power/reset/root.go index 20d2907c..7be3abdf 100644 --- a/internal/app/wwctl/power/reset/root.go +++ b/internal/app/wwctl/power/reset/root.go @@ -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 }, diff --git a/internal/app/wwctl/power/soft/main.go b/internal/app/wwctl/power/soft/main.go index eca97565..52e785c6 100644 --- a/internal/app/wwctl/power/soft/main.go +++ b/internal/app/wwctl/power/soft/main.go @@ -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", } diff --git a/internal/app/wwctl/power/soft/root.go b/internal/app/wwctl/power/soft/root.go index c06ae6db..791aa0e0 100644 --- a/internal/app/wwctl/power/soft/root.go +++ b/internal/app/wwctl/power/soft/root.go @@ -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 }, diff --git a/internal/app/wwctl/power/status/main.go b/internal/app/wwctl/power/status/main.go index 4e72da18..af95dc20 100644 --- a/internal/app/wwctl/power/status/main.go +++ b/internal/app/wwctl/power/status/main.go @@ -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", } diff --git a/internal/app/wwctl/power/status/root.go b/internal/app/wwctl/power/status/root.go index ef66a388..4fda726c 100644 --- a/internal/app/wwctl/power/status/root.go +++ b/internal/app/wwctl/power/status/root.go @@ -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 }, diff --git a/internal/app/wwctl/profile/add/main.go b/internal/app/wwctl/profile/add/main.go index dd07d99d..80e7e3ad 100644 --- a/internal/app/wwctl/profile/add/main.go +++ b/internal/app/wwctl/profile/add/main.go @@ -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) } } diff --git a/internal/app/wwctl/profile/add/root.go b/internal/app/wwctl/profile/add/root.go index 553806c8..c40fa684 100644 --- a/internal/app/wwctl/profile/add/root.go +++ b/internal/app/wwctl/profile/add/root.go @@ -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") diff --git a/internal/app/wwctl/profile/delete/main.go b/internal/app/wwctl/profile/delete/main.go index 06b2cc75..e8d8cb97 100644 --- a/internal/app/wwctl/profile/delete/main.go +++ b/internal/app/wwctl/profile/delete/main.go @@ -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, } diff --git a/internal/app/wwctl/profile/delete/root.go b/internal/app/wwctl/profile/delete/root.go index 4f96882f..7d30b979 100644 --- a/internal/app/wwctl/profile/delete/root.go +++ b/internal/app/wwctl/profile/delete/root.go @@ -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 diff --git a/internal/app/wwctl/profile/edit/root.go b/internal/app/wwctl/profile/edit/root.go index 177bd14e..79936a34 100644 --- a/internal/app/wwctl/profile/edit/root.go +++ b/internal/app/wwctl/profile/edit/root.go @@ -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 }, diff --git a/internal/app/wwctl/profile/list/main.go b/internal/app/wwctl/profile/list/main.go index a8367027..e2bba3d9 100644 --- a/internal/app/wwctl/profile/list/main.go +++ b/internal/app/wwctl/profile/list/main.go @@ -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]) diff --git a/internal/app/wwctl/profile/set/main.go b/internal/app/wwctl/profile/set/main.go index 8ccb00d8..a22c58af 100644 --- a/internal/app/wwctl/profile/set/main.go +++ b/internal/app/wwctl/profile/set/main.go @@ -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 } diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index 2c95e5a7..896ba7b4 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -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() diff --git a/internal/app/wwctl/ssh/main.go b/internal/app/wwctl/ssh/main.go index 8e248058..e91302a5 100644 --- a/internal/app/wwctl/ssh/main.go +++ b/internal/app/wwctl/ssh/main.go @@ -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() { diff --git a/internal/app/wwctl/ssh/root.go b/internal/app/wwctl/ssh/root.go index ed0f9088..fc36838c 100644 --- a/internal/app/wwctl/ssh/root.go +++ b/internal/app/wwctl/ssh/root.go @@ -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 },