From ef5051726a3aa1f0192bd8d99c5c5b1ee9f067af Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Mon, 31 Dec 2007 11:21:10 +0000 Subject: Switch over to more Options usage and complete tests (everything appears to work now) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4142 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Client/Proxy.py | 64 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 19 deletions(-) (limited to 'src/lib/Client/Proxy.py') diff --git a/src/lib/Client/Proxy.py b/src/lib/Client/Proxy.py index 8e34a0fb5..d148748e2 100644 --- a/src/lib/Client/Proxy.py +++ b/src/lib/Client/Proxy.py @@ -6,7 +6,6 @@ from Bcfg2.tlslite.integration.XMLRPCTransport import XMLRPCTransport from Bcfg2.tlslite.integration.HTTPTLSConnection import HTTPTLSConnection from Bcfg2.tlslite.TLSConnection import TLSConnection import Bcfg2.tlslite.errors -from Bcfg2.Settings import settings #FIXME need to reimplement _binadaddress support for XMLRPCTransport @@ -47,39 +46,66 @@ class CobaltComponentError(Exception): class SafeProxy: '''Wrapper for proxy''' - + _retries = 4 _authinfo = () + _components = {} def __init__(self, component, args={}): self.component = component self.log = logging.getLogger(component) - password = settings.COMMUNICATION_PASSWORD - if args['password']: + if args.has_key('server'): + # processing from command line args + self._components[component] = args['server'] + else: + if args.has_key('setup'): + # processing from specified config file + _cfpath = args['setup'] + else: + _cfpath = '/etc/bcfg2.conf' + self._cfile = ConfigParser.ConfigParser() + self._cfile.read([_cfpath]) + try: + self._components = self._cfile._sections['components'] + except: + self.log.error("%s doesn't contain a valid components section" % (_cfpath)) + raise SystemExit, 1 + if args.has_key('password'): + # get passwd from cmdline password = args['password'] - - user = settings.COMMUNICATION_USER - if args['user']: + else: + try: + password = self._cfile.get('communication', 'password') + except: + self.log.error("%s doesn't contain a valid password" % (_cfpath)) + raise SystemExit, 1 + if args.has_key('user'): user = args['user'] + else: + try: + user = self._cfile.get('communication', 'user') + except: + user = 'root' self._authinfo = (user, password) - self.fingerprint = False - if args['fingerprint']: + if args.has_key('fingerprint'): self.fingerprint = args['fingerprint'] + else: + self.fingerprint = False - address = settings.COMPONENTS_BCFG2 - if args['server']: + _bindaddress = "" + try: + _bindaddress = self._cfile.get('communication', 'bindaddress') + except: + pass + + if args.has_key('server'): address = args['server'] - - # NOT USED - #_bindaddress = "" - #try: - # _bindaddress = self._cfile.get('communication', 'bindaddress') - #except: - # pass + else: + address = self.__get_location(component) + try: - # NOT USED # if _bindaddress != "": # self.log.info("Binding client to address %s" % _bindaddress) # self.proxy = xmlrpclib.ServerProxy(address, transport=Bcfg2SafeTransport()) -- cgit v1.2.3-1-g7c22