Browse Source

merge_new_data(): build list of aliased_node

Helge Jung 9 years ago
parent
commit
d8b346c6ad
1 changed files with 13 additions and 5 deletions
  1. 13 5
      ffstatus/basestorage.py

+ 13 - 5
ffstatus/basestorage.py

@@ -104,6 +104,9 @@ class BaseStorage(object):
         if newdata is None or not isinstance(newdata, dict):
             raise ValueError("Expected a dict as new data.")
 
+        # keep a list of aliased nodes so they can be removed from the result
+        aliased_nodes = {}
+
         # start merge on a copy of the current data
         current = {}
         for node in self.get_nodes():
@@ -132,11 +135,16 @@ class BaseStorage(object):
             if not itemid in current:
                 # new element which did not exist in storage before, that's easy
                 updated[itemid] = newdata[itemid]
-                continue
-
-            # merge the old and new element
-            update = ffstatus.dict_merge(current[itemid], newdata[itemid])
-            updated[itemid] = update
+            else:
+                # merge the old and new element
+                update = ffstatus.dict_merge(current[itemid], newdata[itemid])
+                updated[itemid] = update
+
+            for alias_id in updated[itemid]['aliases']:
+                if alias_id in aliased_nodes:
+                    aliased_nodes[alias_id].append(itemid)
+                else:
+                    aliased_nodes[alias_id] = [itemid]
 
         # sanitize each item's data
         for itemid in updated: