summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2006-04-20 02:19:34 +0000
committerNarayan Desai <desai@mcs.anl.gov>2006-04-20 02:19:34 +0000
commit341a39a0fff9f7990022e819cdc704e5ed9fb121 (patch)
tree8dd512c8c0abcb0980fe1b67867fd8abfb80fc3d /src/lib
parent5a35caddd2815d3efcbf09bf10220422b579dc37 (diff)
downloadbcfg2-341a39a0fff9f7990022e819cdc704e5ed9fb121.tar.gz
bcfg2-341a39a0fff9f7990022e819cdc704e5ed9fb121.tar.bz2
bcfg2-341a39a0fff9f7990022e819cdc704e5ed9fb121.zip
Proxy.py downsync from the cobalt repo
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1846 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Client/Proxy.py65
1 files changed, 54 insertions, 11 deletions
diff --git a/src/lib/Client/Proxy.py b/src/lib/Client/Proxy.py
index a809e70f8..670976149 100644
--- a/src/lib/Client/Proxy.py
+++ b/src/lib/Client/Proxy.py
@@ -10,9 +10,18 @@ class CobaltComponentError(Exception):
class SafeProxy:
'''Wrapper for proxy'''
_cfile = ConfigParser.ConfigParser()
- _cfile.read(['/etc/bcfg2.conf'])
- _components = _cfile._sections['components']
- _authinfo = ('root', _cfile.get('communication', 'password'))
+ _cfpath = '/etc/bcfg2.conf'
+ _cfile.read([_cfpath])
+ try:
+ _components = _cfile._sections['components']
+ except KeyError:
+ print "cobalt.conf doesn't contain a valid components section"
+ raise SystemExit, 1
+ try:
+ _authinfo = ('root', _cfile.get('communication', 'password'))
+ except KeyError:
+ print "cobalt.conf doesn't contain a valid communication setup"
+ raise SystemExit, 1
_retries = 4
def __init__(self, component, url=None):
@@ -30,25 +39,25 @@ class SafeProxy:
except:
self.log.error("Failed to initialize xml-rpc", exc_info=1)
- def run_method(self, method_name, method_args):
+ def run_method(self, methodName, methodArgs):
''' Perform an XMLRPC invocation against the server'''
- method = getattr(self.proxy, method_name)
+ method = getattr(self.proxy, methodName)
for irs in range(self._retries):
try:
- ret = apply(method, self._authinfo + method_args)
+ ret = apply(method, self._authinfo + methodArgs)
if irs > 0:
self.log.warning("Required %d attempts to contact %s for operation %s" %
- (irs, self.component, method_name))
- self.log.debug("%s completed successfully" % (method_name))
+ (irs, self.component, methodName))
+ self.log.debug("%s completed successfully" % (methodName))
return ret
except xmlrpclib.ProtocolError:
self.log.error("Server failure: Protocol Error")
raise xmlrpclib.Fault(20, "Server Failure")
except xmlrpclib.Fault:
- self.log.debug("Operation %s completed with fault" % (method_name))
+ self.log.debug("Operation %s completed with fault" % (methodName))
raise
except socket.error, serr:
- self.log.debug("Attempting %s (%d of %d) failed because %s" % (method_name, (irs+1),
+ self.log.debug("Attempting %s (%d of %d) failed because %s" % (methodName, (irs+1),
self._retries, serr))
time.sleep(0.5)
except:
@@ -70,6 +79,10 @@ class SafeProxy:
curl = sdata[0]['url']
self._components[name] = curl
return curl
+
+ def dummy(self):
+ '''dummy method for pylint'''
+ return True
class ComponentProxy(SafeProxy):
'''Component Proxy instantiates a SafeProxy to a component and registers local functions
@@ -88,12 +101,42 @@ class service_location(ComponentProxy):
name = 'service-location'
methods = ['AssertService', 'LookupService', 'DeassertService']
+class allocation_manager(ComponentProxy):
+ '''allocation manager specific component proxy'''
+ name = 'allocation-manager'
+ methods = ['GetProject']
+
+class file_stager(ComponentProxy):
+ '''File staging component'''
+ name = 'file-stager'
+ methods = ['StageInit', 'FinalizeStage']
+
class process_manager(ComponentProxy):
'''process manager specific component proxy'''
name = 'process-manager'
- methods = ['CreateProcessGroup', 'GetProcessGroup']
+ methods = ['CreateProcessGroup', 'GetProcessGroup', 'KillProcessGroup', 'WaitProcessGroup']
+
+class queue_manager(ComponentProxy):
+ '''queue manager proxy'''
+ name = 'queue-manager'
+ methods = ['AddJob', 'GetJobs', 'DelJobs', 'RunJobs', 'SetJobs', 'SetJobID']
+
+class scheduler(ComponentProxy):
+ '''scheduler proxy'''
+ name = 'scheduler'
+ methods = ['AddReservation', 'DelReservation', 'GetPartition', 'AddPartition', 'DelPartition', 'Set']
class bcfg2(ComponentProxy):
'''bcfg2 client code'''
name = 'bcfg2'
methods = ['AssertProfile', 'GetConfig', 'GetProbes', 'RecvProbeData', 'RecvStats']
+
+class CommDict(dict):
+ '''CommDict is a dictionary that automatically instantiates a component proxy upon access'''
+ commnames = {'pm':process_manager, 'fs':file_stager, 'am':allocation_manager,
+ 'sched':scheduler, 'qm':queue_manager}
+
+ def __getitem__(self, name):
+ if not self.has_key(name):
+ self.__setitem__(name, self.commnames[name]())
+ return dict.__getitem__(self, name)