From 0665d5dc8821ceee7e15e3ebf6fb26aeeb11ebed Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Fri, 25 Oct 2024 14:17:00 -0600 Subject: [PATCH] Refactor node Signed-off-by: Jonathon Anderson --- internal/app/wwctl/node/add/root.go | 2 +- internal/app/wwctl/node/delete/main.go | 2 +- internal/app/wwctl/node/edit/main.go | 6 +-- internal/app/wwctl/node/imprt/main.go | 4 +- internal/app/wwctl/node/list/main_test.go | 3 ++ internal/app/wwctl/node/set/root.go | 2 +- internal/app/wwctl/overlay/imprt/main.go | 2 +- internal/app/wwctl/profile/add/main_test.go | 4 +- internal/app/wwctl/profile/add/root.go | 9 +---- internal/app/wwctl/profile/edit/main.go | 6 +-- internal/app/wwctl/profile/set/root.go | 2 +- internal/pkg/api/node/delete.go | 4 +- internal/pkg/api/node/edit.go | 2 +- internal/pkg/api/node/set.go | 2 +- internal/pkg/api/profile/edit.go | 2 +- internal/pkg/api/profile/list.go | 4 +- internal/pkg/api/profile/set.go | 2 +- internal/pkg/node/checkconf.go | 8 ++-- internal/pkg/node/constructors.go | 22 +++++------ internal/pkg/node/constuctors_test.go | 2 +- internal/pkg/node/datastructure.go | 22 +++++------ internal/pkg/node/flags.go | 4 +- internal/pkg/node/ignition.go | 4 +- internal/pkg/node/list.go | 4 +- internal/pkg/node/methods.go | 42 ++++++++++----------- internal/pkg/node/methods_test.go | 4 +- internal/pkg/node/modifiers.go | 8 ++-- internal/pkg/node/util.go | 14 +++---- internal/pkg/overlay/datastructure.go | 10 ++--- internal/pkg/overlay/funcmap.go | 2 +- internal/pkg/overlay/overlay.go | 8 ++-- internal/pkg/overlay/overlay_test.go | 4 +- internal/pkg/warewulfd/nodedb.go | 2 +- internal/pkg/warewulfd/provision.go | 2 +- internal/pkg/warewulfd/util.go | 6 +-- 35 files changed, 112 insertions(+), 114 deletions(-) diff --git a/internal/app/wwctl/node/add/root.go b/internal/app/wwctl/node/add/root.go index 4fb7e5e8..4626e325 100644 --- a/internal/app/wwctl/node/add/root.go +++ b/internal/app/wwctl/node/add/root.go @@ -12,7 +12,7 @@ import ( // Holds the variables which are needed in CobraRunE type variables struct { - nodeConf node.NodeConf + nodeConf node.Node nodeAdd node.NodeConfAdd } diff --git a/internal/app/wwctl/node/delete/main.go b/internal/app/wwctl/node/delete/main.go index 40ad2554..7da7c19f 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.NodeConf + var nodeList []node.Node // 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/edit/main.go b/internal/app/wwctl/node/edit/main.go index 34660743..82a81f43 100644 --- a/internal/app/wwctl/node/edit/main.go +++ b/internal/app/wwctl/node/edit/main.go @@ -38,7 +38,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { Output: args, } nodeListMsg := apinode.FilteredNodes(&filterList) - nodeMap := make(map[string]*node.NodeConf) + nodeMap := make(map[string]*node.Node) // got proper yaml back _ = yaml.Unmarshal([]byte(nodeListMsg.NodeConfMapYaml), nodeMap) file, err := os.CreateTemp(os.TempDir(), "ww4NodeEdit*.yaml") @@ -50,7 +50,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { _ = file.Truncate(0) _, _ = file.Seek(0, 0) if !NoHeader { - yamlTemplate := node.UnmarshalConf(node.NodeConf{}, []string{"tagsdel"}) + yamlTemplate := node.UnmarshalConf(node.Node{}, []string{"tagsdel"}) _, _ = file.WriteString("#nodename:\n# " + strings.Join(yamlTemplate, "\n# ") + "\n") } _, _ = file.WriteString(nodeListMsg.NodeConfMapYaml) @@ -73,7 +73,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { wwlog.Debug("Hashes are before %s and after %s\n", sum1, sum2) if sum1 != sum2 { wwlog.Debug("Nodes were modified") - modifiedNodeMap := make(map[string]*node.NodeConf) + modifiedNodeMap := make(map[string]*node.Node) _, _ = file.Seek(0, 0) // ignore error as only may occurs under strange circumstances buffer, _ := io.ReadAll(file) diff --git a/internal/app/wwctl/node/imprt/main.go b/internal/app/wwctl/node/imprt/main.go index 2a7156c2..5bc1e81c 100644 --- a/internal/app/wwctl/node/imprt/main.go +++ b/internal/app/wwctl/node/imprt/main.go @@ -22,7 +22,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } defer file.Close() - importMap := make(map[string]*node.NodeConf) + importMap := make(map[string]*node.Node) buffer, err := io.ReadAll(file) if err != nil { return fmt.Errorf("could not read: %s", err) @@ -64,7 +64,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { continue } if importMap[line[0]] == nil { - importMap[line[0]] = new(node.NodeConf) + importMap[line[0]] = new(node.Node) } } } diff --git a/internal/app/wwctl/node/list/main_test.go b/internal/app/wwctl/node/list/main_test.go index a821d626..b105579b 100644 --- a/internal/app/wwctl/node/list/main_test.go +++ b/internal/app/wwctl/node/list/main_test.go @@ -496,6 +496,7 @@ nodes: "Interface": "", "EscapeChar": "", "Write": "", + "Template": "", "Tags": {} }, "Init": "", @@ -545,6 +546,7 @@ nodes: "Interface": "", "EscapeChar": "", "Write": "", + "Template": "", "Tags": {} }, "Init": "", @@ -578,6 +580,7 @@ nodes: "Interface": "", "EscapeChar": "", "Write": "", + "Template": "", "Tags": {} }, "Init": "", diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index 3e016e2a..6821614d 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -14,7 +14,7 @@ type variables struct { setNodeAll bool setYes bool setForce bool - nodeConf node.NodeConf + nodeConf node.Node nodeDel node.NodeConfDel nodeAdd node.NodeConfAdd } diff --git a/internal/app/wwctl/overlay/imprt/main.go b/internal/app/wwctl/overlay/imprt/main.go index 190747ce..acad75ec 100644 --- a/internal/app/wwctl/overlay/imprt/main.go +++ b/internal/app/wwctl/overlay/imprt/main.go @@ -72,7 +72,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { return fmt.Errorf("could not get node list: %s", err) } - var updateNodes []node.NodeConf + var updateNodes []node.Node for _, node := range nodes { if util.InSlice(node.SystemOverlay, overlayName) { diff --git a/internal/app/wwctl/profile/add/main_test.go b/internal/app/wwctl/profile/add/main_test.go index d44f3c68..b1e211ff 100644 --- a/internal/app/wwctl/profile/add/main_test.go +++ b/internal/app/wwctl/profile/add/main_test.go @@ -20,7 +20,7 @@ func Test_Add(t *testing.T) { }{ { name: "single profile add", - args: []string{"--yes", "p01"}, + args: []string{"p01"}, wantErr: false, stdout: "", outDb: `WW_INTERNAL: 45 @@ -31,7 +31,7 @@ nodes: {} }, { name: "single profile add with netname and netdev", - args: []string{"--yes", "--netname", "primary", "--netdev", "eno3", "p02"}, + args: []string{"--netname", "primary", "--netdev", "eno3", "p02"}, wantErr: false, stdout: "", outDb: `WW_INTERNAL: 45 diff --git a/internal/app/wwctl/profile/add/root.go b/internal/app/wwctl/profile/add/root.go index f55eb7f8..cb9d30af 100644 --- a/internal/app/wwctl/profile/add/root.go +++ b/internal/app/wwctl/profile/add/root.go @@ -11,12 +11,8 @@ import ( ) type variables struct { - profileConf node.ProfileConf - nodeAdd node.NodeConfAdd - SetNetDevDel string - SetNodeAll bool - SetYes bool - SetForce bool + profileConf node.Profile + nodeAdd node.NodeConfAdd } // GetRootCommand returns the root cobra.Command for the application. @@ -59,6 +55,5 @@ func GetCommand() *cobra.Command { }); err != nil { log.Println(err) } - baseCmd.PersistentFlags().BoolVarP(&vars.SetYes, "yes", "y", false, "Set 'yes' to all questions asked") return baseCmd } diff --git a/internal/app/wwctl/profile/edit/main.go b/internal/app/wwctl/profile/edit/main.go index c3ec9437..f981ada4 100644 --- a/internal/app/wwctl/profile/edit/main.go +++ b/internal/app/wwctl/profile/edit/main.go @@ -39,7 +39,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { Output: args, } profileListMsg := apiprofile.FilteredProfiles(&filterList) - profileMap := make(map[string]*node.ProfileConf) + profileMap := make(map[string]*node.Profile) // got proper yaml back _ = yaml.Unmarshal([]byte(profileListMsg.NodeConfMapYaml), profileMap) file, err := os.CreateTemp(os.TempDir(), "ww4ProfileEdit*.yaml") @@ -51,7 +51,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { _ = file.Truncate(0) _, _ = file.Seek(0, 0) if !NoHeader { - yamlTemplate := node.UnmarshalConf(node.ProfileConf{}, []string{"tagsdel"}) + yamlTemplate := node.UnmarshalConf(node.Profile{}, []string{"tagsdel"}) _, _ = file.WriteString("#profilename:\n# " + strings.Join(yamlTemplate, "\n# ") + "\n") } _, _ = file.WriteString(profileListMsg.NodeConfMapYaml) @@ -74,7 +74,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { wwlog.Debug("Hashes are before %s and after %s\n", sum1, sum2) if sum1 != sum2 { wwlog.Debug("Profiles were modified") - modifiedProfileMap := make(map[string]*node.ProfileConf) + modifiedProfileMap := make(map[string]*node.Profile) _, _ = file.Seek(0, 0) // ignore error as only may occurs under strange circumstances buffer, _ := io.ReadAll(file) diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index 332fd0d5..b341bfd3 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -21,7 +21,7 @@ type variables struct { partName string diskName string fsName string - profileConf node.ProfileConf + profileConf node.Profile profileDel node.NodeConfDel profileAdd node.NodeConfAdd } diff --git a/internal/pkg/api/node/delete.go b/internal/pkg/api/node/delete.go index 7128c2bc..41e60917 100644 --- a/internal/pkg/api/node/delete.go +++ b/internal/pkg/api/node/delete.go @@ -15,7 +15,7 @@ import ( // NodeDelete adds nodes for management by Warewulf. func NodeDelete(ndp *wwapiv1.NodeDeleteParameter) (err error) { - var nodeList []node.NodeConf + var nodeList []node.Node nodeList, err = NodeDeleteParameterCheck(ndp, false) if err != nil { return @@ -55,7 +55,7 @@ func NodeDelete(ndp *wwapiv1.NodeDeleteParameter) (err error) { // NodeDeleteParameterCheck does error checking on NodeDeleteParameter. // Output to the console if console is true. // Returns the nodes to delete. -func NodeDeleteParameterCheck(ndp *wwapiv1.NodeDeleteParameter, console bool) (nodeList []node.NodeConf, err error) { +func NodeDeleteParameterCheck(ndp *wwapiv1.NodeDeleteParameter, console bool) (nodeList []node.Node, err error) { if ndp == nil { err = fmt.Errorf("NodeDeleteParameter is nil") diff --git a/internal/pkg/api/node/edit.go b/internal/pkg/api/node/edit.go index 79324c59..dc988bde 100644 --- a/internal/pkg/api/node/edit.go +++ b/internal/pkg/api/node/edit.go @@ -37,7 +37,7 @@ func NodeAddFromYaml(nodeList *wwapiv1.NodeYaml) (err error) { if err != nil { return fmt.Errorf("could not open NodeDB: %w", err) } - nodeMap := make(map[string]*node.NodeConf) + nodeMap := make(map[string]*node.Node) err = yaml.Unmarshal([]byte(nodeList.NodeConfMapYaml), nodeMap) if err != nil { return fmt.Errorf("could not unmarshal Yaml: %w", err) diff --git a/internal/pkg/api/node/set.go b/internal/pkg/api/node/set.go index e6f4c142..cfa3b0e8 100644 --- a/internal/pkg/api/node/set.go +++ b/internal/pkg/api/node/set.go @@ -60,7 +60,7 @@ func NodeSetParameterCheck(set *wwapiv1.ConfSetParameter) (nodeDB node.NodeYaml, for _, nId := range set.ConfList { if util.InSlice(set.ConfList, nId) { wwlog.Debug("evaluating node: %s", nId) - var nodePtr *node.NodeConf + var nodePtr *node.Node nodePtr, err = nodeDB.GetNodeOnlyPtr(nId) if err != nil { wwlog.Warn("invalid node: %s", nId) diff --git a/internal/pkg/api/profile/edit.go b/internal/pkg/api/profile/edit.go index 059a3272..c8a384a0 100644 --- a/internal/pkg/api/profile/edit.go +++ b/internal/pkg/api/profile/edit.go @@ -40,7 +40,7 @@ func ProfileAddFromYaml(nodeList *wwapiv1.NodeAddParameter) (err error) { return fmt.Errorf("got wrong hash, not modifying profile database") } - profileMap := make(map[string]*node.ProfileConf) + profileMap := make(map[string]*node.Profile) err = yaml.Unmarshal([]byte(nodeList.NodeConfYaml), profileMap) if err != nil { return fmt.Errorf("couldn't unmarshall Yaml: %w", err) diff --git a/internal/pkg/api/profile/list.go b/internal/pkg/api/profile/list.go index 5d027943..be8073eb 100644 --- a/internal/pkg/api/profile/list.go +++ b/internal/pkg/api/profile/list.go @@ -38,7 +38,7 @@ func ProfileList(ShowOpt *wwapiv1.GetProfileList) (profileList wwapiv1.ProfileLi } } } else if ShowOpt.ShowYaml { - profileMap := make(map[string]node.ProfileConf) + profileMap := make(map[string]node.Profile) for _, profile := range profiles { profileMap[profile.Id()] = profile } @@ -46,7 +46,7 @@ func ProfileList(ShowOpt *wwapiv1.GetProfileList) (profileList wwapiv1.ProfileLi buf, _ := yaml.Marshal(profileMap) profileList.Output = append(profileList.Output, string(buf)) } else if ShowOpt.ShowJson { - profileMap := make(map[string]node.ProfileConf) + profileMap := make(map[string]node.Profile) for _, profile := range profiles { profileMap[profile.Id()] = profile } diff --git a/internal/pkg/api/profile/set.go b/internal/pkg/api/profile/set.go index 97c25c51..17b18888 100644 --- a/internal/pkg/api/profile/set.go +++ b/internal/pkg/api/profile/set.go @@ -60,7 +60,7 @@ func ProfileSetParameterCheck(set *wwapiv1.ConfSetParameter) (nodeDB node.NodeYa for _, profileId := range set.ConfList { if util.InSlice(set.ConfList, profileId) { wwlog.Verbose("evaluating profile: %s", profileId) - var profilePtr *node.ProfileConf + var profilePtr *node.Profile profilePtr, err = nodeDB.GetProfilePtr(profileId) if err != nil { wwlog.Warn("invalid profile: %s", profileId) diff --git a/internal/pkg/node/checkconf.go b/internal/pkg/node/checkconf.go index 623f078f..e80ecd01 100644 --- a/internal/pkg/node/checkconf.go +++ b/internal/pkg/node/checkconf.go @@ -14,13 +14,13 @@ import ( /* Checks if for NodeConf all values can be parsed according to their type. */ -func (nodeConf *NodeConf) Check() (err error) { +func (nodeConf *Node) Check() (err error) { nodeInfoType := reflect.TypeOf(nodeConf) nodeInfoVal := reflect.ValueOf(nodeConf) return check(nodeInfoType, nodeInfoVal) } -func (profileConf *ProfileConf) Check() (err error) { +func (profileConf *Profile) Check() (err error) { profileInfoType := reflect.TypeOf(profileConf) profileInfoVal := reflect.ValueOf(profileConf) return check(profileInfoType, profileInfoVal) @@ -49,8 +49,8 @@ func check(infoType reflect.Type, infoVal reflect.Value) (err error) { } } } - } else if infoType.Elem().Field(i).Type == reflect.TypeOf(map[string]*NetDevs(nil)) { - netMap := infoVal.Elem().Field(i).Interface().(map[string]*NetDevs) + } else if infoType.Elem().Field(i).Type == reflect.TypeOf(map[string]*NetDev(nil)) { + netMap := infoVal.Elem().Field(i).Interface().(map[string]*NetDev) for _, val := range netMap { netType := reflect.TypeOf(val) netVal := reflect.ValueOf(val) diff --git a/internal/pkg/node/constructors.go b/internal/pkg/node/constructors.go index 88fec481..ac9b220c 100644 --- a/internal/pkg/node/constructors.go +++ b/internal/pkg/node/constructors.go @@ -46,10 +46,10 @@ func Parse(data []byte) (nodeList NodeYaml, err error) { } wwlog.Debug("Checking nodes for types") if nodeList.nodes == nil { - nodeList.nodes = map[string]*NodeConf{} + nodeList.nodes = map[string]*Node{} } if nodeList.nodeProfiles == nil { - nodeList.nodeProfiles = map[string]*ProfileConf{} + nodeList.nodeProfiles = map[string]*Profile{} } wwlog.Debug("returning node object") return nodeList, nil @@ -58,7 +58,7 @@ func Parse(data []byte) (nodeList NodeYaml, err error) { /* Get a node with its merged in nodes */ -func (config *NodeYaml) GetNode(id string) (node NodeConf, err error) { +func (config *NodeYaml) GetNode(id string) (node Node, err error) { if _, ok := config.nodes[id]; !ok { return node, ErrNotFound } @@ -82,7 +82,7 @@ func (config *NodeYaml) GetNode(id string) (node NodeConf, err error) { wwlog.Warn("profile not found: %s", p) continue } - err = mergo.Merge(&node.ProfileConf, includedProfile, mergo.WithAppendSlice) + err = mergo.Merge(&node.Profile, includedProfile, mergo.WithAppendSlice) if err != nil { return node, err } @@ -112,7 +112,7 @@ func (config *NodeYaml) GetNode(id string) (node NodeConf, err error) { Return the node with the id string without the merged in nodes, return ErrNotFound otherwise */ -func (config *NodeYaml) GetNodeOnly(id string) (node NodeConf, err error) { +func (config *NodeYaml) GetNodeOnly(id string) (node Node, err error) { node = EmptyNode() if found, ok := config.nodes[id]; ok { return *found, nil @@ -124,7 +124,7 @@ func (config *NodeYaml) GetNodeOnly(id string) (node NodeConf, err error) { Return pointer to the node with the id string without the merged in nodes, return ErrMotFound otherwise */ -func (config *NodeYaml) GetNodeOnlyPtr(id string) (*NodeConf, error) { +func (config *NodeYaml) GetNodeOnlyPtr(id string) (*Node, error) { node := EmptyNode() if found, ok := config.nodes[id]; ok { return found, nil @@ -135,7 +135,7 @@ func (config *NodeYaml) GetNodeOnlyPtr(id string) (*NodeConf, error) { /* Get the profile with id, return ErrNotFound otherwise */ -func (config *NodeYaml) GetProfile(id string) (profile ProfileConf, err error) { +func (config *NodeYaml) GetProfile(id string) (profile Profile, err error) { if found, ok := config.nodeProfiles[id]; ok { found.id = id return *found, nil @@ -146,7 +146,7 @@ func (config *NodeYaml) GetProfile(id string) (profile ProfileConf, err error) { /* Get the profile with id, return ErrNotFound otherwise */ -func (config *NodeYaml) GetProfilePtr(id string) (profile *ProfileConf, err error) { +func (config *NodeYaml) GetProfilePtr(id string) (profile *Profile, err error) { if found, ok := config.nodeProfiles[id]; ok { found.id = id return found, nil @@ -158,7 +158,7 @@ func (config *NodeYaml) GetProfilePtr(id string) (profile *ProfileConf, err erro Get the nodes from the loaded configuration. This function also merges the nodes with the given nodes. */ -func (config *NodeYaml) FindAllNodes(nodes ...string) (nodeList []NodeConf, err error) { +func (config *NodeYaml) FindAllNodes(nodes ...string) (nodeList []Node, err error) { if len(nodes) == 0 { for n := range config.nodes { nodes = append(nodes, n) @@ -188,7 +188,7 @@ func (config *NodeYaml) FindAllNodes(nodes ...string) (nodeList []NodeConf, err /* Return all nodes as ProfileConf */ -func (config *NodeYaml) FindAllProfiles(nodes ...string) (profileList []ProfileConf, err error) { +func (config *NodeYaml) FindAllProfiles(nodes ...string) (profileList []Profile, err error) { if len(nodes) == 0 { for n := range config.nodeProfiles { nodes = append(nodes, n) @@ -246,7 +246,7 @@ without a hardware address is returned. If no unconfigured node is found, an error is returned. */ -func (config *NodeYaml) FindDiscoverableNode() (NodeConf, string, error) { +func (config *NodeYaml) FindDiscoverableNode() (Node, string, error) { nodes, _ := config.FindAllNodes() diff --git a/internal/pkg/node/constuctors_test.go b/internal/pkg/node/constuctors_test.go index ec0171cf..246b852a 100644 --- a/internal/pkg/node/constuctors_test.go +++ b/internal/pkg/node/constuctors_test.go @@ -199,7 +199,7 @@ nodes: wwlog.SetLogLevel(wwlog.DEBUG) nodes, err := ymlSrc.FindAllNodes() assert.NoError(err) - nodemap := make(map[string]*NodeConf) + nodemap := make(map[string]*Node) for i := range nodes { nodemap[nodes[i].Id()] = &nodes[i] } diff --git a/internal/pkg/node/datastructure.go b/internal/pkg/node/datastructure.go index bf44236b..0efb21fa 100644 --- a/internal/pkg/node/datastructure.go +++ b/internal/pkg/node/datastructure.go @@ -18,27 +18,27 @@ Structure of which goes to disk */ type NodeYaml struct { WWInternal int `yaml:"WW_INTERNAL,omitempty" json:"WW_INTERNAL,omitempty"` - nodeProfiles map[string]*ProfileConf - nodes map[string]*NodeConf + nodeProfiles map[string]*Profile + nodes map[string]*Node } /* -NodeConf is the datastructure describing a node and a profile which in disk format. +Node is the datastructure describing a node and a profile which in disk format. */ -type NodeConf struct { +type Node struct { id string valid bool // Is set true, if called by the constructor // exported values Discoverable wwtype.WWbool `yaml:"discoverable,omitempty" lopt:"discoverable" sopt:"e" comment:"Make discoverable in given network (true/false)"` AssetKey string `yaml:"asset key,omitempty" lopt:"asset" comment:"Set the node's Asset tag (key)"` Profiles []string `yaml:"profiles,omitempty" lopt:"profile" sopt:"P" comment:"Set the node's profile members (comma separated)"` - ProfileConf `yaml:"-,inline"` // include all values set in the profile, but inline them in yaml output if these are part of NodeConf + Profile `yaml:"-,inline"` // include all values set in the profile, but inline them in yaml output if these are part of Node } /* Holds the data which can be set for profiles and nodes. */ -type ProfileConf struct { +type Profile struct { id string // exported values Comment string `yaml:"comment,omitempty" lopt:"comment" comment:"Set arbitrary string comment"` @@ -51,7 +51,7 @@ type ProfileConf struct { Ipmi *IpmiConf `yaml:"ipmi,omitempty"` Init string `yaml:"init,omitempty" lopt:"init" sopt:"i" comment:"Define the init process to boot the container"` Root string `yaml:"root,omitempty" lopt:"root" comment:"Define the rootfs" ` - NetDevs map[string]*NetDevs `yaml:"network devices,omitempty"` + NetDevs map[string]*NetDev `yaml:"network devices,omitempty"` Tags map[string]string `yaml:"tags,omitempty"` PrimaryNetDev string `yaml:"primary network,omitempty" lopt:"primarynet" sopt:"p" comment:"Set the primary network interface"` Disks map[string]*Disk `yaml:"disks,omitempty"` @@ -78,7 +78,7 @@ type KernelConf struct { Args string `yaml:"args,omitempty" lopt:"kernelargs" sopt:"A" comment:"Set Kernel argument" json:"args,omitempty"` } -type NetDevs struct { +type NetDev struct { Type string `yaml:"type,omitempty" lopt:"type" sopt:"T" comment:"Set device type of given network"` OnBoot *bool `yaml:"onboot,omitempty" lopt:"onboot" comment:"Enable/disable network device (true/false)"` Device string `yaml:"device,omitempty" lopt:"netdev" sopt:"N" comment:"Set the device for given network"` @@ -134,9 +134,9 @@ interface so that nodes and profiles which aren't exported will be marshaled */ type ExportedYml struct { - WWInternal int `yaml:"WW_INTERNAL"` - NodeProfiles map[string]*ProfileConf `yaml:"nodeprofiles"` - Nodes map[string]*NodeConf `yaml:"nodes"` + WWInternal int `yaml:"WW_INTERNAL"` + NodeProfiles map[string]*Profile `yaml:"nodeprofiles"` + Nodes map[string]*Node `yaml:"nodes"` } /* diff --git a/internal/pkg/node/flags.go b/internal/pkg/node/flags.go index e87c750d..62dad5e1 100644 --- a/internal/pkg/node/flags.go +++ b/internal/pkg/node/flags.go @@ -31,11 +31,11 @@ type NodeConfAdd struct { Create cmd line flags from the NodeConf fields. Returns a []func() where every function must be called, as the command line parser returns e.g. netip.IP objects which must be parsed back to strings. */ -func (nodeConf *NodeConf) CreateFlags(baseCmd *cobra.Command) { +func (nodeConf *Node) CreateFlags(baseCmd *cobra.Command) { recursiveCreateFlags(nodeConf, baseCmd) } -func (profileConf *ProfileConf) CreateFlags(baseCmd *cobra.Command) { +func (profileConf *Profile) CreateFlags(baseCmd *cobra.Command) { recursiveCreateFlags(profileConf, baseCmd) } diff --git a/internal/pkg/node/ignition.go b/internal/pkg/node/ignition.go index fbffab87..c3ac4e96 100644 --- a/internal/pkg/node/ignition.go +++ b/internal/pkg/node/ignition.go @@ -13,7 +13,7 @@ import ( /* Create a ignition struct class for ignition */ -func (node *NodeConf) GetStorage() (stor types_3_4.Storage, err error, rep string) { +func (node *Node) GetStorage() (stor types_3_4.Storage, err error, rep string) { var fileSystems []types_3_4.Filesystem for fsdevice, fs := range node.FileSystems { var mountOptions []types_3_4.MountOption @@ -141,7 +141,7 @@ type SimpleIgnitionConfig struct { /* Get a simple config which can be marshalled to json */ -func (node *NodeConf) GetConfig() (conf SimpleIgnitionConfig, rep string, err error) { +func (node *Node) GetConfig() (conf SimpleIgnitionConfig, rep string, err error) { conf.Storage, err, rep = node.GetStorage() conf.Ignition.Version = "3.1.0" return diff --git a/internal/pkg/node/list.go b/internal/pkg/node/list.go index 17d9ba02..490205d6 100644 --- a/internal/pkg/node/list.go +++ b/internal/pkg/node/list.go @@ -41,7 +41,7 @@ type fieldMap map[string]*NodeFields /* Get all the info out of NodeConf. If emptyFields is set true, all fields are shown not only the ones with effective values */ -func (nodeYml *NodeYaml) GetFields(node NodeConf) (output []NodeFields) { +func (nodeYml *NodeYaml) GetFields(node Node) (output []NodeFields) { nodeMap := make(fieldMap) for _, p := range node.Profiles { if profile, ok := nodeYml.nodeProfiles[p]; ok { @@ -64,7 +64,7 @@ func (nodeYml *NodeYaml) GetFields(node NodeConf) (output []NodeFields) { /* Get all the info out of ProfileConf. If emptyFields is set true, all fields are shown not only the ones with effective values */ -func (nodeYml *NodeYaml) GetFieldsProfile(profile ProfileConf) (output []NodeFields) { +func (nodeYml *NodeYaml) GetFieldsProfile(profile Profile) (output []NodeFields) { profileMap := make(fieldMap) profileMap.importFields(&profile, "", "") for _, elem := range profileMap { diff --git a/internal/pkg/node/methods.go b/internal/pkg/node/methods.go index ea449145..4e1ca218 100644 --- a/internal/pkg/node/methods.go +++ b/internal/pkg/node/methods.go @@ -10,13 +10,13 @@ import ( "github.com/warewulf/warewulf/internal/pkg/util" ) -type nodeList []NodeConf +type nodeList []Node func (a nodeList) Len() int { return len(a) } func (a nodeList) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a nodeList) Less(i, j int) bool { return a[i].id < a[j].id } -type profileList []ProfileConf +type profileList []Profile func (a profileList) Len() int { return len(a) } func (a profileList) Swap(i, j int) { a[i], a[j] = a[j], a[i] } @@ -32,9 +32,9 @@ func (a profileList) Less(i, j int) bool { return a[i].id < a[j].id } Filter a given slice of NodeConf against a given regular expression */ -func FilterNodeListByName(set []NodeConf, searchList []string) []NodeConf { - var ret []NodeConf - unique := make(map[string]NodeConf) +func FilterNodeListByName(set []Node, searchList []string) []Node { + var ret []Node + unique := make(map[string]Node) if len(searchList) > 0 { for _, search := range searchList { @@ -59,9 +59,9 @@ func FilterNodeListByName(set []NodeConf, searchList []string) []NodeConf { Filter a given slice of ProfileConf against a given regular expression */ -func FilterProfileListByName(set []ProfileConf, searchList []string) []ProfileConf { - var ret []ProfileConf - unique := make(map[string]ProfileConf) +func FilterProfileListByName(set []Profile, searchList []string) []Profile { + var ret []Profile + unique := make(map[string]Profile) if len(searchList) > 0 { for _, search := range searchList { @@ -85,23 +85,23 @@ func FilterProfileListByName(set []ProfileConf, searchList []string) []ProfileCo /* Creates an NodeConf with the given id. Doesn't add it to the database */ -func NewNode(id string) (nodeconf NodeConf) { +func NewNode(id string) (nodeconf Node) { nodeconf = EmptyNode() nodeconf.id = id return nodeconf } -func NewProfile(id string) (profileconf ProfileConf) { +func NewProfile(id string) (profileconf Profile) { profileconf = EmptyProfile() profileconf.id = id return profileconf } -func EmptyNode() (nodeconf NodeConf) { +func EmptyNode() (nodeconf Node) { nodeconf.Ipmi = new(IpmiConf) nodeconf.Ipmi.Tags = map[string]string{} nodeconf.Kernel = new(KernelConf) - nodeconf.NetDevs = make(map[string]*NetDevs) + nodeconf.NetDevs = make(map[string]*NetDev) nodeconf.Tags = map[string]string{} return nodeconf } @@ -109,11 +109,11 @@ func EmptyNode() (nodeconf NodeConf) { /* Creates a ProfileConf but doesn't add it to the database. */ -func EmptyProfile() (profileconf ProfileConf) { +func EmptyProfile() (profileconf Profile) { profileconf.Ipmi = new(IpmiConf) profileconf.Ipmi.Tags = map[string]string{} profileconf.Kernel = new(KernelConf) - profileconf.NetDevs = make(map[string]*NetDevs) + profileconf.NetDevs = make(map[string]*NetDev) profileconf.Tags = map[string]string{} return profileconf } @@ -123,7 +123,7 @@ Flattens out a NodeConf, which means if there are no explicit values in *IpmiCon or *KernelConf, these pointer will set to nil. This will remove something like ipmi: {} from nodes.conf */ -func (info *NodeConf) Flatten() { +func (info *Node) Flatten() { recursiveFlatten(info) } @@ -132,7 +132,7 @@ Flattens out a ProfileConf, which means if there are no explicit values in *Ipmi or *KernelConf, these pointer will set to nil. This will remove something like ipmi: {} from nodes.conf */ -func (info *ProfileConf) Flatten() { +func (info *Profile) Flatten() { recursiveFlatten(info) } @@ -296,28 +296,28 @@ Getters for unexported fields /* Returns the id of the node */ -func (node *NodeConf) Id() string { +func (node *Node) Id() string { return node.id } /* Returns the id of the profile */ -func (node *ProfileConf) Id() string { +func (node *Profile) Id() string { return node.id } /* Returns if the node is a valid in the database */ -func (node *NodeConf) Valid() bool { +func (node *Node) Valid() bool { return node.valid } /* Check if the netdev is the primary one */ -func (dev *NetDevs) Primary() bool { +func (dev *NetDev) Primary() bool { return dev.primary } @@ -353,7 +353,7 @@ func cleanList(list []string) (ret []string) { Return the ipv4 address and mask in CIDR format. Aimed for the use in templates. */ -func (netdev *NetDevs) IpCIDR() string { +func (netdev *NetDev) IpCIDR() string { if netdev.Ipaddr.IsUnspecified() || netdev.Netmask.IsUnspecified() { return "" } diff --git a/internal/pkg/node/methods_test.go b/internal/pkg/node/methods_test.go index a629ecb4..860e8257 100644 --- a/internal/pkg/node/methods_test.go +++ b/internal/pkg/node/methods_test.go @@ -6,8 +6,8 @@ import ( ) func Test_Empty(t *testing.T) { - var netdev NetDevs - var netdevPtr *NetDevs + var netdev NetDev + var netdevPtr *NetDev t.Run("test for empty", func(t *testing.T) { if ObjectIsEmpty(netdev) != true { diff --git a/internal/pkg/node/modifiers.go b/internal/pkg/node/modifiers.go index 6abf88a1..c6b3f7d6 100644 --- a/internal/pkg/node/modifiers.go +++ b/internal/pkg/node/modifiers.go @@ -14,7 +14,7 @@ import ( /* Add a node with the given ID and return a pointer to it */ -func (config *NodeYaml) AddNode(nodeID string) (*NodeConf, error) { +func (config *NodeYaml) AddNode(nodeID string) (*Node, error) { newNode := NewNode(nodeID) wwlog.Verbose("Adding new node: %s", nodeID) if _, ok := config.nodes[nodeID]; ok { @@ -42,7 +42,7 @@ func (config *NodeYaml) DelNode(nodeID string) error { /* set node for the node with id the values of vals */ -func (config *NodeYaml) SetNode(nodeID string, vals NodeConf) error { +func (config *NodeYaml) SetNode(nodeID string, vals Node) error { node, ok := config.nodes[nodeID] if !ok { return ErrNotFound @@ -61,7 +61,7 @@ func (config *NodeYaml) SetNode(nodeID string, vals NodeConf) error { /* set profile for the node with id the values of vals */ -func (config *NodeYaml) SetProfile(profileId string, vals ProfileConf) error { +func (config *NodeYaml) SetProfile(profileId string, vals Profile) error { profile, ok := config.nodeProfiles[profileId] if !ok { return ErrNotFound @@ -80,7 +80,7 @@ func (config *NodeYaml) SetProfile(profileId string, vals ProfileConf) error { /* Add a node with the given ID and return a pointer to it */ -func (config *NodeYaml) AddProfile(profileId string) (*ProfileConf, error) { +func (config *NodeYaml) AddProfile(profileId string) (*Profile, error) { profile := EmptyProfile() wwlog.Verbose("adding new profile: %s", profileId) if _, ok := config.nodeProfiles[profileId]; ok { diff --git a/internal/pkg/node/util.go b/internal/pkg/node/util.go index c3924da1..325f88ad 100644 --- a/internal/pkg/node/util.go +++ b/internal/pkg/node/util.go @@ -10,9 +10,9 @@ import ( /* Gets a node by its hardware(mac) address */ -func (config *NodeYaml) FindByHwaddr(hwa string) (NodeConf, error) { +func (config *NodeYaml) FindByHwaddr(hwa string) (Node, error) { if _, err := net.ParseMAC(hwa); err != nil { - return NodeConf{}, errors.New("invalid hardware address: " + hwa) + return Node{}, errors.New("invalid hardware address: " + hwa) } nodeList, _ := config.FindAllNodes() for _, node := range nodeList { @@ -23,20 +23,20 @@ func (config *NodeYaml) FindByHwaddr(hwa string) (NodeConf, error) { } } - return NodeConf{}, ErrNotFound + return Node{}, ErrNotFound } /* Find a node by its ip address */ -func (config *NodeYaml) FindByIpaddr(ipaddr string) (NodeConf, error) { +func (config *NodeYaml) FindByIpaddr(ipaddr string) (Node, error) { addr := net.ParseIP(ipaddr) if addr == nil { - return NodeConf{}, errors.New("invalid IP:" + ipaddr) + return Node{}, errors.New("invalid IP:" + ipaddr) } nodeList, err := config.FindAllNodes() if err != nil { - return NodeConf{}, err + return Node{}, err } for _, node := range nodeList { for _, dev := range node.NetDevs { @@ -46,7 +46,7 @@ func (config *NodeYaml) FindByIpaddr(ipaddr string) (NodeConf, error) { } } - return NodeConf{}, ErrNotFound + return Node{}, ErrNotFound } /* diff --git a/internal/pkg/overlay/datastructure.go b/internal/pkg/overlay/datastructure.go index 8a996023..240fcb2b 100644 --- a/internal/pkg/overlay/datastructure.go +++ b/internal/pkg/overlay/datastructure.go @@ -35,17 +35,17 @@ type TemplateStruct struct { Warewulf warewulfconf.WarewulfConf Tftp warewulfconf.TFTPConf Paths warewulfconf.BuildConfig - AllNodes []node.NodeConf - node.NodeConf + AllNodes []node.Node + node.Node // backward compatiblity Container string - ThisNode *node.NodeConf + ThisNode *node.Node } /* Initialize an TemplateStruct with the given node.NodeInfo */ -func InitStruct(nodeData node.NodeConf) (TemplateStruct, error) { +func InitStruct(nodeData node.Node) (TemplateStruct, error) { var tstruct TemplateStruct hostname, _ := os.Hostname() tstruct.BuildHost = hostname @@ -78,7 +78,7 @@ func InitStruct(nodeData node.NodeConf) (TemplateStruct, error) { dt := time.Now() tstruct.BuildTime = dt.Format("01-02-2006 15:04:05 MST") tstruct.BuildTimeUnix = strconv.FormatInt(dt.Unix(), 10) - tstruct.NodeConf.Tags = map[string]string{} + tstruct.Node.Tags = map[string]string{} var buf bytes.Buffer enc := gob.NewEncoder(&buf) dec := gob.NewDecoder(&buf) diff --git a/internal/pkg/overlay/funcmap.go b/internal/pkg/overlay/funcmap.go index 751a97d0..a9758d76 100644 --- a/internal/pkg/overlay/funcmap.go +++ b/internal/pkg/overlay/funcmap.go @@ -106,7 +106,7 @@ func templateContainerFileInclude(containername string, filepath string) string // don't return an error as we use this function for template evaluation, // so error will turn up there as the return string -func createIgnitionJson(node *node.NodeConf) string { +func createIgnitionJson(node *node.Node) string { conf, rep, err := node.GetConfig() if len(conf.Storage.Disks) == 0 && len(conf.Storage.Filesystems) == 0 { wwlog.Debug("no disks or filesystems present, don't create a json object") diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index d14747aa..8542b346 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -28,7 +28,7 @@ var ( /* Build all overlays for a node */ -func BuildAllOverlays(nodes []node.NodeConf) error { +func BuildAllOverlays(nodes []node.Node) error { for _, n := range nodes { sysOverlays := n.SystemOverlay @@ -50,7 +50,7 @@ func BuildAllOverlays(nodes []node.NodeConf) error { // TODO: Add an Overlay Delete for both sourcedir and image -func BuildSpecificOverlays(nodes []node.NodeConf, overlayNames []string) error { +func BuildSpecificOverlays(nodes []node.Node, overlayNames []string) error { for _, n := range nodes { wwlog.Info("Building overlay for %s: %v", n, overlayNames) for _, overlayName := range overlayNames { @@ -123,7 +123,7 @@ func OverlayInit(overlayName string) error { /* Build the given overlays for a node and create a Image for them */ -func BuildOverlay(nodeConf node.NodeConf, context string, overlayNames []string) error { +func BuildOverlay(nodeConf node.Node, context string, overlayNames []string) error { if len(overlayNames) == 0 && context == "" { return nil } @@ -172,7 +172,7 @@ func BuildOverlay(nodeConf node.NodeConf, context string, overlayNames []string) Build the given overlays for a node in the given directory. If the given does not exists it will be created. */ -func BuildOverlayIndir(nodeData node.NodeConf, overlayNames []string, outputDir string) error { +func BuildOverlayIndir(nodeData node.Node, overlayNames []string, outputDir string) error { if len(overlayNames) == 0 { return nil } diff --git a/internal/pkg/overlay/overlay_test.go b/internal/pkg/overlay/overlay_test.go index d1a02a28..56dab2f4 100644 --- a/internal/pkg/overlay/overlay_test.go +++ b/internal/pkg/overlay/overlay_test.go @@ -265,7 +265,7 @@ func Test_BuildAllOverlays(t *testing.T) { defer os.RemoveAll(provisionDir) conf.Paths.WWProvisiondir = provisionDir - var nodes []node.NodeConf + var nodes []node.Node for i, nodeName := range tt.nodes { nodeInfo := node.NewNode(nodeName) if tt.systemOverlays != nil { @@ -363,7 +363,7 @@ func Test_BuildSpecificOverlays(t *testing.T) { defer os.RemoveAll(provisionDir) conf.Paths.WWProvisiondir = provisionDir - var nodes []node.NodeConf + var nodes []node.Node for _, nodeName := range tt.nodes { nodeInfo := node.NewNode(nodeName) nodes = append(nodes, nodeInfo) diff --git a/internal/pkg/warewulfd/nodedb.go b/internal/pkg/warewulfd/nodedb.go index 32903c4a..4ed997b0 100644 --- a/internal/pkg/warewulfd/nodedb.go +++ b/internal/pkg/warewulfd/nodedb.go @@ -53,7 +53,7 @@ func loadNodeDB() (err error) { return nil } -func GetNodeOrSetDiscoverable(hwaddr string) (node.NodeConf, error) { +func GetNodeOrSetDiscoverable(hwaddr string) (node.Node, error) { db.lock.RLock() defer db.lock.RUnlock() // NOTE: since discoverable nodes will write an updated DB to file and then diff --git a/internal/pkg/warewulfd/provision.go b/internal/pkg/warewulfd/provision.go index 9426e067..71c05679 100644 --- a/internal/pkg/warewulfd/provision.go +++ b/internal/pkg/warewulfd/provision.go @@ -35,7 +35,7 @@ type templateVars struct { KernelArgs string KernelOverride string Tags map[string]string - NetDevs map[string]*node.NetDevs + NetDevs map[string]*node.NetDev } func ProvisionSend(w http.ResponseWriter, req *http.Request) { diff --git a/internal/pkg/warewulfd/util.go b/internal/pkg/warewulfd/util.go index 0ba04921..7938d343 100644 --- a/internal/pkg/warewulfd/util.go +++ b/internal/pkg/warewulfd/util.go @@ -44,7 +44,7 @@ func sendFile( return nil } -func getOverlayFile(n node.NodeConf, context string, stage_overlays []string, autobuild bool) (stage_file string, err error) { +func getOverlayFile(n node.Node, context string, stage_overlays []string, autobuild bool) (stage_file string, err error) { stage_file = overlay.OverlayImage(n.Id(), context, stage_overlays) err = nil @@ -60,9 +60,9 @@ func getOverlayFile(n node.NodeConf, context string, stage_overlays []string, au if build { if len(stage_overlays) > 0 { - err = overlay.BuildSpecificOverlays([]node.NodeConf{n}, stage_overlays) + err = overlay.BuildSpecificOverlays([]node.Node{n}, stage_overlays) } else { - err = overlay.BuildAllOverlays([]node.NodeConf{n}) + err = overlay.BuildAllOverlays([]node.Node{n}) } if err != nil { wwlog.Error("Failed to build overlay: %s, %s, %s\n%s",