summaryrefslogtreecommitdiffstats
path: root/src/sbin
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2004-10-11 20:16:38 +0000
committerNarayan Desai <desai@mcs.anl.gov>2004-10-11 20:16:38 +0000
commiteff26756c003f3c80a1b088671a40501adaeb824 (patch)
tree1ee959aaad913be176105e6131912c3592f362fd /src/sbin
parentd9bf1e8a313e6daac6cdc4f045aea20c052443f2 (diff)
downloadbcfg2-eff26756c003f3c80a1b088671a40501adaeb824.tar.gz
bcfg2-eff26756c003f3c80a1b088671a40501adaeb824.tar.bz2
bcfg2-eff26756c003f3c80a1b088671a40501adaeb824.zip
implement singlechild mode
(Logical change 1.84) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@402 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/sbin')
-rw-r--r--src/sbin/Bcfg2Server46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/sbin/Bcfg2Server b/src/sbin/Bcfg2Server
index 637dd00bb..ea7b1af6d 100644
--- a/src/sbin/Bcfg2Server
+++ b/src/sbin/Bcfg2Server
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# $Id: $
+from getopt import getopt, GetoptError
from socket import gethostbyaddr, herror
from string import split
from syslog import syslog, LOG_INFO, LOG_ERR
@@ -18,6 +19,29 @@ from sss.daemonize import daemonize
from sss.restriction import DataSet, Data
from sss.server import Server
+def dgetopt(arglist, opt, vopt):
+ r = {}
+ for o in opt.values() + vopt.values():
+ r[o] = False
+ gstr = join(opt.keys()) + join([x+':' for x in vopt.keys()])
+ try:
+ (o, a) = getopt(arglist, gstr)
+ except GetoptError, g:
+ print g
+ print "bcfg2 Usage:"
+ for (k,v) in opt.iteritems():
+ print " -%s %s"%(k,v)
+ for (k,v) in vopt.iteritems():
+ print " -%s <%s>"%(k,v)
+ exit(1)
+ for (gopt,garg) in o:
+ option = gopt[1:]
+ if opt.has_key(option):
+ r[opt[option]] = True
+ else:
+ r[vopt[option]] = garg
+ return r
+
class BcfgServer(Server):
__implementation__ = 'Bcfg2'
__component__ = 'bcfg2'
@@ -25,6 +49,7 @@ class BcfgServer(Server):
__validate__ = 0
def __setup__(self):
+ self.setup = self.kwargs['setup']
c = ConfigParser()
c.read([self.kwargs.get('configfile', '/etc/bcfg2.conf')])
repo = c.get('server','repository')
@@ -45,10 +70,13 @@ class BcfgServer(Server):
return 0
def BuildConfig(self, xml, (peer,port)):
- try:
- client = gethostbyaddr(peer)[0].split('.')[0]
- except herror:
- return Element("error", type='host resolution error')
+ if setup['client']:
+ client = setup['client']
+ else:
+ try:
+ client = gethostbyaddr(peer)[0].split('.')[0]
+ except herror:
+ return Element("error", type='host resolution error')
t = time()
config = Element("Configuration", version='2.0')
# get metadata for host
@@ -111,9 +139,13 @@ class BcfgServer(Server):
del t,v,tb
if __name__ == '__main__':
- if '--daemon' in argv:
- daemonize('/dev/null')
- server = BcfgServer()
+ options = {'v':'verbose','d':'debug'}
+ doptions = {'D':'daemon', 'C':'client'}
+ setup = dgetopt(argv[1:], options, doptions)
+ print setup
+ if setup['daemon']:
+ daemonize(setup['daemon'])
+ server = BcfgServer(setup=setup)
for i in range(10):
server.__progress__()
server.ServeForever()