Ejemplo n.º 1
0
def main(argv=sys.argv):
    """Main method of the Cloud Verifier Server.  This method is encapsulated in a function for packaging to allow it to be 
    called as a function by an external program."""

    config = ConfigParser.SafeConfigParser()
    config.read(common.CONFIG_FILE)

    cloudverifier_port = config.get('general', 'cloudverifier_port')

    db_filename = "%s/%s" % (common.WORK_DIR,
                             config.get('cloud_verifier', 'db_filename'))
    cloud_verifier_common.init_db(db_filename)

    cloud_verifier_common.set_saved()
    num = cloud_verifier_common.count_instances()
    if num > 0:
        logger.info("Instance ids in db loaded from file: %s" %
                    cloud_verifier_common.get_instance_ids())

    logger.info('Starting Cloud Verifier (tornado) on port ' +
                cloudverifier_port + ', use <Ctrl-C> to stop')

    app = tornado.web.Application([
        (r"/", MainHandler),
        (r"/v1/instances", InstancesHandler),
        (r"/crl", CRLHandler),
    ])

    context = cloud_verifier_common.init_tls(config)
    server = tornado.httpserver.HTTPServer(app, ssl_options=context)
    server.bind(int(cloudverifier_port), address='0.0.0.0')
    server.start(
        config.getint('cloud_verifier', 'multiprocessing_pool_num_workers'))
    tornado.ioloop.IOLoop.current().start()
def main(argv=sys.argv):
    """Main method of the Cloud Verifier Server.  This method is encapsulated in a function for packaging to allow it to be 
    called as a function by an external program."""

    config = ConfigParser.SafeConfigParser()
    config.read(common.CONFIG_FILE)

    cloudverifier_port = config.get('general', 'cloudverifier_port')

    db_filename = "%s/%s" % (common.WORK_DIR,
                             config.get('cloud_verifier', 'db_filename'))
    db = cloud_verifier_common.init_db(db_filename)
    db.update_all_instances(
        'operational_state',
        cloud_verifier_common.CloudInstance_Operational_State.SAVED)

    num = db.count_instances()
    if num > 0:
        logger.info("Instance ids in db loaded from file: %s" %
                    db.get_instance_ids())

    logger.info('Starting Cloud Verifier (tornado) on port ' +
                cloudverifier_port + ', use <Ctrl-C> to stop')

    app = tornado.web.Application([
        (r"/v2/instances/.*", InstancesHandler, {
            'db': db
        }),
        (r".*", MainHandler),
    ])

    context = cloud_verifier_common.init_mtls()
    server = tornado.httpserver.HTTPServer(app, ssl_options=context)
    server.bind(int(cloudverifier_port), address='0.0.0.0')

    #after TLS is up, start revocation notifier
    if config.getboolean('cloud_verifier', 'revocation_notifier'):
        logger.info(
            "Starting service for revocation notifications on port %s" %
            config.getint('general', 'revocation_notifier_port'))
        revocation_notifier.start_broker()

    server.start(
        config.getint('cloud_verifier', 'multiprocessing_pool_num_workers'))

    try:
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        tornado.ioloop.IOLoop.instance().stop()
        if config.getboolean('cloud_verifier', 'revocation_notifier'):
            revocation_notifier.stop_broker()