Rename NodeConf to NodesConf

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2024-11-03 15:29:37 -07:00
parent 76acd8ff80
commit fdbdf88df0
14 changed files with 44 additions and 44 deletions

View File

@@ -82,7 +82,7 @@ func ContainerBuild(cbp *wwapiv1.ContainerBuildParameter) (err error) {
if len(containers) != 1 {
return fmt.Errorf("can only set default for one container")
} else {
var nodeDB node.NodeYaml
var nodeDB node.NodesYaml
nodeDB, err = node.New()
if err != nil {
return fmt.Errorf("could not open node configuration: %s", err)
@@ -238,7 +238,7 @@ func ContainerImport(cip *wwapiv1.ContainerImportParameter) (containerName strin
}
if cip.Default {
var nodeDB node.NodeYaml
var nodeDB node.NodesYaml
nodeDB, err = node.New()
if err != nil {
err = fmt.Errorf("could not open node configuration: %s", err.Error())

View File

@@ -17,7 +17,7 @@ func NodeSet(set *wwapiv1.ConfSetParameter) (err error) {
if set == nil {
return fmt.Errorf("NodeSetParameter is nil")
}
var nodeDB node.NodeYaml
var nodeDB node.NodesYaml
nodeDB, _, err = NodeSetParameterCheck(set)
if err != nil {
return err
@@ -35,7 +35,7 @@ func NodeSet(set *wwapiv1.ConfSetParameter) (err error) {
NodeSetParameterCheck does error checking and returns a modified
NodeYml which than can be persisted
*/
func NodeSetParameterCheck(set *wwapiv1.ConfSetParameter) (nodeDB node.NodeYaml, count uint, err error) {
func NodeSetParameterCheck(set *wwapiv1.ConfSetParameter) (nodeDB node.NodesYaml, count uint, err error) {
nodeDB, err = node.New()
if err != nil {
wwlog.Error("Could not open configuration: %s", err)

View File

@@ -40,7 +40,7 @@ func ProfileDelete(ndp *wwapiv1.NodeDeleteParameter) (err error) {
// ProfileDeleteParameterCheck does error checking on ProfileDeleteParameter.
// Output to the console if console is true.
// Returns the profiles to delete.
func ProfileDeleteParameterCheck(ndp *wwapiv1.NodeDeleteParameter, console bool) (nodeDB node.NodeYaml, profileList []string, err error) {
func ProfileDeleteParameterCheck(ndp *wwapiv1.NodeDeleteParameter, console bool) (nodeDB node.NodesYaml, profileList []string, err error) {
if ndp == nil {
err = fmt.Errorf("profileDeleteParameter is nil")

View File

@@ -35,7 +35,7 @@ func ProfileSet(set *wwapiv1.ConfSetParameter) (err error) {
NodeSetParameterCheck does error checking and returns a modified
NodeYml which than can be persisted
*/
func ProfileSetParameterCheck(set *wwapiv1.ConfSetParameter) (nodeDB node.NodeYaml, count uint, err error) {
func ProfileSetParameterCheck(set *wwapiv1.ConfSetParameter) (nodeDB node.NodesYaml, count uint, err error) {
nodeDB, err = node.New()
if err != nil {
wwlog.Error("Could not open configuration: %s", err)

View File

@@ -21,7 +21,7 @@ var (
/*
Creates a new nodeDb object from the on-disk configuration
*/
func New() (NodeYaml, error) {
func New() (NodesYaml, error) {
conf := warewulfconf.Get()
if ConfigFile == "" {
ConfigFile = path.Join(conf.Paths.Sysconfdir, "warewulf/nodes.conf")
@@ -29,7 +29,7 @@ func New() (NodeYaml, error) {
wwlog.Verbose("Opening node configuration file: %s", ConfigFile)
data, err := os.ReadFile(ConfigFile)
if err != nil {
return NodeYaml{}, err
return NodesYaml{}, err
}
return Parse(data)
}
@@ -38,7 +38,7 @@ func New() (NodeYaml, error) {
// document. Passes any errors return from yaml.Unmarshal. Returns an
// error if any parsed value is not of a valid type for the given
// parameter.
func Parse(data []byte) (nodeList NodeYaml, err error) {
func Parse(data []byte) (nodeList NodesYaml, err error) {
wwlog.Debug("Unmarshaling the node configuration")
err = yaml.Unmarshal(data, &nodeList)
if err != 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 Node, err error) {
func (config *NodesYaml) GetNode(id string) (node Node, err error) {
if _, ok := config.Nodes[id]; !ok {
return node, ErrNotFound
}
@@ -112,7 +112,7 @@ func (config *NodeYaml) GetNode(id string) (node Node, err error) {
Return the node with the id string without the merged in nodes, return ErrNotFound
otherwise
*/
func (config *NodeYaml) GetNodeOnly(id string) (node Node, err error) {
func (config *NodesYaml) 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 Node, 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) (*Node, error) {
func (config *NodesYaml) 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) (*Node, error) {
/*
Get the profile with id, return ErrNotFound otherwise
*/
func (config *NodeYaml) GetProfile(id string) (profile Profile, err error) {
func (config *NodesYaml) 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 Profile, err error) {
/*
Get the profile with id, return ErrNotFound otherwise
*/
func (config *NodeYaml) GetProfilePtr(id string) (profile *Profile, err error) {
func (config *NodesYaml) 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 *Profile, err error) {
Get the nodes from the loaded configuration. This function also merges
the nodes with the given nodes.
*/
func (config *NodeYaml) FindAllNodes(nodes ...string) (nodeList []Node, err error) {
func (config *NodesYaml) 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 []Node, err erro
/*
Return all nodes as ProfileConf
*/
func (config *NodeYaml) FindAllProfiles(nodes ...string) (profileList []Profile, err error) {
func (config *NodesYaml) FindAllProfiles(nodes ...string) (profileList []Profile, err error) {
if len(nodes) == 0 {
for n := range config.NodeProfiles {
nodes = append(nodes, n)
@@ -219,7 +219,7 @@ func (config *NodeYaml) FindAllProfiles(nodes ...string) (profileList []Profile,
/*
Return the names of all available nodes
*/
func (config *NodeYaml) ListAllNodes() []string {
func (config *NodesYaml) ListAllNodes() []string {
nodeList := make([]string, len(config.Nodes))
for name := range config.Nodes {
nodeList = append(nodeList, name)
@@ -230,7 +230,7 @@ func (config *NodeYaml) ListAllNodes() []string {
/*
Return the names of all available nodes
*/
func (config *NodeYaml) ListAllProfiles() []string {
func (config *NodesYaml) ListAllProfiles() []string {
var nodeList []string
for name := range config.NodeProfiles {
nodeList = append(nodeList, name)
@@ -246,7 +246,7 @@ without a hardware address is returned.
If no unconfigured node is found, an error is returned.
*/
func (config *NodeYaml) FindDiscoverableNode() (Node, string, error) {
func (config *NodesYaml) FindDiscoverableNode() (Node, string, error) {
nodes, _ := config.FindAllNodes()

View File

@@ -8,7 +8,7 @@ import (
"gopkg.in/yaml.v3"
)
func newConstructorPrimaryNetworkTest(t *testing.T) NodeYaml {
func newConstructorPrimaryNetworkTest(t *testing.T) NodesYaml {
var data = `
nodeprofiles:
default:
@@ -53,7 +53,7 @@ nodes:
override:
device: ib1
`
var ret NodeYaml
var ret NodesYaml
err := yaml.Unmarshal([]byte(data), &ret)
assert.NoError(t, err)
return ret
@@ -193,7 +193,7 @@ nodes:
- profile2
`
assert := assert.New(t)
var ymlSrc NodeYaml
var ymlSrc NodesYaml
err := yaml.Unmarshal([]byte(nodesconf), &ymlSrc)
assert.NoError(err)
wwlog.SetLogLevel(wwlog.DEBUG)

View File

@@ -14,7 +14,7 @@ const undef string = "UNDEF"
/*
Structure of which goes to disk
*/
type NodeYaml struct {
type NodesYaml struct {
NodeProfiles map[string]*Profile
Nodes map[string]*Node
}

View File

@@ -11,7 +11,7 @@ import (
/*
Calculate the hash of NodeYaml in an orderder fashion
*/
func (config *NodeYaml) Hash() [32]byte {
func (config *NodesYaml) Hash() [32]byte {
// flatten out profiles and nodes
for _, val := range config.NodeProfiles {
val.Flatten()
@@ -29,7 +29,7 @@ func (config *NodeYaml) Hash() [32]byte {
/*
Return the hash as string
*/
func (config *NodeYaml) StringHash() string {
func (config *NodesYaml) StringHash() string {
buffer := config.Hash()
return hex.EncodeToString(buffer[:])
}

View File

@@ -75,7 +75,7 @@ nodes:
default:
ipaddr: 10.0.10.3
`
var nodeConf1, nodeConf2, nodeConf3 NodeYaml
var nodeConf1, nodeConf2, nodeConf3 NodesYaml
err := yaml.Unmarshal([]byte(nodeConfYml1), &nodeConf1)
assert.NoError(t, err)
err = yaml.Unmarshal([]byte(nodeConfYml2), &nodeConf2)
@@ -84,7 +84,7 @@ nodes:
assert.NoError(t, err)
t.Run("Same NodeYaml with same conf", func(t *testing.T) {
var testConf NodeYaml
var testConf NodesYaml
err = yaml.Unmarshal([]byte(nodeConfYml1), &testConf)
assert.NoError(t, err)
if testConf.Hash() != nodeConf1.Hash() {

View File

@@ -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 Node) (output []NodeFields) {
func (nodeYml *NodesYaml) 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 Node) (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 Profile) (output []NodeFields) {
func (nodeYml *NodesYaml) GetFieldsProfile(profile Profile) (output []NodeFields) {
profileMap := make(fieldMap)
profileMap.importFields(&profile, "", "")
for _, elem := range profileMap {

View File

@@ -14,7 +14,7 @@ import (
/*
Add a node with the given ID and return a pointer to it
*/
func (config *NodeYaml) AddNode(nodeID string) (*Node, error) {
func (config *NodesYaml) AddNode(nodeID string) (*Node, error) {
newNode := NewNode(nodeID)
wwlog.Verbose("Adding new node: %s", nodeID)
if _, ok := config.Nodes[nodeID]; ok {
@@ -28,7 +28,7 @@ func (config *NodeYaml) AddNode(nodeID string) (*Node, error) {
/*
delete node with the given id
*/
func (config *NodeYaml) DelNode(nodeID string) error {
func (config *NodesYaml) DelNode(nodeID string) error {
if _, ok := config.Nodes[nodeID]; !ok {
return errors.New("nodename does not exist: " + nodeID)
}
@@ -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 Node) error {
func (config *NodesYaml) 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 Node) error {
/*
set profile for the node with id the values of vals
*/
func (config *NodeYaml) SetProfile(profileId string, vals Profile) error {
func (config *NodesYaml) 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 Profile) error {
/*
Add a node with the given ID and return a pointer to it
*/
func (config *NodeYaml) AddProfile(profileId string) (*Profile, error) {
func (config *NodesYaml) AddProfile(profileId string) (*Profile, error) {
profile := EmptyProfile()
wwlog.Verbose("adding new profile: %s", profileId)
if _, ok := config.NodeProfiles[profileId]; ok {
@@ -94,7 +94,7 @@ func (config *NodeYaml) AddProfile(profileId string) (*Profile, error) {
/*
delete node with the given id
*/
func (config *NodeYaml) DelProfile(nodeID string) error {
func (config *NodesYaml) DelProfile(nodeID string) error {
if _, ok := config.Nodes[nodeID]; !ok {
return errors.New("profile does not exist: " + nodeID)
}
@@ -108,7 +108,7 @@ func (config *NodeYaml) DelProfile(nodeID string) error {
/*
Write the the NodeYaml to disk.
*/
func (config *NodeYaml) Persist() error {
func (config *NodesYaml) Persist() error {
out, dumpErr := config.Dump()
if dumpErr != nil {
wwlog.Error("%s", dumpErr)
@@ -132,7 +132,7 @@ func (config *NodeYaml) Persist() error {
Dump returns a YAML document representing the nodeDb
instance. Passes through any errors generated by yaml.Marshal.
*/
func (config *NodeYaml) Dump() ([]byte, error) {
func (config *NodesYaml) Dump() ([]byte, error) {
// flatten out profiles and nodes
for _, val := range config.NodeProfiles {
val.Flatten()

View File

@@ -10,7 +10,7 @@ import (
/*
Gets a node by its hardware(mac) address
*/
func (config *NodeYaml) FindByHwaddr(hwa string) (Node, error) {
func (config *NodesYaml) FindByHwaddr(hwa string) (Node, error) {
if _, err := net.ParseMAC(hwa); err != nil {
return Node{}, errors.New("invalid hardware address: " + hwa)
}
@@ -29,7 +29,7 @@ func (config *NodeYaml) FindByHwaddr(hwa string) (Node, error) {
/*
Find a node by its ip address
*/
func (config *NodeYaml) FindByIpaddr(ipaddr string) (Node, error) {
func (config *NodesYaml) FindByIpaddr(ipaddr string) (Node, error) {
addr := net.ParseIP(ipaddr)
if addr == nil {
return Node{}, errors.New("invalid IP:" + ipaddr)

View File

@@ -8,7 +8,7 @@ import (
"gopkg.in/yaml.v3"
)
func NewUtilTestNode() (NodeYaml, error) {
func NewUtilTestNode() (NodesYaml, error) {
var data = `
nodeprofiles:
default:
@@ -41,7 +41,7 @@ nodes:
default: false
ipaddr: fd1a:2b3c:4d5e:06f0:1234:5678:90ab:cdef
`
var ret NodeYaml
var ret NodesYaml
err := yaml.Unmarshal([]byte(data), &ret)
if err != nil {
return ret, err
@@ -62,7 +62,7 @@ func Test_nodeYaml_FindByHwaddr(t *testing.T) {
tests := []struct {
name string
//fields fields
config NodeYaml
config NodesYaml
args args
want string
wantErr bool
@@ -100,7 +100,7 @@ func Test_nodeYaml_FindByIpaddr(t *testing.T) {
}
tests := []struct {
name string
config NodeYaml
config NodesYaml
args args
want string
wantErr bool

View File

@@ -12,7 +12,7 @@ import (
type nodeDB struct {
lock sync.RWMutex
NodeInfo map[string]string
yml node.NodeYaml
yml node.NodesYaml
}
var (