summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2008-01-09 23:01:05 +0000
committerNarayan Desai <desai@mcs.anl.gov>2008-01-09 23:01:05 +0000
commit1fbbe737b0cf0bdb83a59b4be30f105b11ee195d (patch)
tree9e9d0d4adbe8b25e523124da572eec7166fa693f /src/lib
parentf5adadec0bf8467c79a5b61d129e8e733f330906 (diff)
downloadbcfg2-1fbbe737b0cf0bdb83a59b4be30f105b11ee195d.tar.gz
bcfg2-1fbbe737b0cf0bdb83a59b4be30f105b11ee195d.tar.bz2
bcfg2-1fbbe737b0cf0bdb83a59b4be30f105b11ee195d.zip
Simplify proxy code. We don't need a multi-component infrastructure or local instantiation for bcfg2
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4229 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Proxy.py134
1 files changed, 6 insertions, 128 deletions
diff --git a/src/lib/Proxy.py b/src/lib/Proxy.py
index 5bcc78ad1..bd69c9f03 100644
--- a/src/lib/Proxy.py
+++ b/src/lib/Proxy.py
@@ -15,32 +15,7 @@ from Bcfg2.tlslite.integration.XMLRPCTransport import XMLRPCTransport
import xmlrpclib
from xmlrpclib import _Method
-__all__ = [
- "ComponentProxy", "ComponentLookupError", "RetryMethod",
- "register_component", "find_configured_servers",
-]
-
-local_components = dict()
-known_servers = dict()
-
-def register_component (component):
- local_components[component.name] = component
-
-
-class ComponentError (Exception):
-
- """Component error baseclass"""
-
-
-class ComponentLookupError (ComponentError):
-
- """Unable to locate an address for the given component."""
-
-
-class ComponentOperationError (ComponentError):
-
- """Component Failure during operation"""
-
+__all__ = ["ComponentProxy", "RetryMethod"]
class RetryMethod(_Method):
"""Method with error handling and retries built in"""
@@ -53,8 +28,10 @@ class RetryMethod(_Method):
except xmlrpclib.ProtocolError:
self.log.error("Server failure: Protocol Error")
raise xmlrpclib.Fault(20, "Server Failure")
- except socket.error:
- pass
+ except socket.error, (err, msg):
+ if retry == 3:
+ self.log.error("Server failure: %s" % msg)
+ raise xmlrpclib.Fault(20, msg)
except Bcfg2.tlslite.errors.TLSFingerprintError, err:
self.log.error("Server fingerprint did not match")
errmsg = err.message.split()
@@ -69,8 +46,7 @@ class RetryMethod(_Method):
# sorry jon
xmlrpclib._Method = RetryMethod
-def ComponentProxy (component_name, defer=False, user=None, password=None,
- fingerprint=None):
+def ComponentProxy (url, user=None, password=None, fingerprint=None):
"""Constructs proxies to components.
@@ -80,27 +56,6 @@ def ComponentProxy (component_name, defer=False, user=None, password=None,
Additional arguments are passed to the ServerProxy constructor.
"""
- if defer:
- return DeferredProxy(component_name)
-
- if component_name in local_components:
- return LocalProxy(local_components[component_name])
- elif component_name in known_servers:
- url = known_servers[component_name]
- elif component_name != "service-location":
- try:
- slp = ComponentProxy("service-location")
- except ComponentLookupError:
- raise ComponentLookupError(component_name)
- try:
- url = slp.locate(component_name)
- except:
- raise ComponentLookupError(component_name)
- if not url:
- raise ComponentLookupError(component_name)
- else:
- raise ComponentLookupError(component_name)
- # process url
if user and password:
method, path = urlparse.urlparse(url)[:2]
newurl = "%s://%s:%s@%s" % (method, user, password, path)
@@ -109,80 +64,3 @@ def ComponentProxy (component_name, defer=False, user=None, password=None,
return xmlrpclib.ServerProxy(newurl, allow_none=True,
transport=XMLRPCTransport(x509Fingerprint=fingerprint))
-class LocalProxy (object):
-
- """Proxy-like filter for inter-component communication.
-
- Used to access other components stored in local memory,
- without having to transport across tcp/http.
-
- Dispatches method calls through the component's _dispatch
- method to keep the interface between this and ServerProxy
- consistent.
- """
-
- def __init__ (self, component):
- self._component = component
-
- def __getattr__ (self, attribute):
- return LocalProxyMethod(self, attribute)
-
-
-class LocalProxyMethod (object):
-
- def __init__ (self, proxy, func_name):
- self._proxy = proxy
- self._func_name = func_name
-
- def __call__ (self, *args):
- return self._proxy._component._dispatch(self._func_name, args)
-
-
-class DeferredProxy (object):
-
- """Defering proxy object.
-
- Gets a new proxy when it can't connect to a component.
- """
-
- def __init__ (self, component_name):
- self._component_name = component_name
-
- def __getattr__ (self, attribute):
- return DeferredProxyMethod(self, attribute)
-
-
-class DeferredProxyMethod (object):
-
- def __init__ (self, proxy, func_name):
- self._proxy = proxy
- self._func_name = func_name
-
- def __call__ (self, *args):
- proxy = ComponentProxy(self._proxy._component_name, defer=False)
- func = getattr(proxy, self._func_name)
- return func(*args)
-
-
-def find_configured_servers (config_files=None):
- """Read associated config files into the module.
-
- Arguments:
- config_files -- a list of paths to config files.
- """
- if not config_files:
- config_files = ['/etc/bcfg2.conf']
- config = SafeConfigParser()
- config.read(config_files)
- try:
- components = config.options("components")
- except NoSectionError:
- return []
- known_servers.clear()
- known_servers.update(dict([
- (component, config.get("components", component))
- for component in components
- ]))
- return known_servers.copy()
-
-find_configured_servers()