diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2005-10-13 18:55:00 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2005-10-13 18:55:00 +0000 |
commit | b9f5348a6ed0f1a9ffc11fc65f2ecb54dac7e600 (patch) | |
tree | 8a13b9e2593b498352c745b037971b417269f57f /src/lib/Client/XMLRPCComm.py | |
parent | 48a0eceadc2fdd6b6094e3c2638aa321241a1edc (diff) | |
download | bcfg2-b9f5348a6ed0f1a9ffc11fc65f2ecb54dac7e600.tar.gz bcfg2-b9f5348a6ed0f1a9ffc11fc65f2ecb54dac7e600.tar.bz2 bcfg2-b9f5348a6ed0f1a9ffc11fc65f2ecb54dac7e600.zip |
(Logical change 1.336)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1374 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Client/XMLRPCComm.py')
-rw-r--r-- | src/lib/Client/XMLRPCComm.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/lib/Client/XMLRPCComm.py b/src/lib/Client/XMLRPCComm.py index e69de29bb..83e99795b 100644 --- a/src/lib/Client/XMLRPCComm.py +++ b/src/lib/Client/XMLRPCComm.py @@ -0,0 +1,57 @@ +'''XMLRPC/SSL Communication Library (following the ssslib API)''' +__revision__ = '$Revision:$' + +from elementtree.ElementTree import XML, tostring +from ConfigParser import ConfigParser +from M2Crypto.m2xmlrpclib import ServerProxy, SSL_Transport +from xmlrpclib import Fault + +class CommunicationError(Exception): + '''Duplicate the sss.ssslib error API''' + pass + +class comm_lib(object): + '''This sets up the communication for XMLRPC Bcfg2''' + + def __init__(self): + self.cf = ConfigParser() + self.cf.read('/etc/bcfg2.conf') + location = self.cf.get("communication", "url") + self.proxy = ServerProxy(location, SSL_Transport()) + self.user = 'root' + self.password = self.cf.get("communication", "password") + + def ClientInit(self, component): + '''Return a single dummy handle''' + return "handle" + + def SendMessage(self, handle, msg): + '''Encode the XML msg as an XML-RPC request''' + data = XML(msg) + args = (self.user, self.password) + if data.tag == 'get-probes': + funcname = "GetProbes" + elif data.tag == 'probe-data': + funcname = "RecvProbeData" + args = (self.user, self.password, data.getchildren()) + elif data.tag == 'get-config': + funcname = 'GetConfig' + elif data.tag == 'upload-statistics': + funcname = "RecvStats" + args = (self.user, self.password, msg) + else: + print "unsupported function call" + raise CommunicationError, "foo" + func = getattr(self.proxy, funcname) + try: + self.response = apply(func, args) + except Fault, msg: + raise CommunicationError, msg + + def RecvMessage(self, handle): + '''Return cached response''' + return self.response + + def ClientClose(self, handle): + '''This is a noop for xmlrpc''' + pass |