mirror of
				https://github.com/gravitl/netmaker.git
				synced 2025-10-31 08:26:23 +08:00 
			
		
		
		
	Merge pull request #1911 from gravitl/story/GRA-822d-2
disallowed hosts removal if nodes still associated
This commit is contained in:
		
						commit
						89bffba30e
					
				
					 1 changed files with 1 additions and 9 deletions
				
			
		|  | @ -146,15 +146,7 @@ func UpsertHost(h *models.Host) error { | |||
| // RemoveHost - removes a given host from server | ||||
| func RemoveHost(h *models.Host) error { | ||||
| 	if len(h.Nodes) > 0 { | ||||
| 		for i := range h.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 fmt.Errorf("host still has associated nodes") | ||||
| 	} | ||||
| 	return database.DeleteRecord(database.HOSTS_TABLE_NAME, h.ID.String()) | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue