merging with geni-api branch
[sfa.git] / sfa / util / api.py
index ca2557f..a7a07b6 100644 (file)
@@ -19,8 +19,6 @@ from sfa.trust.credential import *
 from sfa.trust.certificate import *
 from sfa.util.namespace import *
 from sfa.util.sfalogging import *
-from sfa.server.registry import Registries
-from sfa.server.aggregate import Aggregates
 
 # See "2.2 Characters" in the XML specification:
 #
@@ -99,14 +97,15 @@ def import_deep(name):
 
 class BaseAPI:
 
-    def __init__(self, config = "/etc/sfa/sfa_config.py", encoding = "utf-8", methods='sfa.methods',
-
-                 peer_cert = None, interface = None, key_file = None, cert_file = None):
+    cache = None
+    def __init__(self, config = "/etc/sfa/sfa_config.py", encoding = "utf-8", 
+                 methods='sfa.methods', peer_cert = None, interface = None, 
+                 key_file = None, cert_file = None, cache = cache):
 
         self.encoding = encoding
         
         # flat list of method names
-         
         self.methods_module = methods_module = __import__(methods, fromlist=[methods])
         self.methods = methods_module.all
 
@@ -123,15 +122,18 @@ class BaseAPI:
         self.key = Keypair(filename=self.key_file)
         self.cert_file = cert_file
         self.cert = Certificate(filename=self.cert_file)
+        self.cache = cache
         self.credential = None
         self.source = None 
         self.time_format = "%Y-%m-%d %H:%M:%S"
         self.logger=get_sfa_logger()
         
         # load registries
+        from sfa.server.registry import Registries
         self.registries = Registries(self) 
 
         # load aggregates
+        from sfa.server.aggregate import Aggregates
         self.aggregates = Aggregates(self)
 
 
@@ -140,6 +142,7 @@ class BaseAPI:
         Return a new instance of the specified method.
         """
         # Look up method
+        print self.methods
         if method not in self.methods:
             raise SfaInvalidAPIMethod, method
         
@@ -162,7 +165,8 @@ class BaseAPI:
         self.source = source
         return function(*args)
 
-    def handle(self, source, data):
+    
+    def handle(self, source, data, method_map):
         """
         Handle an XML-RPC or SOAP request from the specified source.
         """
@@ -170,7 +174,10 @@ class BaseAPI:
         try:
             interface = xmlrpclib
             (args, method) = xmlrpclib.loads(data)
+            if method_map.has_key(method):
+                method = method_map[method]
             methodresponse = True
+            
         except Exception, e:
             if SOAPpy is not None:
                 interface = SOAPpy