Ejemplo n.º 1
0
def serve(port):
    """Run a development api server. Don't use this in production."""
    try:
        port = schema.And(
            schema.Use(int),
            lambda n: MIN_PORT_NUMBER <= n <= MAX_PORT_NUMBER).validate(port)
    except schema.SchemaError:
        raise InvalidAPIArgumentsException(
            'Error: Invaid port. Must be in the range 1-65535.')
    except Exception as e:
        sys.exit('Unxpected Error!!! \n %s' % e)
    """Start the HIL API server"""
    config.setup()
    if cfg.has_option('devel', 'debug'):
        debug = cfg.getboolean('devel', 'debug')
    else:
        debug = False
    # We need to import api here so that the functions within it get registered
    # (via `rest_call`), though we don't use it directly:
    # pylint: disable=unused-variable
    from hil import api, rest
    server.init()
    migrations.check_db_schema()
    server.stop_orphan_consoles()
    rest.serve(port, debug=debug)
Ejemplo n.º 2
0
Archivo: admin.py Proyecto: CCI-MOC/hil
 def run(self, port):
     if config.cfg.has_option('devel', 'debug'):
         debug = config.cfg.getboolean('devel', 'debug')
     else:
         debug = False
     # We need to import api here so that the functions within it get
     # registered (via `rest_call`), though we don't use it directly:
     # pylint: disable=unused-variable
     from hil import api
     server.init()
     migrations.check_db_schema()
     server.stop_orphan_consoles()
     rest.serve(port, debug=debug)
Ejemplo n.º 3
0
 def run(self, port):
     if config.cfg.has_option('devel', 'debug'):
         debug = config.cfg.getboolean('devel', 'debug')
     else:
         debug = False
     # We need to import api here so that the functions within it get
     # registered (via `rest_call`), though we don't use it directly:
     # pylint: disable=unused-variable
     from hil import api
     server.init()
     migrations.check_db_schema()
     server.stop_orphan_consoles()
     rest.serve(port, debug=debug)
Ejemplo n.º 4
0
def launch_server():
    """Launch the hil API server in another thread.

    The keystone client will try to make *real* http requests, so we can't
    just use flask's built-in test fixtures; we need to actually be listening
    on a port.

    Starts the server listening on port 6000. Will not return until the
    server is actually accepting connections.

    We use 6000 instead of the usual 5000, because the latter is used by
    keystone itself.
    """
    # `debug=False` is required because otherwise something in the
    # implementation of werkzeug calls `signal`, and we get a
    # `ValueError` because (apparently) this doesn't work outside of
    # the main thread.
    Thread(target=lambda: rest.serve(port=6000, debug=False)).start()

    # Poll the server to see if it's accepting connections yet:
    while True:
        try:
            requests.get('http://localhost:6000')
            return
        except requests.exceptions.ConnectionError:
            time.sleep(0.2)
Ejemplo n.º 5
0
def launch_server():
    """Launch the hil API server in another thread.

    The keystone client will try to make *real* http requests, so we can't
    just use flask's built-in test fixtures; we need to actually be listening
    on a port.

    Starts the server listening on port 6000. Will not return until the
    server is actually accepting connections.

    We use 6000 instead of the usual 5000, because the latter is used by
    keystone itself.
    """
    # `debug=False` is required because otherwise something in the
    # implementation of werkzeug calls `signal`, and we get a
    # `ValueError` because (apparently) this doesn't work outside of
    # the main thread.
    Thread(target=lambda: rest.serve(port=6000,
                                     debug=False)).start()

    # Poll the server to see if it's accepting connections yet:
    while True:
        try:
            requests.get('http://localhost:6000')
            return
        except requests.exceptions.ConnectionError:
            time.sleep(0.2)