Merge pull request #2028 from gravitl/fix/GRA-1200/default_hosts

adapt createNetwork + default host addition
This commit is contained in:
dcarns 2023-02-13 15:40:48 -05:00 committed by GitHub
commit ddf538da91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 20 deletions

View file

@ -403,11 +403,6 @@ func createNetwork(w http.ResponseWriter, r *http.Request) {
return
}
if err = logic.AddDefaultHostsToNetwork(network.NetID, servercfg.GetServer()); err != nil {
logger.Log(0, fmt.Sprintf("failed to add default hosts to network [%v]: %v",
network.NetID, err.Error()))
}
defaultHosts := logic.GetDefaultHosts()
for i := range defaultHosts {
currHost := &defaultHosts[i]

View file

@ -216,6 +216,7 @@ func UpdateHostNetwork(h *models.Host, network string, add bool) (*models.Node,
newNode := models.Node{}
newNode.Server = servercfg.GetServer()
newNode.Network = network
newNode.HostID = h.ID
if err := AssociateNodeToHost(&newNode, h); err != nil {
return nil, err
}
@ -308,21 +309,6 @@ func GetDefaultHosts() []models.Host {
return defaultHostList[:]
}
// AddDefaultHostsToNetwork - adds a node to network for every default host on Netmaker server
func AddDefaultHostsToNetwork(network, server string) error {
// add default hosts to network
defaultHosts := GetDefaultHosts()
for i := range defaultHosts {
newNode := models.Node{}
newNode.Network = network
newNode.Server = server
if err := AssociateNodeToHost(&newNode, &defaultHosts[i]); err != nil {
return err
}
}
return nil
}
// GetHostNetworks - fetches all the networks
func GetHostNetworks(hostID string) []string {
currHost, err := GetHost(hostID)