sfaprotocol is renamed into sfaserverproxy, with class SfaServerProxy
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 7 Dec 2011 10:12:47 +0000 (11:12 +0100)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 7 Dec 2011 10:12:47 +0000 (11:12 +0100)
that behaves like an xmlrpclib.ServerProxy

sfa/client/sfaclientlib.py
sfa/client/sfascan.py
sfa/client/sfaserverproxy.py [moved from sfa/client/sfaprotocol.py with 79% similarity]
sfa/client/sfi.py
sfa/plc/plcomponentdriver.py
sfa/server/interface.py
sfa/server/sfa-clean-peer-records.py
sfa/server/sfa_component_setup.py
tests/testInterfaces.py

index ba8f502..2b5cb19 100644 (file)
@@ -7,35 +7,10 @@ import os,os.path
 
 import sfa.util.sfalogging
 
 
 import sfa.util.sfalogging
 
-# what we use on GID actually is inherited from Certificate
-#from sfa.trust.gid import GID
+from sfa.client.sfaserverproxy import SfaServerProxy
+
+# see optimizing dependencies below
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.trust.certificate import Keypair, Certificate
-# what we need in the Credential class essentially amounts to saving the incoming result
-# in a file as the output from the registry already is under xml format
-#from sfa.trust.credential import Credential
-
-import sfa.client.sfaprotocol as sfaprotocol
-
-class SfaServerProxy:
-
-    def __init__ (self, url, keyfile, certfile, verbose=False, timeout=None):
-        self.url=url
-        self.keyfile=keyfile
-        self.certfile=certfile
-        self.verbose=verbose
-        self.timeout=timeout
-        # an instance of xmlrpclib.ServerProxy
-        self.serverproxy=sfaprotocol.server_proxy \
-            (self.url, self.keyfile, self.certfile, self.timeout, self.verbose)
-
-    # this is python magic to return the code to run when 
-    # SfaServerProxy receives a method call
-    # so essentially we send the same method with identical arguments
-    # to the server_proxy object
-    def __getattr__(self, name):
-        def func(*args, **kwds):
-            return getattr(self.serverproxy, name)(*args, **kwds)
-        return func
 
 ########## 
 # a helper class to implement the bootstrapping of crypto. material
 
 ########## 
 # a helper class to implement the bootstrapping of crypto. material
index 9e2b09d..fdfa580 100644 (file)
@@ -14,7 +14,7 @@ from optparse import OptionParser
 
 from sfa.client.sfi import Sfi
 from sfa.util.sfalogging import logger, DEBUG
 
 from sfa.client.sfi import Sfi
 from sfa.util.sfalogging import logger, DEBUG
-import sfa.client.sfaprotocol as sfaprotocol
+from sfa.client.sfaserverproxy import SfaServerProxy
 
 def url_hostname_port (url):
     if url.find("://")<0:
 
 def url_hostname_port (url):
     if url.find("://")<0:
@@ -153,8 +153,8 @@ class Interface:
             url=self.url()
             logger.info('issuing GetVersion at %s'%url)
             # setting timeout here seems to get the call to fail - even though the response time is fast
             url=self.url()
             logger.info('issuing GetVersion at %s'%url)
             # setting timeout here seems to get the call to fail - even though the response time is fast
-            #server=sfaprotocol.server_proxy(url, key_file, cert_file, verbose=self.verbose, timeout=options.timeout)
-            server=sfaprotocol.server_proxy(url, key_file, cert_file, verbose=self.verbose)
+            #server=SfaServerProxy(url, key_file, cert_file, verbose=self.verbose, timeout=options.timeout)
+            server=SfaServerProxy(url, key_file, cert_file, verbose=self.verbose)
             self._version=server.GetVersion()
         except:
             logger.log_exc("failed to get version")
             self._version=server.GetVersion()
         except:
             logger.log_exc("failed to get version")
similarity index 79%
rename from sfa/client/sfaprotocol.py
rename to sfa/client/sfaserverproxy.py
index 3c8bb4f..18b7713 100644 (file)
@@ -7,7 +7,7 @@ try:
     from sfa.util.sfalogging import logger
 except:
     import logging
     from sfa.util.sfalogging import logger
 except:
     import logging
-    logger=logging.getLogger('sfaprotocol')
+    logger=logging.getLogger('sfaserverproxy')
 
 ##
 # ServerException, ExceptionUnmarshaller
 
 ##
 # ServerException, ExceptionUnmarshaller
@@ -91,7 +91,25 @@ class XMLRPCServerProxy(xmlrpclib.ServerProxy):
         logger.debug ("xml-rpc %s method:%s"%(self.url,attr))
         return xmlrpclib.ServerProxy.__getattr__(self, attr)
 
         logger.debug ("xml-rpc %s method:%s"%(self.url,attr))
         return xmlrpclib.ServerProxy.__getattr__(self, attr)
 
-def server_proxy(url, key_file, cert_file, timeout=None, verbose=False):
-    transport = XMLRPCTransport(key_file, cert_file, timeout)
-    return XMLRPCServerProxy(url, transport, allow_none=True, verbose=verbose)
+########## the object on which we can send methods that get sent over xmlrpc
+class SfaServerProxy:
+
+    def __init__ (self, url, keyfile, certfile, verbose=False, timeout=None):
+        self.url=url
+        self.keyfile=keyfile
+        self.certfile=certfile
+        self.verbose=verbose
+        self.timeout=timeout
+        # an instance of xmlrpclib.ServerProxy
+        transport = XMLRPCTransport(keyfile, certfile, timeout)
+        self.serverproxy = XMLRPCServerProxy(url, transport, allow_none=True, verbose=verbose)
+
+    # this is python magic to return the code to run when 
+    # SfaServerProxy receives a method call
+    # so essentially we send the same method with identical arguments
+    # to the server_proxy object
+    def __getattr__(self, name):
+        def func(*args, **kwds):
+            return getattr(self.serverproxy, name)(*args, **kwds)
+        return func
 
 
index ed45b07..c9bde73 100644 (file)
@@ -31,7 +31,7 @@ from sfa.rspecs.rspec_converter import RSpecConverter
 from sfa.rspecs.version_manager import VersionManager
 from sfa.client.return_value import ReturnValue
 
 from sfa.rspecs.version_manager import VersionManager
 from sfa.client.return_value import ReturnValue
 
-import sfa.client.sfaprotocol as sfaprotocol
+from sfa.client.sfaserverproxy import SfaServerProxy, ServerException
 from sfa.client.client_helper import pg_users_arg, sfa_users_arg
 
 AGGREGATE_PORT=12346
 from sfa.client.client_helper import pg_users_arg, sfa_users_arg
 
 AGGREGATE_PORT=12346
@@ -479,9 +479,9 @@ class Sfi:
        self.cert_file = cert_file
        self.cert = GID(filename=cert_file)
        self.logger.info("Contacting Registry at: %s"%self.reg_url)
        self.cert_file = cert_file
        self.cert = GID(filename=cert_file)
        self.logger.info("Contacting Registry at: %s"%self.reg_url)
-       self.registry = sfaprotocol.server_proxy(self.reg_url, key_file, cert_file, timeout=self.options.timeout, verbose=self.options.debug)  
+       self.registry = SfaServerProxy(self.reg_url, key_file, cert_file, timeout=self.options.timeout, verbose=self.options.debug)  
        self.logger.info("Contacting Slice Manager at: %s"%self.sm_url)
        self.logger.info("Contacting Slice Manager at: %s"%self.sm_url)
-       self.slicemgr = sfaprotocol.server_proxy(self.sm_url, key_file, cert_file, timeout=self.options.timeout, verbose=self.options.debug)
+       self.slicemgr = SfaServerProxy(self.sm_url, key_file, cert_file, timeout=self.options.timeout, verbose=self.options.debug)
        return
 
     def get_cached_server_version(self, server):
        return
 
     def get_cached_server_version(self, server):
@@ -574,7 +574,7 @@ class Sfi:
             self.logger.info("Getting Registry issued cert")
             self.read_config()
             # *hack.  need to set registry before _get_gid() is called 
             self.logger.info("Getting Registry issued cert")
             self.read_config()
             # *hack.  need to set registry before _get_gid() is called 
-            self.registry = sfaprotocol.server_proxy(self.reg_url, key_file, cert_file, 
+            self.registry = SfaServerProxy(self.reg_url, key_file, cert_file, 
                                                      timeout=self.options.timeout, verbose=self.options.debug)
             gid = self._get_gid(type='user')
             self.registry = None 
                                                      timeout=self.options.timeout, verbose=self.options.debug)
             gid = self._get_gid(type='user')
             self.registry = None 
