An enhancement to sfa for tracing and logging calls. The original caller credential...
authorAnil-Kumar Vengalil <Anil-Kumar.Vengalil@sophia.inria.fr>
Mon, 17 Aug 2009 17:49:28 +0000 (17:49 +0000)
committerAnil-Kumar Vengalil <Anil-Kumar.Vengalil@sophia.inria.fr>
Mon, 17 Aug 2009 17:49:28 +0000 (17:49 +0000)
sfa/plc/api.py
sfa/plc/nodes.py
sfa/plc/slices.py
sfa/util/geniclient.py
sfa/util/sfalogging.py [new file with mode: 0644]

index 4d4055b..46bf239 100644 (file)
@@ -19,6 +19,8 @@ from sfa.trust.rights import *
 from sfa.trust.credential import *
 from sfa.util.misc import *
 
+from sfa.util.sfalogging import *
+
 # See "2.2 Characters" in the XML specification:
 #
 # #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD]
@@ -119,7 +121,7 @@ class GeniAPI:
         self.plshell_version = self.getPLCShellVersion()
         self.hrn = self.config.SFA_INTERFACE_HRN
         self.time_format = "%Y-%m-%d %H:%M:%S"
-
+       self.logger=get_sfa_logger()
 
     def getPLCShell(self):
         self.plauth = {'Username': self.config.SFA_PLC_USER,
@@ -495,7 +497,6 @@ class GeniAPI:
         """
         Handle an XML-RPC or SOAP request from the specified source.
         """
-
         # Parse request into method name and arguments
         try:
             interface = xmlrpclib
@@ -535,3 +536,4 @@ class GeniAPI:
             data = buildSOAP(kw = {'%sResponse' % method: {'Result': result}}, encoding = self.encoding)
 
         return data
+
index dcf835d..7706763 100644 (file)
@@ -20,7 +20,7 @@ from sfa.server.aggregate import Aggregates
 
 class Nodes(SimpleStorage):
 
-    def __init__(self, api, ttl = 1):
+    def __init__(self, api, ttl = 1, caller_cred=None):
         self.api = api
         self.ttl = ttl
         self.threshold = None
@@ -31,6 +31,7 @@ class Nodes(SimpleStorage):
         SimpleStorage.__init__(self, self.nodes_file)
         self.policy = Policy(api)
         self.load()
+       self.caller_cred=caller_cred
 
 
     def refresh(self):
@@ -47,7 +48,6 @@ class Nodes(SimpleStorage):
             elif self.api.interface in ['slicemgr']:
                 self.refresh_nodes_smgr()
 
-        
     def refresh_nodes_aggregate(self):
         rspec = Rspec()
         rspec.parseString(self.get_rspec())
@@ -114,7 +114,7 @@ class Nodes(SimpleStorage):
         for aggregate in aggregates:
             try:
                 # get the rspec from the aggregate
-                agg_rspec = aggregates[aggregate].get_resources(credential, hrn)
+                agg_rspec = aggregates[aggregate].get_resources(credential, hrn, caller_cred=self.caller_cred)
                 # extract the netspec from each aggregates rspec
                 rspec.parseString(agg_rspec)
                 networks.extend([{'NetSpec': rspec.getDictsByTagName('NetSpec')}])
index a74687e..8931296 100644 (file)
@@ -19,7 +19,7 @@ from sfa.server.registry import Registries
 
 class Slices(SimpleStorage):
 
-    def __init__(self, api, ttl = .5):
+    def __init__(self, api, ttl = .5, caller_cred=None):
         self.api = api
         self.ttl = ttl
         self.threshold = None
@@ -30,6 +30,7 @@ class Slices(SimpleStorage):
         SimpleStorage.__init__(self, self.slices_file)
         self.policy = Policy(self.api)    
         self.load()
+       self.caller_cred=caller_cred
 
 
     def get_peer(self, hrn):
@@ -138,7 +139,7 @@ class Slices(SimpleStorage):
         aggregates = Aggregates(self.api)
         for aggregate in aggregates:
             try:
-                aggregates[aggregate].delete_slice(credential, hrn)
+                aggregates[aggregate].delete_slice(credential, hrn, caller_cred=self.caller_cred)
             except:
                 print >> log, "Error calling list nodes at aggregate %s" % aggregate
                 traceback.print_exc(log)
@@ -339,9 +340,9 @@ class Slices(SimpleStorage):
             try:
                 # send the whloe rspec to the local aggregate
                 if aggregate in [self.api.hrn]:
-                    aggregates[aggregate].create_slice(credential, hrn, rspec)
+                    aggregates[aggregate].create_slice(credential, hrn, rspec, caller_cred=self.caller_cred)
                 else:
-                    aggregates[aggregate].create_slice(credential, hrn, rspecs[aggregate])
+                    aggregates[aggregate].create_slice(credential, hrn, rspecs[aggregate], caller_cred=self.caller_cred)
             except:
                 print >> log, "Error creating slice %(hrn)s at aggregate %(aggregate)s" % locals()
                 traceback.print_exc()
index 9d959d3..06b3aa6 100644 (file)
@@ -130,8 +130,8 @@ class GeniClient:
     #
     # @return list of record objects
 
-    def list(self, cred, auth_hrn):
-        result_dict_list = self.server.list(cred.save_to_string(save_parents=True), auth_hrn)
+    def list(self, cred, auth_hrn, caller_cred=None):
+        result_dict_list = self.server.list(cred.save_to_string(save_parents=True), auth_hrn, caller_cred)
         result_rec_list = []
         for dict in result_dict_list:
              result_rec_list.append(GeniRecord(dict=dict))
@@ -214,21 +214,12 @@ class GeniClient:
     # @param cred a credential
     # @param hrn slice hrn
 
-    def get_resources(self, cred, hrn=None):
-        result = self.server.get_resources(cred.save_to_string(save_parents=True), hrn)
+    def get_resources(self, cred, hrn=None, caller_cred=None):
+        result = self.server.get_resources(cred.save_to_string(save_parents=True), hrn, caller_cred)
         return result
 
-    ## list info about all known aggregates
-
     def get_aggregates(self, cred, hrn=None):
-        result = self.server.get_aggregates(cred.save_to_string(save_parents=True), hrn)
-        return result
-
-
-    ## list info about all known registries
-
-    def get_registries(self, cred, hrn=None):
-        result = self.server.get_registries(cred.save_to_string(save_parents=True), hrn)
+        result = self.server.get_resources(cred.save_to_string(save_parents=True), hrn)
         return result
 
     ## get policy
@@ -244,8 +235,8 @@ class GeniClient:
     # @param cred a credential
     # @param rspec resource specification defining how to instantiate the slice
     
-    def create_slice(self, cred, hrn, rspec):
-        result = self.server.create_slice(cred.save_to_string(save_parents=True), hrn, rspec)
+    def create_slice(self, cred, hrn, rspec, caller_cred=None):
+        result = self.server.create_slice(cred.save_to_string(save_parents=True), hrn, rspec, caller_cred)
         return result
 
 
@@ -253,8 +244,8 @@ class GeniClient:
     #
     # @param cred a credential
     # @param hrn slice to delete
-    def delete_slice(self, cred, hrn):
-        result = self.server.delete_slice(cred.save_to_string(save_parents=True), hrn)
+    def delete_slice(self, cred, hrn, caller_cred=None):
+        result = self.server.delete_slice(cred.save_to_string(save_parents=True), hrn, caller_cred)
         return result    
 
     # ------------------------------------------------------------------------
@@ -297,8 +288,8 @@ class GeniClient:
     # @param cred a credential identifying the caller (callerGID) and the slice
     #     (objectGID)
 
-    def delete_slice(self, cred, hrn):
-        result = self.server.delete_slice(cred.save_to_string(save_parents=True), hrn)
+    def delete_slice(self, cred, hrn, caller_cred=None):
+        result = self.server.delete_slice(cred.save_to_string(save_parents=True), hrn, caller_cred)
         return result
 
     ##
diff --git a/sfa/util/sfalogging.py b/sfa/util/sfalogging.py
new file mode 100644 (file)
index 0000000..e2aaaee
--- /dev/null
@@ -0,0 +1,14 @@
+import logging
+
+#SFA access log initialization
+
+SFA_ACCESS_LOGFILE='/var/log/sfa_access.log'
+logger=logging.getLogger()
+logger.setLevel(logging.INFO)
+logfile=logging.FileHandler(SFA_ACCESS_LOGFILE)
+formatter = logging.Formatter("%(asctime)s - %(message)s")
+logfile.setFormatter(formatter)
+logger.addHandler(logfile)
+
+def get_sfa_logger():
+    return logger