BUGFIX: should update cluster info with new info for my device, if my device was previously registered with different info
This commit is contained in:
parent
70eb98da76
commit
2523a2da6d
|
@ -23,9 +23,19 @@ class EtcdClient:
|
|||
with self.etcd.lock('syncthing_monitor'):
|
||||
cluster_info = self.load_cluster_info()
|
||||
|
||||
if any(device_id in device['id'] for device in cluster_info['devices']):
|
||||
print("Checking for existing device with node name '{0}'...".format(node_name), flush=True)
|
||||
existing_device = next(
|
||||
(device for device in cluster_info['devices'] if node_name in device['node_name']),
|
||||
None)
|
||||
|
||||
if existing_device is not None:
|
||||
self.update_existing_device(cluster_info, existing_device, device_id, node_name, address)
|
||||
return
|
||||
|
||||
print(
|
||||
"Existing device not found; Creating new cluster_info entry for node name: '{0}'...".format(node_name),
|
||||
flush=True)
|
||||
|
||||
new_device = {
|
||||
'id': device_id,
|
||||
'node_name': node_name,
|
||||
|
@ -34,6 +44,22 @@ class EtcdClient:
|
|||
|
||||
cluster_info['devices'].append(new_device)
|
||||
|
||||
self.do_cluster_info_update(cluster_info)
|
||||
|
||||
def update_existing_device(self, cluster_info, existing_device, device_id, node_name, address):
|
||||
|
||||
if device_id == existing_device['id']:
|
||||
print("Existing device contains up-to-date ID! No need to update.".format(node_name), flush=True)
|
||||
return
|
||||
|
||||
print("Existing device with my node name '{0}' contains stale info! Updating...".format(node_name), flush=True)
|
||||
existing_device['id'] = device_id
|
||||
existing_device['address'] = address
|
||||
|
||||
self.do_cluster_info_update(cluster_info)
|
||||
|
||||
@retry(stop_max_delay=60000, wait_fixed=500)
|
||||
def do_cluster_info_update(self, cluster_info):
|
||||
print("Updating etcd value for '{0}': {1}".format(self.key, json.dumps(cluster_info)), flush=True)
|
||||
self.etcd.put(self.key, json.dumps(cluster_info))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user