api changes to modify unexported fields

changes can now not be done directly but must
go to SetNode or SetProfile. Although its also
now possible to access the field direclty with
GetNodePtr

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Christian Goll
2023-12-20 15:42:44 +01:00
committed by Jonathon Anderson
parent 4c8a07f1dc
commit 9ba1aa8d63
12 changed files with 130 additions and 122 deletions

View File

@@ -8,7 +8,7 @@ import (
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
"github.com/warewulf/warewulf/internal/pkg/node"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)
/*
@@ -20,7 +20,7 @@ func FindAllProfileConfs() *wwapiv1.NodeYaml {
wwlog.Error("Could not open nodeDB: %s\n", err)
os.Exit(1)
}
profileMap := nodeDB.NodeProfiles
profileMap, _ := nodeDB.FindAllProfiles()
// ignore err as nodeDB should always be correct
buffer, _ := yaml.Marshal(profileMap)
retVal := wwapiv1.NodeYaml{
@@ -38,8 +38,8 @@ func FilteredProfiles(profileList *wwapiv1.NodeList) *wwapiv1.NodeYaml {
wwlog.Error("Could not open nodeDB: %s\n", err)
os.Exit(1)
}
profileMap := nodeDB.NodeProfiles
profileMap = node.FilterProfilesByName(profileMap, profileList.Output)
profileMap, _ := nodeDB.FindAllProfiles()
//profileMap = node.FilterProfilesByName(profileMap, profileList.Output)
buffer, _ := yaml.Marshal(profileMap)
retVal := wwapiv1.NodeYaml{
NodeConfMapYaml: string(buffer),
@@ -65,7 +65,10 @@ func ProfileAddFromYaml(nodeList *wwapiv1.NodeAddParameter) (err error) {
return errors.Wrap(err, "Could not unmarshall Yaml: %s\n")
}
for profileName, profile := range profileMap {
nodeDB.NodeProfiles[profileName] = profile
err = nodeDB.SetProfile(profileName, *profile)
if err != nil {
return errors.Wrap(err, "couldn't set profile")
}
}
err = nodeDB.Persist()
if err != nil {