Example #1
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    is_pserve = sys.argv[0] in [os.path.join(os.getenv('VENV'), 'bin/pserve'),
                                os.path.join(os.getenv('VENV'), 'bin/nosetests')]

    init_ixiacr_logger()

    # Query debugging fluff....
    def before_cursor_execute(conn, cursor, statement,
                            parameters, context, executemany):
        context._query_start_time = time.time()
        ixiacrlogger.debug("Start Query - statement: %s" % statement)
        ixiacrlogger.debug("Start Query - parameters: %s" % parameters)

    def after_cursor_execute(conn, cursor, statement,
                            parameters, context, executemany):
        total = time.time() - context._query_start_time
        ixiacrlogger.debug("Query Complete!")
        ixiacrlogger.debug("Total Time: %f" % total)


    engine = engine_from_config(settings, 'sqlalchemy.')

    #Uncomment if you would like to debug sql statements in pserve log...
    #event.listen(engine, "before_cursor_execute", before_cursor_execute)
    #event.listen(engine, "after_cursor_execute", after_cursor_execute)

    db.configure(bind=engine)

    if is_pserve:
        # Sessions
        session_factory = session_factory_from_settings(settings)
        # set_cache_regions_from_settings(settings)

        # Configure our authorization policy
        authentication = RemoteUserAuthenticationPolicy(
            '!@#$%12345@345@34523$%@#$%@#$2$%@3$%2#523452345',
            callback=has_group)
        authorization= ACLAuthorizationPolicy()

        settings = dict(settings)
        settings.setdefault('jinja2.i18n.domain', 'messages')

        # Create the Pyramid Configurator.
        config = Configurator(settings=settings, session_factory=session_factory,
            root_factory='ixiacr.models.IxiaACLFactory',
            authentication_policy=authentication,
            authorization_policy=authorization)

        # Secure by default all views/handlers
        # Comment this line out to return to the old behavior of all API being unauthenticated
        # config.set_default_permission(Authenticated)

        if 'debug' in settings and settings['debug'].lower() != 'false':
            config.include('pyramid_debugtoolbar')

        # Static views and handlers
        config.include('pyramid_handlers')
        config.include('pyramid_jinja2')
        config.include("pyramid_beaker")
        config.add_static_view('static', 'static')
        config.add_jinja2_search_path("ixiacr:templates")

        config.add_translation_dirs("ixiacr:locale/")
        config._set_locale_negotiator(create_locale_negotiator(['en'], 'en'))

        # The core app views
        config.include('ixiacr.handlers.core.view_includes')

        # The Ixia test views
        config.include('ixiacr.handlers.tests.view_includes')

        # The Ixia test views
        config.include('ixiacr.handlers.tasks.view_includes')

        # The login/auth handlers
        config.include('ixiacr.handlers.auth.view_includes')

        # The admin handlers
        config.include('ixiacr.handlers.admin.view_includes')

        # The utility handlers
        config.include('ixiacr.handlers.utils.view_includes')

        # JSON api functions
        config.include('ixiacr.views.ixiacr_json.view_includes')

        # STATIC Test result ReST
        config.include('ixiacr.views.results.view_includes')

        # Load everything, except things matched by ignore
        # We *MUST* have the ignore here, otherwise mock objects from the
        # unit test get loaded and screw everything up
        # There is no reason to load these scripts either.
        config.scan(ignore=[re.compile('utest$').search,
                            'ixiacr.scripts'])

        patch_pyramid_xmlrpc()

    else:
        config = Configurator()

    # Toggle this expression to enable the profiler.
    # Profile results are available at https://<ip>/_RequestProfiler
    if True:
        return config.make_wsgi_app()
    else:
        return RequestProfiler(config.make_wsgi_app(),
                               custom_cols=['db_sel', 'db_update',
                                            'memc_get', 'memc_set', 'memc_del'])
Example #2
0
        '''
        The result data consumer callback that processes results into the data
        object being passed in from the task consumer.
        '''
        try:
            result = cPickle.loads(body)
            assert result, 'Unable to unpickle result object'

            self._results.append(result)

            if result.resulttype in self.RESULT_SYNC_TRIGGERS:
                self._sync_results()

            return True

        except Exception as e:
            self.log.exception('ResultsConsumer: {0}'.format(e))
            return False

    def run(self):
        self.rr.read(self.process_result)


if __name__ == '__main__':
    try:
        init_ixiacr_logger()
        rc = ResultsConsumer()
        rc.run()
    except Exception as e:
        print str(e)