diff --git a/internal/pkg/node/constructors.go b/internal/pkg/node/constructors.go index ac9b220c..e22390a3 100644 --- a/internal/pkg/node/constructors.go +++ b/internal/pkg/node/constructors.go @@ -45,11 +45,11 @@ func Parse(data []byte) (nodeList NodeYaml, err error) { return nodeList, err } wwlog.Debug("Checking nodes for types") - if nodeList.nodes == nil { - nodeList.nodes = map[string]*Node{} + if nodeList.Nodes == nil { + nodeList.Nodes = map[string]*Node{} } - if nodeList.nodeProfiles == nil { - nodeList.nodeProfiles = map[string]*Profile{} + if nodeList.NodeProfiles == nil { + nodeList.NodeProfiles = map[string]*Profile{} } wwlog.Debug("returning node object") return nodeList, nil @@ -59,7 +59,7 @@ func Parse(data []byte) (nodeList NodeYaml, err error) { Get a node with its merged in nodes */ func (config *NodeYaml) GetNode(id string) (node Node, err error) { - if _, ok := config.nodes[id]; !ok { + if _, ok := config.Nodes[id]; !ok { return node, ErrNotFound } node = EmptyNode() @@ -68,7 +68,7 @@ func (config *NodeYaml) GetNode(id string) (node Node, err error) { var buf bytes.Buffer enc := gob.NewEncoder(&buf) dec := gob.NewDecoder(&buf) - err = enc.Encode(config.nodes[id]) + err = enc.Encode(config.Nodes[id]) if err != nil { return node, err } @@ -76,7 +76,7 @@ func (config *NodeYaml) GetNode(id string) (node Node, err error) { if err != nil { return node, err } - for _, p := range cleanList(config.nodes[id].Profiles) { + for _, p := range cleanList(config.Nodes[id].Profiles) { includedProfile, err := config.GetProfile(p) if err != nil { wwlog.Warn("profile not found: %s", p) @@ -114,7 +114,7 @@ otherwise */ func (config *NodeYaml) GetNodeOnly(id string) (node Node, err error) { node = EmptyNode() - if found, ok := config.nodes[id]; ok { + if found, ok := config.Nodes[id]; ok { return *found, nil } return node, ErrNotFound @@ -126,7 +126,7 @@ otherwise */ func (config *NodeYaml) GetNodeOnlyPtr(id string) (*Node, error) { node := EmptyNode() - if found, ok := config.nodes[id]; ok { + if found, ok := config.Nodes[id]; ok { return found, nil } return &node, ErrNotFound @@ -136,7 +136,7 @@ func (config *NodeYaml) GetNodeOnlyPtr(id string) (*Node, error) { Get the profile with id, return ErrNotFound otherwise */ func (config *NodeYaml) GetProfile(id string) (profile Profile, err error) { - if found, ok := config.nodeProfiles[id]; ok { + if found, ok := config.NodeProfiles[id]; ok { found.id = id return *found, nil } @@ -147,7 +147,7 @@ func (config *NodeYaml) GetProfile(id string) (profile Profile, err error) { Get the profile with id, return ErrNotFound otherwise */ func (config *NodeYaml) GetProfilePtr(id string) (profile *Profile, err error) { - if found, ok := config.nodeProfiles[id]; ok { + if found, ok := config.NodeProfiles[id]; ok { found.id = id return found, nil } @@ -160,7 +160,7 @@ the nodes with the given nodes. */ func (config *NodeYaml) FindAllNodes(nodes ...string) (nodeList []Node, err error) { if len(nodes) == 0 { - for n := range config.nodes { + for n := range config.Nodes { nodes = append(nodes, n) } } @@ -190,7 +190,7 @@ Return all nodes as ProfileConf */ func (config *NodeYaml) FindAllProfiles(nodes ...string) (profileList []Profile, err error) { if len(nodes) == 0 { - for n := range config.nodeProfiles { + for n := range config.NodeProfiles { nodes = append(nodes, n) } } @@ -220,8 +220,8 @@ func (config *NodeYaml) FindAllProfiles(nodes ...string) (profileList []Profile, Return the names of all available nodes */ func (config *NodeYaml) ListAllNodes() []string { - nodeList := make([]string, len(config.nodes)) - for name := range config.nodes { + nodeList := make([]string, len(config.Nodes)) + for name := range config.Nodes { nodeList = append(nodeList, name) } return nodeList @@ -232,7 +232,7 @@ Return the names of all available nodes */ func (config *NodeYaml) ListAllProfiles() []string { var nodeList []string - for name := range config.nodeProfiles { + for name := range config.NodeProfiles { nodeList = append(nodeList, name) } return nodeList diff --git a/internal/pkg/node/constuctors_test.go b/internal/pkg/node/constructors_test.go similarity index 99% rename from internal/pkg/node/constuctors_test.go rename to internal/pkg/node/constructors_test.go index 246b852a..382f8814 100644 --- a/internal/pkg/node/constuctors_test.go +++ b/internal/pkg/node/constructors_test.go @@ -138,7 +138,7 @@ func Test_FindDiscoverableNode(t *testing.T) { t.Run(tt.description, func(t *testing.T) { config := newConstructorPrimaryNetworkTest(t) for _, node := range tt.discoverable_nodes { - config.nodes[node].Discoverable = "true" + config.Nodes[node].Discoverable = "true" } discovered_node, discovered_interface, err := config.FindDiscoverableNode() if !tt.succeed { diff --git a/internal/pkg/node/datastructure.go b/internal/pkg/node/datastructure.go index 40e635be..6735fc3d 100644 --- a/internal/pkg/node/datastructure.go +++ b/internal/pkg/node/datastructure.go @@ -3,9 +3,7 @@ package node import ( "net" - "github.com/warewulf/warewulf/internal/pkg/wwlog" "github.com/warewulf/warewulf/internal/pkg/wwtype" - "gopkg.in/yaml.v3" ) const undef string = "UNDEF" @@ -17,8 +15,8 @@ const undef string = "UNDEF" Structure of which goes to disk */ type NodeYaml struct { - nodeProfiles map[string]*Profile - nodes map[string]*Node + NodeProfiles map[string]*Profile + Nodes map[string]*Node } /* @@ -127,45 +125,3 @@ type FileSystem struct { Options []string `yaml:"options,omitempty" comment:"any additional options to be passed to the format-specific mkfs utility"` MountOptions string `yaml:"mount_options,omitempty" comment:"any special options to be passed to the mount command"` } - -/* -interface so that nodes and profiles which aren't exported will -be marshaled -*/ -type ExportedYml struct { - NodeProfiles map[string]*Profile `yaml:"nodeprofiles"` - Nodes map[string]*Node `yaml:"nodes"` -} - -/* -Marshall Exported stuff, not NodeYaml directly -*/ -func (yml *NodeYaml) MarshalYAML() (interface{}, error) { - wwlog.Debug("marshall yml") - var exp ExportedYml - exp.Nodes = yml.nodes - exp.NodeProfiles = yml.nodeProfiles - node := yaml.Node{} - err := node.Encode(exp) - if err != nil { - return node, err - } - return node, err -} - -/* -Unmarshal to intermediate format -*/ -func (yml *NodeYaml) UnmarshalYAML( - unmarshal func(interface{}) (err error), -) (err error) { - wwlog.Debug("UnmarshalYAML called") - var exp ExportedYml - err = unmarshal(&exp) - if err != nil { - return - } - yml.nodes = exp.Nodes - yml.nodeProfiles = exp.NodeProfiles - return nil -} diff --git a/internal/pkg/node/hash.go b/internal/pkg/node/hash.go index 1c57dce9..18814bac 100644 --- a/internal/pkg/node/hash.go +++ b/internal/pkg/node/hash.go @@ -13,10 +13,10 @@ Calculate the hash of NodeYaml in an orderder fashion */ func (config *NodeYaml) Hash() [32]byte { // flatten out profiles and nodes - for _, val := range config.nodeProfiles { + for _, val := range config.NodeProfiles { val.Flatten() } - for _, val := range config.nodes { + for _, val := range config.Nodes { val.Flatten() } data, err := yaml.Marshal(config) diff --git a/internal/pkg/node/list.go b/internal/pkg/node/list.go index 490205d6..9ca4e59a 100644 --- a/internal/pkg/node/list.go +++ b/internal/pkg/node/list.go @@ -44,7 +44,7 @@ Get all the info out of NodeConf. If emptyFields is set true, all fields are sho func (nodeYml *NodeYaml) GetFields(node Node) (output []NodeFields) { nodeMap := make(fieldMap) for _, p := range node.Profiles { - if profile, ok := nodeYml.nodeProfiles[p]; ok { + if profile, ok := nodeYml.NodeProfiles[p]; ok { nodeMap.importFields(profile, "", p) } } diff --git a/internal/pkg/node/modifiers.go b/internal/pkg/node/modifiers.go index c6b3f7d6..6063614e 100644 --- a/internal/pkg/node/modifiers.go +++ b/internal/pkg/node/modifiers.go @@ -17,10 +17,10 @@ Add a node with the given ID and return a pointer to it func (config *NodeYaml) AddNode(nodeID string) (*Node, error) { newNode := NewNode(nodeID) wwlog.Verbose("Adding new node: %s", nodeID) - if _, ok := config.nodes[nodeID]; ok { + if _, ok := config.Nodes[nodeID]; ok { return nil, errors.New("nodename already exists: " + nodeID) } else { - config.nodes[nodeID] = &newNode + config.Nodes[nodeID] = &newNode } return &newNode, nil } @@ -29,12 +29,12 @@ func (config *NodeYaml) AddNode(nodeID string) (*Node, error) { delete node with the given id */ func (config *NodeYaml) DelNode(nodeID string) error { - if _, ok := config.nodes[nodeID]; !ok { + if _, ok := config.Nodes[nodeID]; !ok { return errors.New("nodename does not exist: " + nodeID) } wwlog.Verbose("Deleting node: %s", nodeID) - delete(config.nodes, nodeID) + delete(config.Nodes, nodeID) return nil } @@ -43,7 +43,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 Node) error { - node, ok := config.nodes[nodeID] + node, ok := config.Nodes[nodeID] if !ok { return ErrNotFound } @@ -62,7 +62,7 @@ func (config *NodeYaml) SetNode(nodeID string, vals Node) error { set profile for the node with id the values of vals */ func (config *NodeYaml) SetProfile(profileId string, vals Profile) error { - profile, ok := config.nodeProfiles[profileId] + profile, ok := config.NodeProfiles[profileId] if !ok { return ErrNotFound } @@ -83,10 +83,10 @@ Add a node with the given ID and return a pointer to it func (config *NodeYaml) AddProfile(profileId string) (*Profile, error) { profile := EmptyProfile() wwlog.Verbose("adding new profile: %s", profileId) - if _, ok := config.nodeProfiles[profileId]; ok { + if _, ok := config.NodeProfiles[profileId]; ok { return nil, errors.New("profile already exists: " + profileId) } else { - config.nodeProfiles[profileId] = &profile + config.NodeProfiles[profileId] = &profile } return &profile, nil } @@ -95,12 +95,12 @@ func (config *NodeYaml) AddProfile(profileId string) (*Profile, error) { delete node with the given id */ func (config *NodeYaml) DelProfile(nodeID string) error { - if _, ok := config.nodes[nodeID]; !ok { + if _, ok := config.Nodes[nodeID]; !ok { return errors.New("profile does not exist: " + nodeID) } wwlog.Verbose("deleting profile: %s", nodeID) - delete(config.nodes, nodeID) + delete(config.Nodes, nodeID) return nil } @@ -134,10 +134,10 @@ instance. Passes through any errors generated by yaml.Marshal. */ func (config *NodeYaml) Dump() ([]byte, error) { // flatten out profiles and nodes - for _, val := range config.nodeProfiles { + for _, val := range config.NodeProfiles { val.Flatten() } - for _, val := range config.nodes { + for _, val := range config.Nodes { val.Flatten() } var buf bytes.Buffer