def serve(port): try: port = schema.And(schema.Use(int), lambda n: MIN_PORT_NUMBER <= n <= MAX_PORT_NUMBER).validate(port) except schema.SchemaError: sys.exit('Error: Invaid port. Must be in the range 1-65535.') except Exception as e: sys.exit('Unxpected Error!!! \n %s' % e) """Start the HaaS API server""" 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: from haas import model, api, rest model.init_db() # Stop all orphan console logging processes on startup db = model.Session() nodes = db.query(model.Node).all() for node in nodes: node.stop_console() node.delete_console() # Start server rest.serve(port, debug=debug)
def launch_server(): """Launch the haas 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)
def serve(): """Start the HaaS API server""" 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: from haas import model, api, rest model.init_db() # Stop all orphan console logging processes on startup db = model.Session() nodes = db.query(model.Node).all() for node in nodes: node.stop_console() node.delete_console() # Start server rest.serve(debug=debug)
def serve(port): try: port = schema.And(schema.Use(int), lambda n: MIN_PORT_NUMBER <= n <= MAX_PORT_NUMBER).validate(port) except schema.SchemaError: sys.exit('Error: Invaid port. Must be in the range 1-65535.') except Exception as e: sys.exit('Unxpected Error!!! \n %s' % e) """Start the HaaS API server""" 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: from haas import model, api, rest server.init(stop_consoles=True) rest.serve(port, debug=debug)
def serve(port): try: port = schema.And( schema.Use(int), lambda n: MIN_PORT_NUMBER <= n <= MAX_PORT_NUMBER).validate(port) except schema.SchemaError: sys.exit('Error: Invaid port. Must be in the range 1-65535.') except Exception as e: sys.exit('Unxpected Error!!! \n %s' % e) """Start the HaaS API server""" 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: from haas import model, api, rest server.init(stop_consoles=True) rest.serve(port, debug=debug)