mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-09 02:30:49 +08:00
disallowed hosts removal if nodes still associated
This commit is contained in:
@@ -146,15 +146,7 @@ func UpsertHost(h *models.Host) error {
|
|||||||
// RemoveHost - removes a given host from server
|
// RemoveHost - removes a given host from server
|
||||||
func RemoveHost(h *models.Host) error {
|
func RemoveHost(h *models.Host) error {
|
||||||
if len(h.Nodes) > 0 {
|
if len(h.Nodes) > 0 {
|
||||||
for i := range h.Nodes {
|
return fmt.Errorf("host still has associated nodes")
|
||||||
id := h.Nodes[i]
|
|
||||||
n, err := GetNodeByID(id)
|
|
||||||
if err == nil {
|
|
||||||
if err = DissasociateNodeFromHost(&n, h); err != nil {
|
|
||||||
return err // must remove associated nodes before removing a host
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return database.DeleteRecord(database.HOSTS_TABLE_NAME, h.ID.String())
|
return database.DeleteRecord(database.HOSTS_TABLE_NAME, h.ID.String())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user