mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 01:07:41 +08:00
fixed update issue
This commit is contained in:
@@ -52,6 +52,16 @@ func GetNetworkNodesMemory(allNodes []models.Node, network string) []models.Node
|
|||||||
return nodes
|
return nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateNodeCheckin - updates the checkin time of a node
|
||||||
|
func UpdateNodeCheckin(node *models.Node) error {
|
||||||
|
node.SetLastCheckIn()
|
||||||
|
data, err := json.Marshal(node)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return database.Insert(node.ID.String(), string(data), database.NODES_TABLE_NAME)
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateNode - takes a node and updates another node with it's values
|
// UpdateNode - takes a node and updates another node with it's values
|
||||||
func UpdateNode(currentNode *models.Node, newNode *models.Node) error {
|
func UpdateNode(currentNode *models.Node, newNode *models.Node) error {
|
||||||
if newNode.Address.IP.String() != currentNode.Address.IP.String() {
|
if newNode.Address.IP.String() != currentNode.Address.IP.String() {
|
||||||
|
@@ -382,8 +382,7 @@ func handleHostCheckin(h, currentHost *models.Host) bool {
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
node.SetLastCheckIn()
|
if err := logic.UpdateNodeCheckin(&node); err != nil {
|
||||||
if err := logic.UpdateNode(&node, &node); err != nil {
|
|
||||||
logger.Log(0, "error updating node", node.ID.String(), " on checkin", err.Error())
|
logger.Log(0, "error updating node", node.ID.String(), " on checkin", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,13 +390,16 @@ func handleHostCheckin(h, currentHost *models.Host) bool {
|
|||||||
for i := range h.Interfaces {
|
for i := range h.Interfaces {
|
||||||
h.Interfaces[i].AddressString = h.Interfaces[i].Address.String()
|
h.Interfaces[i].AddressString = h.Interfaces[i].Address.String()
|
||||||
}
|
}
|
||||||
h.HostPass = currentHost.HostPass
|
ifaceDelta := len(h.Interfaces) != len(currentHost.Interfaces) || !h.EndpointIP.Equal(currentHost.EndpointIP)
|
||||||
if err := logic.UpsertHost(h); err != nil {
|
currentHost.EndpointIP = h.EndpointIP
|
||||||
|
currentHost.Interfaces = h.Interfaces
|
||||||
|
currentHost.DefaultInterface = h.DefaultInterface
|
||||||
|
if err := logic.UpsertHost(currentHost); err != nil {
|
||||||
logger.Log(0, "failed to update host after check-in", h.Name, h.ID.String(), err.Error())
|
logger.Log(0, "failed to update host after check-in", h.Name, h.ID.String(), err.Error())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Log(3, "ping processed for host", h.Name, h.ID.String())
|
logger.Log(0, "ping processed for host", h.Name, h.ID.String())
|
||||||
return len(h.Interfaces) != len(currentHost.Interfaces) ||
|
return ifaceDelta
|
||||||
!h.EndpointIP.Equal(currentHost.EndpointIP)
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user