merging with geni-api branch
[sfa.git] / sfa / server / interface.py
index 0275703..65b8d83 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 *
@@ -46,10 +46,9 @@ class Interfaces(dict):
     # defined by the class 
     default_dict = {}
 
-    # allowed types
-    types = ['sa', 'ma']
+    types = ['authority']
 
-    def __init__(self, api, conf_file, type):
+    def __init__(self, api, conf_file, type='authority'):
         if type not in self.types:
             raise SfaInfaildArgument('Invalid type %s: must be in %s' % (type, self.types))    
         dict.__init__(self, {})
@@ -62,12 +61,18 @@ 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
 
-        print "INTERFACES", self.interfaces
-        # get connections
-        self.update(self.get_connections(self.interfaces))
 
     def sync_interfaces(self):
         """
@@ -95,21 +100,24 @@ 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
             try:
                 # get gid from the registry
                 interface_info =  self.interfaces[new_hrn]
-                interface = self.get_connections(self.interfaces[new_hrn])[new_hrn]
+                interface = self[new_hrn]
                 trusted_gids = interface.get_trusted_certs()
-                # default message
-                message = "interface: %s\tunable to install trusted gid for %s" % \
-                           (self.api.interface, new_hrn) 
                 if trusted_gids:
                     # the gid we want shoudl be the first one in the list, 
                     # but lets make sure
                     for trusted_gid in trusted_gids:
+                        # default message
+                        message = "interface: %s\t" % (self.api.interface)
+                        message += "unable to install trusted gid for %s" % \
+                                   (new_hrn) 
                         gid = GID(string=trusted_gids[0])
                         peer_gids.append(gid) 
                         if gid.get_hrn() == new_hrn:
@@ -117,8 +125,8 @@ class Interfaces(dict):
                             gid.save_to_file(gid_filename, save_parents=True)
                             message = "interface: %s\tinstalled trusted gid for %s" % \
                                 (self.api.interface, new_hrn)
-                # log the message
-                self.api.logger.info(message)
+                        # log the message
+                        self.api.logger.info(message)
             except:
                 message = "interface: %s\tunable to install trusted gid for %s" % \
                             (self.api.interface, new_hrn) 
@@ -167,22 +175,21 @@ class Interfaces(dict):
                 record = SfaRecord(dict=record)
                 table.insert(record)
                         
-    def get_connections(self, interfaces):
+    def get_connections(self):
         """
         read connection details for the trusted peer registries from file return 
         a dictionary of connections keyed on interface hrn. 
         """
         connections = {}
         required_fields = self.default_fields.keys()
-        if not isinstance(interfaces, list):
-            interfaces = [interfaces]
-        for interface in interfaces:
+        for interface in self.interfaces.values():
             # 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'