make sure all trusted gids have a registry record, not just the new ones
[sfa.git] / sfa / server / interface.py
index 0503479..489d88b 100644 (file)
@@ -13,7 +13,7 @@ import traceback
 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
 import sfa.util.soapprotocol as soapprotocol
 
+
 # GeniLight client support is optional
 try:
     from egeni.geniLight_client import *
@@ -61,8 +61,17 @@ class Interfaces(dict):
         if not isinstance(interfaces, list):
             interfaces = [self.interfaces]
         self.interfaces = {}
+        required_fields = self.default_fields.keys()
         for interface in interfaces:
-            self.interfaces[interface['hrn']] = interface
+            valid = True
+            # skp any interface definition that has a null hrn, 
+            # address or port
+            for field in required_fields:
+                if field not in interface or not interface[field]:
+                    valid = False
+                    break
+            if valid:     
+                self.interfaces[interface['hrn']] = interface
 
 
     def sync_interfaces(self):
@@ -78,8 +87,8 @@ class Interfaces(dict):
         hrns_current = [gid.get_hrn() for gid in gids_current] 
         hrns_expected = self.interfaces.keys() 
         new_hrns = set(hrns_expected).difference(hrns_current)
-        gids = self.get_peer_gids(new_hrns)
-        # update the local db records for these registries
+        gids = self.get_peer_gids(new_hrns) + gids_current
+        # make sure there is a record for every gid
         self.update_db_records(self.type, gids)
         
     def get_peer_gids(self, new_hrns):
@@ -91,6 +100,8 @@ class Interfaces(dict):
             return peer_gids
         trusted_certs_dir = self.api.config.get_trustedroots_dir()
         for new_hrn in new_hrns:
+            if not new_hrn:
+                continue
             # the gid for this interface should already be installed  
             if new_hrn == self.api.config.SFA_INTERFACE_HRN:
                 continue
@@ -142,9 +153,9 @@ class Interfaces(dict):
 
         # get hrns that actually exist in the db
         table = SfaTable()
-        records = table.find({'type': type})
+        records = table.find({'type': type, 'pointer': -1})
         hrns_found = [record['hrn'] for record in records]
-       
+      
         # remove old records
         for record in records:
             if record['hrn'] not in hrns_expected:
@@ -175,9 +186,10 @@ class Interfaces(dict):
             # make sure the required fields are present and not null
             if not all([interface.get(key) for key in required_fields]):
                 continue
+            
             hrn, address, port = interface['hrn'], interface['addr'], interface['port']
             url = 'http://%(address)s:%(port)s' % locals()
+            
             # check which client we should use
             # sfa.util.xmlrpcprotocol is default
             client_type = 'xmlrpcprotocol'