From dffd7fa770d4cc6b80bda25c0296c7c029f37b18 Mon Sep 17 00:00:00 2001 From: Sapan Bhatia Date: Tue, 7 Jul 2009 20:49:08 +0000 Subject: [PATCH] Adding SOAP protocol support. --- sfa/util/geniclient.py | 62 ++++++++---------------------------------- 1 file changed, 12 insertions(+), 50 deletions(-) diff --git a/sfa/util/geniclient.py b/sfa/util/geniclient.py index 65ce60b9..54ded71e 100644 --- a/sfa/util/geniclient.py +++ b/sfa/util/geniclient.py @@ -9,56 +9,11 @@ ### $Id$ ### $URL$ -import xmlrpclib - from sfa.trust.gid import * from sfa.trust.credential import * from sfa.util.record import * from sfa.util.sfaticket import SfaTicket -## -# ServerException, ExceptionUnmarshaller -# -# Used to convert server exception strings back to an exception. -# from usenet, Raghuram Devarakonda - -class ServerException(Exception): - pass - -class ExceptionUnmarshaller(xmlrpclib.Unmarshaller): - def close(self): - try: - return xmlrpclib.Unmarshaller.close(self) - except xmlrpclib.Fault, e: - raise ServerException(e.faultString) - -## -# GeniTransport -# -# A transport for XMLRPC that works on top of HTTPS - -class GeniTransport(xmlrpclib.Transport): - key_file = None - cert_file = None - def make_connection(self, host): - # create a HTTPS connection object from a host descriptor - # host may be a string, or a (host, x509-dict) tuple - import httplib - host, extra_headers, x509 = self.get_host_info(host) - try: - HTTPS = httplib.HTTPS() - except AttributeError: - raise NotImplementedError( - "your version of httplib doesn't support HTTPS" - ) - else: - return httplib.HTTPS(host, None, key_file=self.key_file, cert_file=self.cert_file) #**(x509 or {})) - - def getparser(self): - unmarshaller = ExceptionUnmarshaller() - parser = xmlrpclib.ExpatParser(unmarshaller) - return parser, unmarshaller - ## # The GeniClient class provides stubs for executing Geni operations. A given # client object connects to one server. To connect to multiple servers, create @@ -77,15 +32,22 @@ class GeniClient: # @param key_file = private key file of client # @param cert_file = x.509 cert containing the client's public key. This # could be a GID certificate, or any x.509 cert. + # @param protocol The ORPC protocol to use. Can be "soap" or "xmlrpc" - def __init__(self, url, key_file, cert_file): + def __init__(self, url, key_file, cert_file, protocol="xmlrpc"): self.url = url self.key_file = key_file self.cert_file = cert_file - self.transport = GeniTransport() - self.transport.key_file = self.key_file - self.transport.cert_file = self.cert_file - self.server = xmlrpclib.ServerProxy(self.url, self.transport, allow_none=True) + + if (protocol=="xmlrpc"): + import xmlrpcprotocol + self.server = xmlrpcprotocol.get_server(self.url, self.key_file, self.cert_file) + elif (protocol=="soap"): + import soapprotocol + self.server = soapprotocol.get_server(self.url, self.key_file, self.cert_file) + else: + raise Exception("Attempted use of undefined protocol %s"%protocol) + # ------------------------------------------------------------------------- # Registry Interface -- 2.43.0