@@ -756,7 +756,7 @@ class Sfi:
         host_parts = host.split('/')
         host_parts[0] = host_parts[0] + ":" + str(port)
         url =  "http://%s" %  "/".join(host_parts)    
         host_parts = host.split('/')
         host_parts[0] = host_parts[0] + ":" + str(port)
         url =  "http://%s" %  "/".join(host_parts)    
-        return sfaprotocol.server_proxy(url, keyfile, certfile, timeout=self.options.timeout, 
+        return SfaServerProxy(url, keyfile, certfile, timeout=self.options.timeout, 
                                         verbose=self.options.debug)
 
     # xxx opts could be retrieved in self.options
                                         verbose=self.options.debug)
 
     # xxx opts could be retrieved in self.options
@@ -881,7 +881,7 @@ or version information about sfi itself
         elif record['type'] in ["slice"]:
             try:
                 cred = self.get_slice_cred(record.get_name()).save_to_string(save_parents=True)
         elif record['type'] in ["slice"]:
             try:
                 cred = self.get_slice_cred(record.get_name()).save_to_string(save_parents=True)
-            except sfaprotocol.ServerException, e:
+            except ServerException, e:
                # XXX smbaker -- once we have better error return codes, update this
                # to do something better than a string compare
                if "Permission error" in e.args[0]:
                # XXX smbaker -- once we have better error return codes, update this
                # to do something better than a string compare
                if "Permission error" in e.args[0]:
index 5e74612..991cdde 100644 (file)
@@ -1,7 +1,7 @@
 import os
 import tempfile
 
 import os
 import tempfile
 
-import sfa.client.sfaprotocol as sfaprotocol
+from sfa.client.sfaserverproxy import SfaServerProxy
 from sfa.plc.nodemanager import NodeManager
 
 from sfa.trust.credential import Credential
 from sfa.plc.nodemanager import NodeManager
 
 from sfa.trust.credential import Credential
@@ -33,7 +33,7 @@ class PlComponentDriver:
         addr, port = self.config.SFA_REGISTRY_HOST, self.config.SFA_REGISTRY_PORT
         url = "http://%(addr)s:%(port)s" % locals()
         ### xxx this would require access to the api...
         addr, port = self.config.SFA_REGISTRY_HOST, self.config.SFA_REGISTRY_PORT
         url = "http://%(addr)s:%(port)s" % locals()
         ### xxx this would require access to the api...
-        server = sfaprotocol.server_proxy(url, self.key_file, self.cert_file)
+        server = SfaServerProxy(url, self.key_file, self.cert_file)
         return server
 
     def get_node_key(self):
         return server
 
     def get_node_key(self):
index 920857c..2f46146 100644 (file)
@@ -1,5 +1,4 @@
-#from sfa.util.faults import *
-import sfa.client.sfaprotocol as sfaprotocol
+from sfa.client.sfaserverproxy import SfaServerProxy
 from sfa.util.xml import XML
 
 # GeniLight client support is optional
 from sfa.util.xml import XML
 
 # GeniLight client support is optional
@@ -31,7 +30,7 @@ class Interface:
             # xxx url and self.api are undefined
             server = GeniClientLight(url, self.api.key_file, self.api.cert_file)
         else:
             # xxx url and self.api are undefined
             server = GeniClientLight(url, self.api.key_file, self.api.cert_file)
         else:
-            server = sfaprotocol.server_proxy(self.get_url(), key_file, cert_file, timeout) 
+            server = SfaServerProxy(self.get_url(), key_file, cert_file, timeout) 
  
         return server       
 ##
  
         return server       
 ##
index 5024a10..bcb917b 100644 (file)
@@ -14,7 +14,7 @@ from sfa.server.registry import Registries
 
 from sfa.storage.table import SfaTable
 
 
 from sfa.storage.table import SfaTable
 
-import sfa.client.sfaprotocol as sfaprotocol 
+from sfa.client.sfaserverproxy import SfaServerProxy 
 
 from sfa.generic import Generic
 
 
 from sfa.generic import Generic
 
@@ -35,7 +35,7 @@ def main():
     # and a valid credential
     authority = config.SFA_INTERFACE_HRN
     url = 'http://%s:%s/' %(config.SFA_REGISTRY_HOST, config.SFA_REGISTRY_PORT)
     # and a valid credential
     authority = config.SFA_INTERFACE_HRN
     url = 'http://%s:%s/' %(config.SFA_REGISTRY_HOST, config.SFA_REGISTRY_PORT)
