Пример #1
0
    def __init__(self, options):
        # Launch reverse proxy
        start_proxy(options)

        make_dirs = [
            os.path.dirname(os.path.abspath(options.access_log)),
            os.path.dirname(os.path.abspath(options.error_log)),
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_debugreports_path()),
            os.path.abspath(config.get_distros_store())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        self.configObj = KimchiConfig()
        cherrypy.tools.nocache = cherrypy.Tool('on_end_resource', set_no_cache)
        cherrypy.tools.kimchiauth = cherrypy.Tool('before_handler',
                                                  auth.kimchiauth)
        # Setting host to 127.0.0.1. This makes kimchi runs
        # as a localhost app, inaccessible to the outside
        # directly. You must go through the proxy.
        cherrypy.server.socket_host = '127.0.0.1'
        cherrypy.server.socket_port = options.cherrypy_port
        cherrypy.config.nginx_port = options.port

        cherrypy.log.screen = True
        cherrypy.log.access_file = options.access_log
        cherrypy.log.error_file = options.error_log

        logLevel = LOGGING_LEVEL.get(options.log_level, logging.DEBUG)
        dev_env = options.environment != 'production'

        # Create handler to rotate access log file
        h = logging.handlers.RotatingFileHandler(options.access_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add access log file to cherrypy configuration
        cherrypy.log.access_log.addHandler(h)

        # Create handler to rotate error log file
        h = logging.handlers.RotatingFileHandler(options.error_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add rotating log file to cherrypy configuration
        cherrypy.log.error_log.addHandler(h)

        # Handling running mode
        if not dev_env:
            cherrypy.config.update({'environment': 'production'})

        if hasattr(options, 'model'):
            model_instance = options.model
        elif options.test:
            model_instance = mockmodel.get_mock_environment()
        else:
            model_instance = model.Model()

        if isinstance(model_instance, model.Model):
            vnc_ws_proxy = vnc.new_ws_proxy()
            cherrypy.engine.subscribe('exit', vnc_ws_proxy.kill)

        for ident, node in sub_nodes.items():
            if node.url_auth:
                cfg = self.configObj
                ident = "/%s" % ident
                cfg[ident] = {'tools.kimchiauth.on': True}
                if node.admin_methods:
                    cfg[ident][
                        'tools.kimchiauth.admin_methods'] = node.admin_methods

        self.app = cherrypy.tree.mount(KimchiRoot(model_instance, dev_env),
                                       config=self.configObj)
        self._load_plugins()

        # Terminate proxy when cherrypy server is terminated
        cherrypy.engine.subscribe('exit', terminate_proxy)

        cherrypy.lib.sessions.init()
Пример #2
0
    def __init__(self, options):
        # Launch reverse proxy
        start_proxy(options)

        make_dirs = [
            os.path.dirname(os.path.abspath(options.access_log)),
            os.path.dirname(os.path.abspath(options.error_log)),
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_debugreports_path()),
            os.path.abspath(config.get_distros_store())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        self.configObj = KimchiConfig()
        cherrypy.tools.nocache = cherrypy.Tool('on_end_resource', set_no_cache)
        cherrypy.tools.kimchiauth = cherrypy.Tool('before_handler',
                                                  auth.kimchiauth)
        # Setting host to 127.0.0.1. This makes kimchi runs
        # as a localhost app, inaccessible to the outside
        # directly. You must go through the proxy.
        cherrypy.server.socket_host = '127.0.0.1'
        cherrypy.server.socket_port = options.cherrypy_port
        cherrypy.config.nginx_port = options.port

        cherrypy.log.screen = True
        cherrypy.log.access_file = options.access_log
        cherrypy.log.error_file = options.error_log

        logLevel = LOGGING_LEVEL.get(options.log_level, logging.DEBUG)
        dev_env = options.environment != 'production'

        # Create handler to rotate access log file
        h = logging.handlers.RotatingFileHandler(options.access_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add access log file to cherrypy configuration
        cherrypy.log.access_log.addHandler(h)

        # Create handler to rotate error log file
        h = logging.handlers.RotatingFileHandler(options.error_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add rotating log file to cherrypy configuration
        cherrypy.log.error_log.addHandler(h)

        # Handling running mode
        if not dev_env:
            cherrypy.config.update({'environment': 'production'})

        if hasattr(options, 'model'):
            model_instance = options.model
        elif options.test:
            model_instance = mockmodel.get_mock_environment()
        else:
            model_instance = model.Model()

        if isinstance(model_instance, model.Model):
            vnc_ws_proxy = vnc.new_ws_proxy()
            cherrypy.engine.subscribe('exit', vnc_ws_proxy.kill)

        for ident, node in sub_nodes.items():
            if node.url_auth:
                cfg = self.configObj
                ident = "/%s" % ident
                cfg[ident] = {'tools.kimchiauth.on': True}
                if node.admin_methods:
                    cfg[ident][
                        'tools.kimchiauth.admin_methods'] = node.admin_methods

        self.app = cherrypy.tree.mount(KimchiRoot(model_instance, dev_env),
                                       config=self.configObj)
        self._load_plugins()

        # Terminate proxy when cherrypy server is terminated
        cherrypy.engine.subscribe('exit', terminate_proxy)

        cherrypy.lib.sessions.init()
Пример #3
0
    def __init__(self, options):
        make_dirs = [
            os.path.dirname(os.path.abspath(options.access_log)),
            os.path.dirname(os.path.abspath(options.error_log)),
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_session_path()),
            os.path.abspath(config.get_debugreports_path()),
            os.path.abspath(config.get_distros_store())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        cherrypy.tools.nocache = cherrypy.Tool('on_end_resource', set_no_cache)
        cherrypy.tools.kimchiauth = cherrypy.Tool('before_handler',
                                                  auth.kimchiauth)
        cherrypy.server.socket_host = options.host
        cherrypy.server.socket_port = options.port

        # SSL Server
        try:
            if options.ssl_port and options.ssl_port > 0:
                self._init_ssl(options)
        except AttributeError:
            pass

        cherrypy.log.screen = True
        cherrypy.log.access_file = options.access_log
        cherrypy.log.error_file = options.error_log

        logLevel = LOGGING_LEVEL.get(options.log_level, logging.DEBUG)
        dev_env = options.environment != 'production'

        # Create handler to rotate access log file
        h = logging.handlers.RotatingFileHandler(options.access_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add access log file to cherrypy configuration
        cherrypy.log.access_log.addHandler(h)

        # Create handler to rotate error log file
        h = logging.handlers.RotatingFileHandler(options.error_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add rotating log file to cherrypy configuration
        cherrypy.log.error_log.addHandler(h)

        # Handling running mode
        if not dev_env:
            cherrypy.config.update({'environment': 'production'})

        if hasattr(options, 'model'):
            model_instance = options.model
        elif options.test:
            model_instance = mockmodel.get_mock_environment()
        else:
            model_instance = model.Model()

        if isinstance(model_instance, model.Model):
            vnc_ws_proxy = vnc.new_ws_proxy()
            cherrypy.engine.subscribe('exit', vnc_ws_proxy.kill)

        for ident, node in sub_nodes.items():
            if node.url_auth:
                self.configObj["/%s" % ident] = {'tools.kimchiauth.on': True}

        self.app = cherrypy.tree.mount(KimchiRoot(model_instance, dev_env),
                                       config=self.configObj)
        self._load_plugins()

        cherrypy.lib.sessions.init()