@@ -24,6 +24,7 @@ func FindAllNodeConfs() *wwapiv1.NodeYaml {
|
||||
buffer, _ := yaml.Marshal(nodeMap)
|
||||
retVal := wwapiv1.NodeYaml{
|
||||
NodeConfMapYaml: string(buffer),
|
||||
Hash: nodeDB.StringHash(),
|
||||
}
|
||||
return &retVal
|
||||
}
|
||||
@@ -42,6 +43,7 @@ func FilteredNodes(nodeList *wwapiv1.NodeList) *wwapiv1.NodeYaml {
|
||||
buffer, _ := yaml.Marshal(nodeMap)
|
||||
retVal := wwapiv1.NodeYaml{
|
||||
NodeConfMapYaml: string(buffer),
|
||||
Hash: nodeDB.StringHash(),
|
||||
}
|
||||
return &retVal
|
||||
}
|
||||
|
||||
20
internal/pkg/api/node/hash.go
Normal file
20
internal/pkg/api/node/hash.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package apinode
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
func Hash() *wwapiv1.NodeDBHash {
|
||||
config, err := node.New()
|
||||
if err != nil {
|
||||
wwlog.Warn("couldb't read config")
|
||||
}
|
||||
hash := config.Hash()
|
||||
return &wwapiv1.NodeDBHash{
|
||||
Hash: hex.EncodeToString(hash[:]),
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package apinode
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -29,7 +30,10 @@ func NodeAdd(nap *wwapiv1.NodeAddParameter) (err error) {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to open node database")
|
||||
}
|
||||
|
||||
dbHash := nodeDB.Hash()
|
||||
if hex.EncodeToString(dbHash[:]) != nap.Hash && !nap.Force {
|
||||
return fmt.Errorf("got wrong hash, not modifying node database")
|
||||
}
|
||||
node_args := hostlist.Expand(nap.NodeNames)
|
||||
var nodeConf node.NodeConf
|
||||
err = yaml.Unmarshal([]byte(nap.NodeConfYaml), &nodeConf)
|
||||
@@ -95,6 +99,10 @@ func NodeDelete(ndp *wwapiv1.NodeDeleteParameter) (err error) {
|
||||
wwlog.Error("Failed to open node database: %s", err)
|
||||
return
|
||||
}
|
||||
dbHash := nodeDB.Hash()
|
||||
if hex.EncodeToString(dbHash[:]) != ndp.Hash && !ndp.Force {
|
||||
return fmt.Errorf("got wrong hash, not modifying node database")
|
||||
}
|
||||
|
||||
for _, n := range nodeList {
|
||||
err := nodeDB.DelNode(n.Id.Get())
|
||||
@@ -133,6 +141,13 @@ func NodeDeleteParameterCheck(ndp *wwapiv1.NodeDeleteParameter, console bool) (n
|
||||
wwlog.Error("Failed to open node database: %s", err)
|
||||
return
|
||||
}
|
||||
dbHash := nodeDB.Hash()
|
||||
if hex.EncodeToString(dbHash[:]) != ndp.Hash && !ndp.Force {
|
||||
wwlog.Debug("got hash: %s", ndp.Hash)
|
||||
wwlog.Debug("actual hash: %s", hex.EncodeToString(dbHash[:]))
|
||||
err = fmt.Errorf("got wrong hash, not modifying node database")
|
||||
return
|
||||
}
|
||||
|
||||
nodes, err := nodeDB.FindAllNodes()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user