Changeset a2da110


Ignore:
Timestamp:
Nov 28, 2008 2:54:22 PM (15 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
Children:
1b57352
Parents:
0ea5050
Message:

Move service configuration into the config file and remove some extraneous options.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/fedd.py

    r0ea5050 ra2da110  
    33import sys
    44
     5from socket import error as socket_error
    56from BaseHTTPServer import BaseHTTPRequestHandler
    67
     
    268269                version="0.1")
    269270
    270         self.set_defaults(host="localhost", port=23235, transport="soap",
    271                 logfile=None, debug=0)
     271        self.set_defaults(logfile=None, debug=0)
    272272
    273273        self.add_option("-d", "--debug", action="count", dest="debug",
    274274                help="Set debug.  Repeat for more information")
    275275        self.add_option("-f", "--configfile", action="store",
     276                default="/usr/local/etc/fedd.conf",
    276277                dest="configfile", help="Configuration file (required)")
    277         self.add_option("-H", "--host", action="store", type="string",
    278                 dest="host", help="Hostname to listen on (default %default)")
    279278        self.add_option("-l", "--logfile", action="store", dest="logfile",
    280279                help="File to send log messages to")
    281         self.add_option("-p", "--port", action="store", type="int",
    282                 dest="port", help="Port to listen on (default %default)")
    283         self.add_option("-s", "--service", action="append", type="string",
    284                 dest="services",
    285                 help="Service description: host:port:transport")
    286         self.add_option("-x","--transport", action="store", type="choice",
    287                 choices=("xmlrpc", "soap"),
    288                 help="Transport for request (xmlrpc|soap) (Default: %default)")
    289280        self.add_option("--trace", action="store_const", dest="tracefile",
    290281                const=sys.stderr, help="Print SOAP exchange to stderr")
    291282
    292283servers_active = True       # Sub-servers run while this is True
    293 services = [ ]              # Service descriptions
    294284servers = [ ]               # fedd_server instances instantiated from services
    295285servers_lock = Lock()       # Lock to manipulate servers from sub-server threads
     
    385375            raise
    386376
    387 # Walk through the service descriptions and pack them into the services list.
    388 # That list has the form (transport (host, port)).
    389 if opts.services:
    390     for s in opts.services:
    391         try:
    392             h, p, t  = s.split(':')
    393         except ValueError:
    394             sys.exit("Invalid services specification: %s" % s)
    395 
    396         if not h: h = opts.host
    397         if not p: p = opts.port
    398         if not t: h = opts.transport
    399 
    400         p = int(p)
    401 
    402         services.append((t, (h, p)))
    403 else:
    404     services.append((opts.transport, (opts.host, opts.port)))
    405 
    406 # Create the servers and put them into a list
    407 for s in services:
    408     if s[0] == "soap":
    409         servers.append(fedd_server(s[1], fedd_soap_handler, ctx, impl))
    410     elif s[0] == "xmlrpc":
    411         servers.append(fedd_server(s[1], fedd_xmlrpc_handler, ctx, impl))
    412     else: flog.warning("Unknown transport: %s" % s[0])
     377services = config.get("globals", "services", "23235")
     378
     379for s in services.split(","):
     380    s = s.strip()
     381    colons = s.count(":")
     382    try:
     383        if colons == 0:
     384            p = int(s)
     385            h = ''
     386            t = 'soap'
     387        elif colons == 1:
     388            p, t  = s.split(":")
     389            p = int(p)
     390            h = ''
     391        elif colons == 2:
     392            h, p, t  = s.split(":")
     393            p = int(p)
     394        else:
     395            flog.error("Invalid service specification %s ignored." % s)
     396            continue
     397    except ValueError:
     398        flog.error("Error converting port to integer in %s: spec ignored" % s)
     399        continue
     400
     401    t = t.lower()
     402    try:
     403        if t == 'soap':
     404            servers.append(fedd_server((h, p), fedd_soap_handler, ctx, impl))
     405        elif t == 'xmlrpc':
     406            servers.append(fedd_server((h, p), fedd_xmlrpc_handler, ctx, impl))
     407        else:
     408            flog.error("Invalid transport specification (%s) in service %s" % \
     409                    (t, s))
     410            continue
     411    except socket_error, e:
     412        flog.error("Cannot create server for %s: %s" % (s, e[1]))
     413        continue
    413414
    414415#  Make sure that there are no malformed servers in the list
    415 services = [ s for s in services if s ]
     416servers = [ s for s in servers if s ]
    416417
    417418# Catch signals
Note: See TracChangeset for help on using the changeset viewer.