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
-# 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
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:
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")
from sfa.util.sfalogging import logger
except:
import logging
- logger=logging.getLogger('sfaprotocol')
+ logger=logging.getLogger('sfaserverproxy')
##
# ServerException, ExceptionUnmarshaller
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
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
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.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):
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
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
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]:
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
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):
-#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
# 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
##
from sfa.storage.table import SfaTable
-import sfa.client.sfaprotocol as sfaprotocol
+from sfa.client.sfaserverproxy import SfaServerProxy
from sfa.generic import Generic
# 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()
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
if verbose:
print "Contacting registry at: %(url)s" % locals()
- server = sfaprotocol.server_proxy(url, keyfile, certfile)
+ server = SfaServerProxy(url, keyfile, certfile)
return server
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 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))
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
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: