Files
warewulf/internal/pkg/api/profile/edit.go
Jonathon Anderson b331fd12af Remove dead code
Verified with

```
deadcode -test ./...
```

Followed-up with a lint check.

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
2024-10-18 15:09:01 -06:00

61 lines
1.5 KiB
Go

package apiprofile
import (
"fmt"
"os"
"github.com/pkg/errors"
"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.v3"
)
/*
Returns filtered list of nodes
*/
func FilteredProfiles(profileList *wwapiv1.NodeList) *wwapiv1.NodeYaml {
nodeDB, err := node.New()
if err != nil {
wwlog.Error("Could not open nodeDB: %s\n", err)
os.Exit(1)
}
profiles, _ := nodeDB.FindAllProfiles()
profiles = node.FilterProfileListByName(profiles, profileList.Output)
buffer, _ := yaml.Marshal(profiles)
retVal := wwapiv1.NodeYaml{
NodeConfMapYaml: string(buffer),
}
return &retVal
}
/*
Add profiles from yaml
*/
func ProfileAddFromYaml(nodeList *wwapiv1.NodeAddParameter) (err error) {
nodeDB, err := node.New()
if err != nil {
return errors.Wrap(err, "Could not open NodeDB: %s\n")
}
if nodeDB.StringHash() != nodeList.Hash && !nodeList.Force {
return fmt.Errorf("got wrong hash, not modifying profile database")
}
profileMap := make(map[string]*node.ProfileConf)
err = yaml.Unmarshal([]byte(nodeList.NodeConfYaml), profileMap)
if err != nil {
return errors.Wrap(err, "Could not unmarshall Yaml: %s\n")
}
for profileName, profile := range profileMap {
err = nodeDB.SetProfile(profileName, *profile)
if err != nil {
return errors.Wrap(err, "couldn't set profile")
}
}
err = nodeDB.Persist()
if err != nil {
return errors.Wrap(err, "failed to persist nodedb")
}
return nil
}