diff options
| author | Seth Vidal <skvidal@fedoraproject.org> | 2007-09-20 21:28:51 -0400 |
|---|---|---|
| committer | Seth Vidal <skvidal@fedoraproject.org> | 2007-09-20 21:28:51 -0400 |
| commit | 8d168259f1cb0af25a7ee342bd1c32cd5bfdd424 (patch) | |
| tree | 9c1d80b6da18a902b03ba7b21ec6bd0a60aabbfa /server/server.py | |
| parent | a83c4bcc40aae7c8b8058d831667ee1e07a969dc (diff) | |
| parent | 98010f591948fb4bf297c1c0c32def42f766edca (diff) | |
Merge branch 'master' of ssh://git.fedoraproject.org/git/hosted/func
* 'master' of ssh://git.fedoraproject.org/git/hosted/func: (27 commits)
just a friendly reminder
we are not vf_server, change I!*N domain
Add virt module.
Add test code for virt.
add a very simple, very dumb commandline client:
Remove messages.pot from po dir, since its automatically generated
Get rid of extra / in module loading error
pychecker cleanups
Add po dir to git
Prevent XMLRPC server from printing to console.
Catch FuncException when the config file is missing and exit gracefully
Implement a quickie service control module
Removing VF items + misc cleanup
Clean up some speclint warnings
Baseobj bites the dust.
remove all the --debug "try to run from the src tree" crap
debug spew cleanup to protect the unwashed masses from foo poisoning
fix up config_data to use ConfigParser correctly
attempt to let us run with --debug flag to run from src checkout
attempts at letting us run from a installed, or local modules
...
Diffstat (limited to 'server/server.py')
| -rwxr-xr-x | server/server.py | 181 |
1 files changed, 78 insertions, 103 deletions
diff --git a/server/server.py b/server/server.py index d297b06..aa8bdef 100755 --- a/server/server.py +++ b/server/server.py @@ -1,11 +1,10 @@ #!/usr/bin/python + """ -Virt-factory backend code. +func -Copyright 2006, Red Hat, Inc -Michael DeHaan <mdehaan@redhat.com> -Scott Seago <sseago@redhat.com> -Adrian Likins <alikins@redhat.com> +Copyright 2007, Red Hat, Inc +see AUTHORS This software may be freely redistributed under the terms of the GNU general public license. @@ -15,198 +14,174 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. """ +# standard modules import SimpleXMLRPCServer -import os -import subprocess +import string import socket +import sys +import traceback -SERVE_ON = (None,None) - -# FIXME: logrotate - -from codes import * +from rhpl.translate import _, N_, textdomain, utf8 +I18N_DOMAIN = "func" +# our modules +import codes import config_data import logger import module_loader import utils +# ====================================================================================== -MODULE_PATH="modules/" -modules = module_loader.load_modules(MODULE_PATH) -print "modules", modules - +class XmlRpcInterface(object): -#from busrpc.services import RPCDispatcher -#from busrpc.config import DeploymentConfig + def __init__(self, modules={}): -from rhpl.translate import _, N_, textdomain, utf8 -I18N_DOMAIN = "vf_server" - - -class Singleton(object): - def __new__(type, *args, **kwargs): - if not '_the_instance' in type.__dict__: - type._the_instance = object.__new__(type, *args, **kwargs) - type._the_instance.init(*args, **kwargs) - return type._the_instance - -class XmlRpcInterface(Singleton): - - def init(self): """ - Constructor sets up SQLAlchemy (database ORM) and logging. + Constructor. """ + config_obj = config_data.Config() self.config = config_obj.get() - - self.tables = {} - self.tokens = [] - + self.modules = modules self.logger = logger.Logger().logger - self.__setup_handlers() def __setup_handlers(self): + """ Add RPC functions from each class to the global list so they can be called. - FIXME: eventually calling most functions should go from here through getattr. """ + self.handlers = {} - print "ffffffffffff", modules.keys() - for x in modules.keys(): - print "x", x + for x in self.modules.keys(): try: - modules[x].register_rpc(self.handlers) + self.modules[x].register_rpc(self.handlers) self.logger.debug("adding %s" % x) except AttributeError, e: - self.logger.warning("module %s could not be loaded, it did not have a register_rpc method" % modules[x]) + self.logger.warning("module %s not loaded, missing register_rpc method" % self.modules[x]) - # FIXME: find some more elegant way to surface the handlers? - # FIXME: aforementioned login/session token requirement - def get_dispatch_method(self, method): + if method in self.handlers: - return FuncApiMethod(self.logger, method, - self.handlers[method]) + return FuncApiMethod(self.logger, method, self.handlers[method]) else: self.logger.info("Unhandled method call for method: %s " % method) - raise InvalidMethodException + raise codes.InvalidMethodException def _dispatch(self, method, params): + """ the SimpleXMLRPCServer class will call _dispatch if it doesn't find a handler method """ + return self.get_dispatch_method(method)(*params) -class BusRpcWrapper: - - def __init__(self, config): - self.rpc_interface = None +# ====================================================================================== - def __getattr__(self, name): - if self.rpc_interface == None: - self.rpc_interface = XmlRpcInterface() - return self.rpc_interface.get_dispatch_method(name) +class FuncApiMethod: - def __repr__(self): - return ("<BusRpcWrapper>") + """ + Used to hold a reference to all of the registered functions. + """ -class FuncApiMethod: def __init__(self, logger, name, method): + self.logger = logger self.__method = method self.__name = name def __log_exc(self): + """ Log an exception. """ + (t, v, tb) = sys.exc_info() self.logger.info("Exception occured: %s" % t ) self.logger.info("Exception value: %s" % v) self.logger.info("Exception Info:\n%s" % string.join(traceback.format_list(traceback.extract_tb(tb)))) def __call__(self, *args): + self.logger.debug("(X) -------------------------------------------") + try: rc = self.__method(*args) - except FuncException, e: + except codes.FuncException, e: self.__log_exc() rc = e except: - self.logger.debug("Not a virt-factory specific exception") + self.logger.debug("Not a Func-specific exception") self.__log_exc() raise - rc = rc.to_datastruct() self.logger.debug("Return code for %s: %s" % (self.__name, rc)) + return rc +# ====================================================================================== def serve(websvc): + """ Code for starting the XMLRPC service. FIXME: make this HTTPS (see RRS code) and make accompanying Rails changes.. """ + server =FuncXMLRPCServer(('', 51234)) + server.logRequests = 0 # don't print stuff to console server.register_instance(websvc) server.serve_forever() -def serve_qpid(config_path, register_with_bridge=False, is_bridge_server=False): - """ - Code for starting the QPID RPC service. - """ - config = DeploymentConfig(config_path) - dispatcher = RPCDispatcher(config, register_with_bridge, is_bridge_server=is_bridge_server) - - try: - dispatcher.start() - except KeyboardInterrupt: - dispatcher.stop() - print "Exiting..." +# ====================================================================================== class FuncXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer): + def __init__(self, args): + self.allow_reuse_address = True SimpleXMLRPCServer.SimpleXMLRPCServer.__init__(self, args) + +# ====================================================================================== def main(argv): + """ Start things up. """ - websvc = XmlRpcInterface() - - for arg in sys.argv: - if arg == "import" or arg == "--import": - prov_obj = provisioning.Provisioning() - prov_obj.init(None, {}) - return - elif arg == "sync" or arg == "--sync": - prov_obj = provisioning.Provisioning() - prov_obj.sync(None, {}) # just for testing - return - if "qpid" in sys.argv or "--qpid" in sys.argv: - if "daemon" in sys.argv or "--daemon" in sys.argv: - utils.daemonize("/var/run/vf_server_qpid.pid") - else: - print "serving...\n" - serve_qpid("/etc/virt-factory/qpid.conf") + modules = module_loader.load_modules() + + print "\n\n\n\n\n" + print " WARNING WARNING WARNING" + print "DANGER DANGER DANGER" + print "\n\n\n\n" + print "THERE IS NO AUTHENTICATION IN THIS VERSION" + print "DO NOT RUN ON A MACHINE EXPOSED TO ANYONE YOU DO NOT TRUST" + print " THEY CAN DO VERY BAD THINGS" + print "\n\n\n\n\n" + print "Really, don't do that. It is not at all secure at the moment" + print "like, at all." + print "" + print "Seriously.\n\n" + + try: + websvc = XmlRpcInterface(modules=modules) + except FuncException, e: + print >> sys.stderr, 'error: %s' % e + sys.exit(1) + + if "daemon" in sys.argv or "--daemon" in sys.argv: + utils.daemonize("/var/run/vf_server.pid") else: - if "daemon" in sys.argv or "--daemon" in sys.argv: - utils.daemonize("/var/run/vf_server.pid") - else: - print "serving...\n" - # daemonize only if --daemonize, because I forget to type "debug" -- MPD - serve(websvc) - -# FIXME: upgrades? database upgrade logic would be nice to have here, as would general creation (?) -# FIXME: command line way to add a distro would be nice to have in the future, rsync import is a bit heavy handed. -# (and might not be enough for RHEL, but is good for Fedora/Centos) + print "serving...\n" + serve(websvc) + +# ====================================================================================== if __name__ == "__main__": textdomain(I18N_DOMAIN) |
