take advantage of the new Table::dict method
[plcapi.git] / PLC / Peers.py
index e4598dc..94d3204 100644 (file)
@@ -110,7 +110,7 @@ class Peer (Row):
        # a host would have switched from one plc to the other
        local_foreign_nodes = ForeignNodes (self.api)
         # new to index it by hostname for searching later
-        local_foreign_nodes.hostname_index()
+        local_foreign_nodes_index = local_foreign_nodes.dict('hostname')
        
        ### mark entries for this peer outofdate
         old_count=0;
@@ -120,7 +120,6 @@ class Peer (Row):
                 old_count += 1
 
         ### these fields get copied through
-        ### xxx need to figure how to revert unix timestamp to db timestamp format
         remote_fields = ['boot_state','model','version','date_created','last_updated']
 
        ### scan the new entries, and mark them uptodate
@@ -128,7 +127,7 @@ class Peer (Row):
            hostname = node['hostname']
             foreign_id = node ['node_id']
             try:
-                foreign_node = local_foreign_nodes.hostname_locate(hostname)
+                foreign_node = local_foreign_nodes_index[hostname]
                 if foreign_node['peer_id'] != peer_id:
                     ### the node has changed its plc, needs to update peer_node
                     old_peer_id = foreign_node['peer_id']
@@ -153,7 +152,7 @@ class Peer (Row):
                 new_foreign_node.sync()
                 new_foreign_node.uptodate = True
                 self.manage_node(new_foreign_node,foreign_id,True)
-                local_foreign_nodes.hostname_add_by(new_foreign_node)
+                local_foreign_nodes_index[hostname]=new_foreign_node
 
        ### delete entries that are not uptodate
         for foreign_node in local_foreign_nodes: