Merge pull request #1926 from MatthewHink/mhink-node-dupicate

Fail API add node if node exists
This commit is contained in:
Christian Goll
2025-06-16 10:40:46 +02:00
committed by GitHub
2 changed files with 5 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Updated 70-persistent-net.rules.ww to use `(lower $netdev.Type)` for case-insensitive comparison of "infiniband".
- Fixed a regression in SELinux support by restoring the `/run` mount during wwinit. #1910
- Fixed `wwctl profile set` for disks, partitions and file systems. #1883
- Do not let API add a node that exists
### Changed

View File

@@ -123,9 +123,13 @@ func addNode() usecase.Interactor {
u := usecase.NewInteractor(func(ctx context.Context, input addNodeInput, output *node.Node) error {
wwlog.Debug("api.addNode(ID:%v, Node:%+v)", input.ID, input.Node)
// registry is the warewulf node "db" yaml file.
if registry, err := node.New(); err != nil {
return err
} else {
if _, ok := registry.Nodes[input.ID]; ok {
return status.Wrap(fmt.Errorf("node name '%s' already exists", input.ID), status.InvalidArgument)
}
for _, profile := range input.Node.Profiles {
if _, ok := registry.NodeProfiles[profile]; !ok {
return status.Wrap(fmt.Errorf("profile '%s' does not exist", profile), status.InvalidArgument)