mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-12 08:04:25 +08:00
update host network fix
This commit is contained in:
parent
b017e41e52
commit
8ad87f5a81
1 changed files with 17 additions and 9 deletions
|
@ -159,6 +159,23 @@ func RemoveHostByID(hostID string) error {
|
|||
|
||||
// UpdateHostNetwork - adds/deletes host from a network
|
||||
func UpdateHostNetwork(h *models.Host, network string, add bool) (*models.Node, error) {
|
||||
for _, nodeID := range h.Nodes {
|
||||
node, err := GetNodeByID(nodeID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if node.Network == network {
|
||||
if !add {
|
||||
return &node, nil
|
||||
} else {
|
||||
return nil, errors.New("host already part of network " + network)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if !add {
|
||||
return nil, errors.New("host not part of the network " + network)
|
||||
}
|
||||
|
||||
if add {
|
||||
newNode := models.Node{}
|
||||
|
@ -169,15 +186,6 @@ func UpdateHostNetwork(h *models.Host, network string, add bool) (*models.Node,
|
|||
}
|
||||
return &newNode, nil
|
||||
}
|
||||
for _, nodeID := range h.Nodes {
|
||||
node, err := GetNodeByID(nodeID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if node.Network == network {
|
||||
return &node, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, errors.New("failed to update host networks")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue