summaryrefslogtreecommitdiffstats
path: root/src/lib/Component.py
diff options
context:
space:
mode:
authorRobert Gogolok <gogo@cs.uni-sb.de>2007-12-30 19:26:51 +0000
committerRobert Gogolok <gogo@cs.uni-sb.de>2007-12-30 19:26:51 +0000
commite8c9ba57d10d174c79ac1aae9b53661ee8464d0f (patch)
tree65cb5f7b0c699e6c97eb365ec83c76155a023f7e /src/lib/Component.py
parent73ba22f7e519694dbf7010810de69b3b845f634f (diff)
downloadbcfg2-e8c9ba57d10d174c79ac1aae9b53661ee8464d0f.tar.gz
bcfg2-e8c9ba57d10d174c79ac1aae9b53661ee8464d0f.tar.bz2
bcfg2-e8c9ba57d10d174c79ac1aae9b53661ee8464d0f.zip
Settings class to remove redundant code for parsing config file.
If a module wants to access bcfg2 settings: from Bcfg2.Settings import settings git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4131 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Component.py')
-rw-r--r--src/lib/Component.py39
1 files changed, 14 insertions, 25 deletions
diff --git a/src/lib/Component.py b/src/lib/Component.py
index a6f3e9aa2..442ea8112 100644
--- a/src/lib/Component.py
+++ b/src/lib/Component.py
@@ -3,6 +3,7 @@ __revision__ = '$Revision$'
import atexit, logging, select, signal, socket, sys, time, urlparse, xmlrpclib, cPickle, ConfigParser, os
from base64 import decodestring
+
import BaseHTTPServer, SimpleXMLRPCServer
import Bcfg2.tlslite.errors
import Bcfg2.tlslite.api
@@ -10,6 +11,8 @@ import Bcfg2.tlslite.api
import Bcfg2.Client.Proxy as Proxy
from Bcfg2.tlslite.TLSConnection import TLSConnection
+from Bcfg2.Settings import settings
+
log = logging.getLogger('Component')
class ComponentInitError(Exception):
@@ -144,34 +147,20 @@ class Component(TLSServer,
signal.signal(signal.SIGINT, self.start_shutdown)
signal.signal(signal.SIGTERM, self.start_shutdown)
self.logger = logging.getLogger('Component')
- self.cfile = ConfigParser.ConfigParser()
self.children = []
- if setup['configfile']:
- cfilename = setup['configfile']
- else:
- cfilename = '/etc/bcfg2.conf'
- self.cfile.read([cfilename])
- if not self.cfile.has_section('communication'):
- print "Configfile missing communication section"
- raise SystemExit, 1
- self.static = False
- if not self.cfile.has_section('components'):
- print "Configfile missing components section"
- raise SystemExit, 1
- if self.cfile._sections['components'].has_key(self.__name__):
- self.static = True
- location = urlparse.urlparse(self.cfile.get('components', self.__name__))[1].split(':')
+ self.static = True
+
+ location = settings.COMPONENTS_BCFG2
+ if settings.COMPONENTS_BCFG2_STATIC:
+ location = urlparse.urlparse(settings.COMPONENTS_BCFG2)[1].split(':')
location = (location[0], int(location[1]))
- else:
- location = (socket.gethostname(), 0)
- try:
- keyfile = self.cfile.get('communication', 'key')
- #keyfile = '/tmp/keys/server.pkey'
- except ConfigParser.NoOptionError:
- print "No key specified in cobalt.conf"
+
+ if not settings.COMMUNICATION_KEY:
+ print "No key specified in '%s'" % settings.CONFIG_FILE
raise SystemExit, 1
+ keyfile = settings.COMMUNICATION_KEY
- self.password = self.cfile.get('communication', 'password')
+ self.password = settings.COMMUNICATION_PASSWORD
try:
TLSServer.__init__(self, location, keyfile, CobaltXMLRPCRequestHandler)
@@ -182,7 +171,7 @@ class Component(TLSServer,
self.logger.error("Failed to parse key" % (keyfile))
raise ComponentInitError
except:
- self.logger.error("Failed to load ssl key %s" % (keyfile), exc_info=1)
+ self.logger.error("Failed to load ssl key '%s'" % (keyfile), exc_info=1)
raise ComponentInitError
try:
SimpleXMLRPCServer.SimpleXMLRPCDispatcher.__init__(self)