Example #1
0
def start_master(port=None,
                 config=None,
                 config_path=None,
                 block=False,
                 watchdog=True):
    """
    Start a master server instance on this node.

    Kwargs:
        config: A scanner Config object. If specified, config_path is
                ignored.
        config_path: Path to a Scanner configuration TOML, by default
                     assumed to be `~/.scanner.toml`.
        block: If true, will wait until the server is shutdown. Server
               will not shutdown currently unless wait_For_server_shutdown
               is eventually called.

    Returns:
        A cpp database instance.
    """
    config = config or Config(config_path)
    port = port or config.master_port

    # Load all protobuf types
    import libscanner as bindings
    db = bindings.Database(config.storage_config, config.db_path,
                           config.master_address + ':' + port)
    result = bindings.start_master(db, port, watchdog)
    if not result.success:
        raise ScannerException('Failed to start master: {}'.format(result.msg))
    if block:
        bindings.wait_for_server_shutdown(db)
    return db
Example #2
0
def start_worker(master_address,
                 machine_params=None,
                 port=None,
                 config=None,
                 config_path=None,
                 block=False,
                 watchdog=True):
    """
    Start a worker instance on this node.

    Args:
        master_address: The address of the master server to connect this worker
                        to.

    Kwargs:
        config: A scanner Config object. If specified, config_path is
                ignored.
        config_path: Path to a Scanner configuration TOML, by default
                     assumed to be `~/.scanner.toml`.
        block: If true, will wait until the server is shutdown. Server
               will not shutdown currently unless wait_ror_server_shutdown
               is eventually called.

    Returns:
        A cpp database instance.
    """
    config = config or Config(config_path)
    port = port or config.worker_port

    # Load all protobuf types
    import libscanner as bindings
    db = bindings.Database(
        config.storage_config,
        #storage_config,
        config.db_path,
        master_address)
    machine_params = machine_params or bindings.default_machine_params()
    result = bindings.start_worker(db, machine_params,
                                   str(port).encode('ascii'), watchdog)
    if not result.success:
        raise ScannerException('Failed to start worker: {}'.format(result.msg))
    if block:
        bindings.wait_for_server_shutdown(db)
    return result