Fail API add node if node exists

This commit is contained in:
MatthewHink
2025-06-13 12:10:53 -07:00
parent a99b4eead2
commit 0a1d12e6d4
2 changed files with 5 additions and 0 deletions

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)