def get_official_client(username, password): """ Get official vantage6 client. :param username: :param password: :return: """ client = Client(_HOST, _PORT) client.authenticate(username, password) client.setup_encryption(None) return client
def create_client_and_authenticate(ctx): """Create a client and authenticate.""" host = ctx.config['server_url'] port = ctx.config['port'] api_path = ctx.config['api_path'] info(f"Connecting to server at '{host}:{port}{api_path}'") username = q.text("Username:"******"Password:"******"Could not authenticate with server!") debug(e) exit(1) return client
# print the results per node for result in results: node_id = result.get("node") print("-" * 80) print(f"Results from node = {node_id}") print(result.get("result")) # central server configuration host = "http://192.168.37.1" port = 5000 collaboration_id = 3 # 1. authenticate to the central server client = Client(host=host, port=port, path="/api") client.setup_encryption(None) client.authenticate("root", "admin") # 2. connect to websocket interface bearer_token = client.token socket = SocketIO(host, port=port, headers={"Authorization": f"Bearer {bearer_token}"}) # subscribe to the websocket channel. taskNamespace = socket.define(TasksNamespace, "/tasks") taskNamespace.emit("join_room", f"collaboration_{collaboration_id}") # input for the dsummary Docker image (algorithm) input_ = {
A more advanced example shows how to obtain the results using websockets The researcher has to execute the following steps: 1) Authenticate to the central-server 2) Prepare the input for the algorithm 3) Post a new task to a collaboration on the central server 4) Wait for all results to finish (polling) 5) Obtain the results 6) Optionally do some central processing """ import time from vantage6.client import Client # 1. authenticate to the central server client = Client(host="http://192.168.37.1", port=5000, path="/api") client.setup_encryption(None) client.authenticate("root", "admin") # 2. Prepare input for the dsummary Docker image (algorithm) input_ = { "master": "true", "method": "master", "args": [], "kwargs": { #"functions": ["min", "max"], "columns": [{ "variable": "age", "table": "records", "functions": ["min", "max"] }, {
def setup_client() -> Client: client = Client(HOST, PORT) client.authenticate(FAKE_USERNAME, FAKE_PASSWORD) client.setup_encryption(None) return client
from vantage6.client import Client from pathlib import Path import time print("Attempt login to Vantage6 API") client = Client("http://localhost", 5000, "/api") client.authenticate("johan", "1234") client.setup_encryption(None) input_ = {"master": "true", "method": "master", "args": [], "kwargs": {}} print("Requesting to execute summary algorithm") task = client.post_task(name="testing", image="docker.io/username/imagename", collaboration_id=1, input_=input_, organization_ids=[1]) print("Wait and fetch results") res = client.result.get(id_=task.get("results")[0]['id']) attempts = 1 while ((res["result"] == None) and attempts < 7): print("waiting...") time.sleep(5) res = client.result.get(id_=task.get("results")[0]['id']) attempts += 1 print(res)
# algorithm needs to be executed on the machine of the researcher. # For simplicity this example also uses polling to obtain the results. # A more advanced example shows how to obtain the results using websockets # The researcher has to execute the following steps: # 1) Authenticate to the central-server # 2) Prepare the input for the algorithm # 3) Post a new task to a collaboration on the central server # 4) Wait for central container to finish (polling) # 5) Obtain the results # """ # import time # from vantage6.client import Client # # 1. authenticate to the central server client = Client(host="127.0.0.1", port=5000, path="/api") client.authenticate("root", "admin") client.setup_encryption(None) # # # 2. Prepare input for the dsummary Docker image (algorithm) input_ = { "method": "master", "args": [], "kwargs": { "decimal": ",", "seperator": ";", "columns": { "patient_id": "Int64", "age": "Int64", "weight": "float64",