-    registry = sfaprotocol.server_proxy(url, key_file, cert_file)
+    registry = SfaServerProxy(url, key_file, cert_file)
     sfa_api = Generic.the_flavour()
     credential = sfa_api.getCredential()
 
     sfa_api = Generic.the_flavour()
     credential = sfa_api.getCredential()
 
index 05a9525..589a572 100755 (executable)
@@ -6,7 +6,7 @@ from optparse import OptionParser
 
 from sfa.util.faults import ConnectionKeyGIDMismatch
 from sfa.util.config import Config
 
 from sfa.util.faults import ConnectionKeyGIDMismatch
 from sfa.util.config import Config
-import sfa.client.sfaprotocol as sfaprotocol
+from sfa.client.sfaserverproxy import SfaServerProxy
 from sfa.util.plxrn import hrn_to_pl_slicename, slicename_to_hrn
 
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.util.plxrn import hrn_to_pl_slicename, slicename_to_hrn
 
 from sfa.trust.certificate import Keypair, Certificate
@@ -48,7 +48,7 @@ def server_proxy(url=None, port=None, keyfile=None, certfile=None,verbose=False)
     if verbose:
         print "Contacting registry at: %(url)s" % locals()
 
     if verbose:
         print "Contacting registry at: %(url)s" % locals()
 
-    server = sfaprotocol.server_proxy(url, keyfile, certfile)
+    server = SfaServerProxy(url, keyfile, certfile)
     return server    
     
 
     return server    
     
 
index f12cae1..a51799b 100755 (executable)
@@ -4,7 +4,7 @@ import os
 import random
 import string
 import unittest
 import random
 import string
 import unittest
-import sfa.util.sfaprotocol as sfaprotocol
+
 from unittest import TestCase
 from optparse import OptionParser
 from sfa.util.xrn import get_authority
 from unittest import TestCase
 from optparse import OptionParser
 from sfa.util.xrn import get_authority
@@ -13,6 +13,7 @@ from sfa.trust.certificate import *
 from sfa.trust.credential import *
 from sfa.trust.sfaticket import SfaTicket
 from sfa.client import sfi
 from sfa.trust.credential import *
 from sfa.trust.sfaticket import SfaTicket
 from sfa.client import sfi
+from sfa.client.sfaserverproxy import SfaServerProxy, ServerException
 
 def random_string(size):
     return "".join(random.sample(string.letters, size))
 
 def random_string(size):
     return "".join(random.sample(string.letters, size))
@@ -43,10 +44,10 @@ class Client:
         self.cert.save_to_file(cert_file)        
         SFI_AGGREGATE = config.SFI_SM.replace('12347', '12346')
         SFI_CM = 'http://' + options.cm_host + ':12346'
         self.cert.save_to_file(cert_file)        
         SFI_AGGREGATE = config.SFI_SM.replace('12347', '12346')
         SFI_CM = 'http://' + options.cm_host + ':12346'
-        self.registry = sfaprotocol.server_proxy(config.SFI_REGISTRY, key_file, cert_file)
-        self.aggregate = sfaprotocol.server_proxy(SFI_AGGREGATE, key_file, cert_file)
-        self.sm = sfaprotocol.server_proxy(config.SFI_SM, key_file, cert_file)
-        self.cm = sfaprotocol.server_proxy(SFI_CM, key_file, cert_file)
+        self.registry = SfaServerProxy(config.SFI_REGISTRY, key_file, cert_file)
+        self.aggregate = SfaServerProxy(SFI_AGGREGATE, key_file, cert_file)
+        self.sm = SfaServerProxy(config.SFI_SM, key_file, cert_file)
+        self.cm = SfaServerProxy(SFI_CM, key_file, cert_file)
         self.hrn = config.SFI_USER
         # XX defaulting to user, but this should be configurable so we can
         # test from components persepctive
         self.hrn = config.SFI_USER
         # XX defaulting to user, but this should be configurable so we can
         # test from components persepctive
@@ -170,7 +171,7 @@ class RegistryTest(BasicTestCase):
         server_exception = False 
         try:
             callable(self.credential)
         server_exception = False 
         try:
             callable(self.credential)
-        except sfaprotocol.ServerException:
+        except ServerException:
             server_exception = True
         finally:
             if self.type in ['user'] and not server_exception:
             server_exception = True
         finally:
             if self.type in ['user'] and not server_exception: