From 035f652455e0be942bd5a8f8da68a1ed4c6b11b1 Mon Sep 17 00:00:00 2001 From: KatHellg Date: Fri, 8 Nov 2024 16:27:21 +0100 Subject: [PATCH 01/11] session_id flag added --- fedn/cli/client_cmd.py | 14 +++++++++++--- fedn/cli/combiner_cmd.py | 14 +++++++++++--- fedn/cli/model_cmd.py | 34 +++++++++++++++++++++++++++++++--- fedn/cli/package_cmd.py | 14 +++++++++++--- fedn/cli/round_cmd.py | 35 ++++++++++++++++++++++++++++++++--- fedn/cli/session_cmd.py | 16 ++++++++++++---- fedn/cli/shared.py | 25 +++++++++++++++++-------- fedn/cli/status_cmd.py | 34 +++++++++++++++++++++++++++++++--- fedn/cli/validation_cmd.py | 34 +++++++++++++++++++++++++++++++--- 9 files changed, 187 insertions(+), 33 deletions(-) diff --git a/fedn/cli/client_cmd.py b/fedn/cli/client_cmd.py index 7827d1cc0..d24c39e0e 100644 --- a/fedn/cli/client_cmd.py +++ b/fedn/cli/client_cmd.py @@ -39,10 +39,11 @@ def client_cmd(ctx): @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=False, help="Client ID") @click.option("--n_max", required=False, help="Number of items to list") @client_cmd.command("list") @click.pass_context -def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, n_max: int = None): +def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, n_max: int = None): """Return: ------ - count: number of clients @@ -60,12 +61,19 @@ def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, n_ if _token: headers["Authorization"] = _token + if id: + url = f"{url}{id}" + headers["id"] = id + + click.echo(f"\nListing clients: {url}\n") click.echo(f"Headers: {headers}") - try: response = requests.get(url, headers=headers) - print_response(response, "clients") + if id: + print_response(response, "client", True) + else: + print_response(response, "clients", False) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") diff --git a/fedn/cli/combiner_cmd.py b/fedn/cli/combiner_cmd.py index 3e7753e80..d04385231 100644 --- a/fedn/cli/combiner_cmd.py +++ b/fedn/cli/combiner_cmd.py @@ -67,10 +67,11 @@ def start_cmd(ctx, discoverhost, discoverport, token, name, host, port, fqdn, se @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=False, help="Combiner ID") @click.option("--n_max", required=False, help="Number of items to list") @combiner_cmd.command("list") @click.pass_context -def list_combiners(ctx, protocol: str, host: str, port: str, token: str = None, n_max: int = None): +def list_combiners(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, n_max: int = None): """Return: ------ - count: number of combiners @@ -88,11 +89,18 @@ def list_combiners(ctx, protocol: str, host: str, port: str, token: str = None, if _token: headers["Authorization"] = _token + if id: + url = f"{url}{id}" + headers["id"] = id + + click.echo(f"\nListing combiners: {url}\n") click.echo(f"Headers: {headers}") - try: response = requests.get(url, headers=headers) - print_response(response, "combiners") + if id: + print_response(response, "combiner", True) + else: + print_response(response, "combiners", False) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") diff --git a/fedn/cli/model_cmd.py b/fedn/cli/model_cmd.py index 80a8f795e..a1f2a2343 100644 --- a/fedn/cli/model_cmd.py +++ b/fedn/cli/model_cmd.py @@ -17,10 +17,12 @@ def model_cmd(ctx): @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=False, help="Model ID") +@click.option("-session_id", "--session_id", required=False, help="models in session with given session id") @click.option("--n_max", required=False, help="Number of items to list") @model_cmd.command("list") @click.pass_context -def list_models(ctx, protocol: str, host: str, port: str, token: str = None, n_max: int = None): +def list_models(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, session_id: str = None, n_max: int = None): """Return: ------ - count: number of models @@ -38,11 +40,37 @@ def list_models(ctx, protocol: str, host: str, port: str, token: str = None, n_m if _token: headers["Authorization"] = _token + if id: + url = f"{url}{id}" + headers["id"] = id + + click.echo(f"\nListing models: {url}\n") click.echo(f"Headers: {headers}") - try: response = requests.get(url, headers=headers) - print_response(response, "models") + if session_id: + if response.status_code == 200: + json_data = response.json() + count, result = json_data.values() + click.echo(f"Found {count} models") + click.echo("\n---------------------------------\n") + for obj in result: + if obj.get("session_id")==session_id: + click.echo("{") + for k, v in obj.items(): + click.echo(f"\t{k}: {v}") + click.echo("}") + + elif response.status_code == 500: + json_data = response.json() + click.echo(f'Error: {json_data["message"]}') + else: + click.echo(f"Error: {response.status_code}") + else: + if id: + print_response(response, "model", True, session_id) + else: + print_response(response, "models", False, session_id) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") diff --git a/fedn/cli/package_cmd.py b/fedn/cli/package_cmd.py index 3c78d9944..7dab52231 100644 --- a/fedn/cli/package_cmd.py +++ b/fedn/cli/package_cmd.py @@ -45,10 +45,11 @@ def create_cmd(ctx, path, name): @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=False, help="Package ID") @click.option("--n_max", required=False, help="Number of items to list") @package_cmd.command("list") @click.pass_context -def list_packages(ctx, protocol: str, host: str, port: str, token: str = None, n_max: int = None): +def list_packages(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, n_max: int = None): """Return: ------ - count: number of packages @@ -66,11 +67,18 @@ def list_packages(ctx, protocol: str, host: str, port: str, token: str = None, n if _token: headers["Authorization"] = _token + if id: + url = f"{url}{id}" + headers["id"] = id + + click.echo(f"\nListing packages: {url}\n") click.echo(f"Headers: {headers}") - try: response = requests.get(url, headers=headers) - print_response(response, "packages") + if id: + print_response(response, "package", True) + else: + print_response(response, "packages", False) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") diff --git a/fedn/cli/round_cmd.py b/fedn/cli/round_cmd.py index ac42f43ef..dc9b66be5 100644 --- a/fedn/cli/round_cmd.py +++ b/fedn/cli/round_cmd.py @@ -16,11 +16,13 @@ def round_cmd(ctx): @click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") +@click.option("-id", "--id", required=False, help="Round ID") +@click.option("-session_id", "--session_id", required=False, help="Rounds in session with given session id") @click.option("-t", "--token", required=False, help="Authentication token") @click.option("--n_max", required=False, help="Number of items to list") @round_cmd.command("list") @click.pass_context -def list_rounds(ctx, protocol: str, host: str, port: str, token: str = None, n_max: int = None): +def list_rounds(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, session_id: str = None, n_max: int = None): """Return: ------ - count: number of rounds @@ -38,11 +40,38 @@ def list_rounds(ctx, protocol: str, host: str, port: str, token: str = None, n_m if _token: headers["Authorization"] = _token + if id: + url = f"{url}{id}" + headers["id"] = id + click.echo(f"\nListing rounds: {url}\n") click.echo(f"Headers: {headers}") - try: response = requests.get(url, headers=headers) - print_response(response, "rounds") + if session_id: + if response.status_code == 200: + json_data = response.json() + count, result = json_data.values() + click.echo(f"Found {count} rounds") + click.echo("\n---------------------------------\n") + for obj in result: + if obj.get("round_config").get("session_id")==session_id: + click.echo("{") + for k, v in obj.items(): + click.echo(f"\t{k}: {v}") + click.echo("}") + + elif response.status_code == 500: + json_data = response.json() + click.echo(f'Error: {json_data["message"]}') + else: + click.echo(f"Error: {response.status_code}") + else: + if id: + print_response(response, "round", True, session_id) + else: + print_response(response, "rounds", False, session_id) + + except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") diff --git a/fedn/cli/session_cmd.py b/fedn/cli/session_cmd.py index 65db98c69..287fe186a 100644 --- a/fedn/cli/session_cmd.py +++ b/fedn/cli/session_cmd.py @@ -17,10 +17,11 @@ def session_cmd(ctx): @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=False, help="Session ID") @click.option("--n_max", required=False, help="Number of items to list") @session_cmd.command("list") @click.pass_context -def list_sessions(ctx, protocol: str, host: str, port: str, token: str = None, n_max: int = None): +def list_sessions(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, n_max: int = None): """Return: ------ - count: number of sessions @@ -38,11 +39,18 @@ def list_sessions(ctx, protocol: str, host: str, port: str, token: str = None, n if _token: headers["Authorization"] = _token + if id: + url = f"{url}{id}" + headers["id"] = id + + click.echo(f"\nListing sessions: {url}\n") click.echo(f"Headers: {headers}") - try: response = requests.get(url, headers=headers) - print_response(response, "sessions") + if id: + print_response(response, "session", True) + else: + print_response(response, "sessions", False) except requests.exceptions.ConnectionError: - click.echo(f"Error: Could not connect to {url}") + click.echo(f"Error: Could not connect to {url}") \ No newline at end of file diff --git a/fedn/cli/shared.py b/fedn/cli/shared.py index d32f4ff43..4fb05590d 100644 --- a/fedn/cli/shared.py +++ b/fedn/cli/shared.py @@ -64,7 +64,7 @@ def get_client_package_dir(path: str) -> str: # Print response from api (list of entities) -def print_response(response, entity_name: str): +def print_response(response, entity_name: str, so, session_id): """Prints the api response to the cli. :param response: type: array @@ -72,18 +72,27 @@ def print_response(response, entity_name: str): :param entity_name: type: string description: name of entity + :param so: + type: boolean + desriptions: single output format (y/n) return: None """ if response.status_code == 200: json_data = response.json() - count, result = json_data.values() - click.echo(f"Found {count} {entity_name}") - click.echo("\n---------------------------------\n") - for obj in result: - click.echo("{") - for k, v in obj.items(): + if so: + click.echo(f"Found {entity_name}") + click.echo("\n---------------------------------\n") + for k, v in json_data.items(): click.echo(f"\t{k}: {v}") - click.echo("}") + else: + count, result = json_data.values() + click.echo(f"Found {count} {entity_name}") + click.echo("\n---------------------------------\n") + for obj in result: + click.echo("{") + for k, v in obj.items(): + click.echo(f"\t{k}: {v}") + click.echo("}") elif response.status_code == 500: json_data = response.json() click.echo(f'Error: {json_data["message"]}') diff --git a/fedn/cli/status_cmd.py b/fedn/cli/status_cmd.py index c879ca1ef..47acdf940 100644 --- a/fedn/cli/status_cmd.py +++ b/fedn/cli/status_cmd.py @@ -16,10 +16,12 @@ def status_cmd(ctx): @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=False, help="Status ID") +@click.option("-session_id", "--session_id", required=False, help="statuses with given session id") @click.option("--n_max", required=False, help="Number of items to list") @status_cmd.command("list") @click.pass_context -def list_statuses(ctx, protocol: str, host: str, port: str, token: str = None, n_max: int = None): +def list_statuses(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, session_id: str = None, n_max: int = None): """Return: ------ - count: number of statuses @@ -37,11 +39,37 @@ def list_statuses(ctx, protocol: str, host: str, port: str, token: str = None, n if _token: headers["Authorization"] = _token + if id: + url = f"{url}{id}" + headers["id"] = id + + click.echo(f"\nListing statuses: {url}\n") click.echo(f"Headers: {headers}") - try: response = requests.get(url, headers=headers) - print_response(response, "statuses") + if session_id: + if response.status_code == 200: + json_data = response.json() + count, result = json_data.values() + click.echo(f"Found {count} statuses") + click.echo("\n---------------------------------\n") + for obj in result: + if obj.get("session_id")==session_id: + click.echo("{") + for k, v in obj.items(): + click.echo(f"\t{k}: {v}") + click.echo("}") + + elif response.status_code == 500: + json_data = response.json() + click.echo(f'Error: {json_data["message"]}') + else: + click.echo(f"Error: {response.status_code}") + else: + if id: + print_response(response, "status", True) + else: + print_response(response, "statuses", False) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") diff --git a/fedn/cli/validation_cmd.py b/fedn/cli/validation_cmd.py index 4bf4e63fa..b8b29b4c4 100644 --- a/fedn/cli/validation_cmd.py +++ b/fedn/cli/validation_cmd.py @@ -17,10 +17,12 @@ def validation_cmd(ctx): @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=False, help="validation ID") +@click.option("-session_id", "--session_id", required=False, help="validations in session with given session id") @click.option("--n_max", required=False, help="Number of items to list") @validation_cmd.command("list") @click.pass_context -def list_validations(ctx, protocol: str, host: str, port: str, token: str = None, n_max: int = None): +def list_validations(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, session_id: str = None, n_max: int = None): """Return: ------ - count: number of validations @@ -38,11 +40,37 @@ def list_validations(ctx, protocol: str, host: str, port: str, token: str = None if _token: headers["Authorization"] = _token + if id: + url = f"{url}{id}" + headers["id"] = id + + click.echo(f"\nListing validations: {url}\n") click.echo(f"Headers: {headers}") - try: response = requests.get(url, headers=headers) - print_response(response, "validations") + if session_id: + if response.status_code == 200: + json_data = response.json() + count, result = json_data.values() + click.echo(f"Found {count} statuses") + click.echo("\n---------------------------------\n") + for obj in result: + if obj.get("session_id")==session_id: + click.echo("{") + for k, v in obj.items(): + click.echo(f"\t{k}: {v}") + click.echo("}") + + elif response.status_code == 500: + json_data = response.json() + click.echo(f'Error: {json_data["message"]}') + else: + click.echo(f"Error: {response.status_code}") + else: + if id: + print_response(response, "validation", True) + else: + print_response(response, "validations", False) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") From 131e045792ce897a7ef050fe27a1ba8a7a00b00d Mon Sep 17 00:00:00 2001 From: KatHellg Date: Mon, 11 Nov 2024 13:12:19 +0100 Subject: [PATCH 02/11] minor code fix --- fedn/cli/model_cmd.py | 7 +++---- fedn/cli/round_cmd.py | 7 +++---- fedn/cli/status_cmd.py | 7 +++---- fedn/cli/validation_cmd.py | 7 +++---- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/fedn/cli/model_cmd.py b/fedn/cli/model_cmd.py index a1f2a2343..c3b2d587b 100644 --- a/fedn/cli/model_cmd.py +++ b/fedn/cli/model_cmd.py @@ -67,10 +67,9 @@ def list_models(ctx, protocol: str, host: str, port: str, token: str = None, id: click.echo(f'Error: {json_data["message"]}') else: click.echo(f"Error: {response.status_code}") + elif id: + print_response(response, "model", True, session_id) else: - if id: - print_response(response, "model", True, session_id) - else: - print_response(response, "models", False, session_id) + print_response(response, "models", False, session_id) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") diff --git a/fedn/cli/round_cmd.py b/fedn/cli/round_cmd.py index dc9b66be5..68364202c 100644 --- a/fedn/cli/round_cmd.py +++ b/fedn/cli/round_cmd.py @@ -66,11 +66,10 @@ def list_rounds(ctx, protocol: str, host: str, port: str, token: str = None, id: click.echo(f'Error: {json_data["message"]}') else: click.echo(f"Error: {response.status_code}") + elif id: + print_response(response, "round", True, session_id) else: - if id: - print_response(response, "round", True, session_id) - else: - print_response(response, "rounds", False, session_id) + print_response(response, "rounds", False, session_id) except requests.exceptions.ConnectionError: diff --git a/fedn/cli/status_cmd.py b/fedn/cli/status_cmd.py index 47acdf940..01f7c497a 100644 --- a/fedn/cli/status_cmd.py +++ b/fedn/cli/status_cmd.py @@ -66,10 +66,9 @@ def list_statuses(ctx, protocol: str, host: str, port: str, token: str = None, i click.echo(f'Error: {json_data["message"]}') else: click.echo(f"Error: {response.status_code}") + elif id: + print_response(response, "status", True) else: - if id: - print_response(response, "status", True) - else: - print_response(response, "statuses", False) + print_response(response, "statuses", False) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") diff --git a/fedn/cli/validation_cmd.py b/fedn/cli/validation_cmd.py index b8b29b4c4..1dc68c311 100644 --- a/fedn/cli/validation_cmd.py +++ b/fedn/cli/validation_cmd.py @@ -67,10 +67,9 @@ def list_validations(ctx, protocol: str, host: str, port: str, token: str = None click.echo(f'Error: {json_data["message"]}') else: click.echo(f"Error: {response.status_code}") + elif id: + print_response(response, "validation", True) else: - if id: - print_response(response, "validation", True) - else: - print_response(response, "validations", False) + print_response(response, "validations", False) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") From ef2543dd1acb3ed389c87aac0837056843f46370 Mon Sep 17 00:00:00 2001 From: KatHellg Date: Mon, 11 Nov 2024 13:15:17 +0100 Subject: [PATCH 03/11] added new line end of session cmd file --- fedn/cli/session_cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fedn/cli/session_cmd.py b/fedn/cli/session_cmd.py index 287fe186a..28f630880 100644 --- a/fedn/cli/session_cmd.py +++ b/fedn/cli/session_cmd.py @@ -53,4 +53,4 @@ def list_sessions(ctx, protocol: str, host: str, port: str, token: str = None, i else: print_response(response, "sessions", False) except requests.exceptions.ConnectionError: - click.echo(f"Error: Could not connect to {url}") \ No newline at end of file + click.echo(f"Error: Could not connect to {url}") From 794a0b136241bdd48afaa65ab52caefff3567c9b Mon Sep 17 00:00:00 2001 From: KatHellg Date: Wed, 13 Nov 2024 14:52:39 +0100 Subject: [PATCH 04/11] fixed acc to feedback --- fedn/cli/client_cmd.py | 43 +++++++++++++++++++----- fedn/cli/combiner_cmd.py | 42 +++++++++++++++++++---- fedn/cli/model_cmd.py | 68 +++++++++++++++++++++++--------------- fedn/cli/package_cmd.py | 42 +++++++++++++++++++---- fedn/cli/round_cmd.py | 68 +++++++++++++++++++++++--------------- fedn/cli/session_cmd.py | 43 +++++++++++++++++++----- fedn/cli/shared.py | 3 +- fedn/cli/status_cmd.py | 66 +++++++++++++++++++++--------------- fedn/cli/validation_cmd.py | 62 ++++++++++++++++++++-------------- 9 files changed, 303 insertions(+), 134 deletions(-) diff --git a/fedn/cli/client_cmd.py b/fedn/cli/client_cmd.py index d24c39e0e..00f903926 100644 --- a/fedn/cli/client_cmd.py +++ b/fedn/cli/client_cmd.py @@ -39,11 +39,10 @@ def client_cmd(ctx): @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=False, help="Client ID") @click.option("--n_max", required=False, help="Number of items to list") @client_cmd.command("list") @click.pass_context -def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, n_max: int = None): +def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, n_max: int = None): """Return: ------ - count: number of clients @@ -58,6 +57,38 @@ def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, id _token = get_token(token) + if _token: + headers["Authorization"] = _token + + + click.echo(f"\nListing clients: {url}\n") + click.echo(f"Headers: {headers}") + try: + response = requests.get(url, headers=headers) + print_response(response, "clients", None) + except requests.exceptions.ConnectionError: + click.echo(f"Error: Could not connect to {url}") + + +@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") +@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") +@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") +@click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=False, help="Client ID") +@client_cmd.command("get") +@click.pass_context +def get_client(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): + """Return: + ------ + - count: number of clients + - result: list of clients + + """ + url = get_api_url(protocol=protocol, host=host, port=port, endpoint="clients") + headers = {} + + _token = get_token(token) + if _token: headers["Authorization"] = _token @@ -66,18 +97,14 @@ def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, id headers["id"] = id - click.echo(f"\nListing clients: {url}\n") + click.echo(f"\nRetrieving client: {url}\n") click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) - if id: - print_response(response, "client", True) - else: - print_response(response, "clients", False) + print_response(response, "client", id) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") - @client_cmd.command("start") @click.option("-d", "--discoverhost", required=False, help="Hostname for discovery services(reducer).") @click.option("-p", "--discoverport", required=False, help="Port for discovery services (reducer).") diff --git a/fedn/cli/combiner_cmd.py b/fedn/cli/combiner_cmd.py index d04385231..f7e937261 100644 --- a/fedn/cli/combiner_cmd.py +++ b/fedn/cli/combiner_cmd.py @@ -67,11 +67,10 @@ def start_cmd(ctx, discoverhost, discoverport, token, name, host, port, fqdn, se @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=False, help="Combiner ID") @click.option("--n_max", required=False, help="Number of items to list") @combiner_cmd.command("list") @click.pass_context -def list_combiners(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, n_max: int = None): +def list_combiners(ctx, protocol: str, host: str, port: str, token: str = None, n_max: int = None): """Return: ------ - count: number of combiners @@ -84,6 +83,38 @@ def list_combiners(ctx, protocol: str, host: str, port: str, token: str = None, if n_max: headers["X-Limit"] = n_max + _token = get_token(token) + + if _token: + headers["Authorization"] = _token + + + click.echo(f"\nListing combiners: {url}\n") + click.echo(f"Headers: {headers}") + try: + response = requests.get(url, headers=headers) + print_response(response, "combiners", None) + except requests.exceptions.ConnectionError: + click.echo(f"Error: Could not connect to {url}") + + +@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") +@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") +@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") +@click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=False, help="Combiner ID") +@combiner_cmd.command("get") +@click.pass_context +def get_combiner(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): + """Return: + ------ + - result: combiner with given id + + """ + url = get_api_url(protocol=protocol, host=host, port=port, endpoint="combiners") + headers = {} + + _token = get_token(token) if _token: @@ -94,13 +125,10 @@ def list_combiners(ctx, protocol: str, host: str, port: str, token: str = None, headers["id"] = id - click.echo(f"\nListing combiners: {url}\n") + click.echo(f"\nRetrieving combiner: {url}\n") click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) - if id: - print_response(response, "combiner", True) - else: - print_response(response, "combiners", False) + print_response(response, "combiner", id) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") diff --git a/fedn/cli/model_cmd.py b/fedn/cli/model_cmd.py index c3b2d587b..ebf6e6dca 100644 --- a/fedn/cli/model_cmd.py +++ b/fedn/cli/model_cmd.py @@ -17,12 +17,11 @@ def model_cmd(ctx): @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=False, help="Model ID") @click.option("-session_id", "--session_id", required=False, help="models in session with given session id") @click.option("--n_max", required=False, help="Number of items to list") @model_cmd.command("list") @click.pass_context -def list_models(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, session_id: str = None, n_max: int = None): +def list_models(ctx, protocol: str, host: str, port: str, token: str = None, session_id: str = None, n_max: int = None): """Return: ------ - count: number of models @@ -30,11 +29,50 @@ def list_models(ctx, protocol: str, host: str, port: str, token: str = None, id: """ url = get_api_url(protocol=protocol, host=host, port=port, endpoint="models") + + headers = {} if n_max: headers["X-Limit"] = n_max + _token = get_token(token) + + if _token: + headers["Authorization"] = _token + + if session_id: + url = f"{url}?session_id={session_id}" + headers["session_id"] = session_id + + click.echo(f"\nListing models: {url}\n") + click.echo(f"Headers: {headers}") + try: + response = requests.get(url, headers=headers) + print_response(response, "models", None) + except requests.exceptions.ConnectionError: + click.echo(f"Error: Could not connect to {url}") + + +@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") +@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") +@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") +@click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=False, help="Model ID") +@model_cmd.command("get") +@click.pass_context +def get_model(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): + """Return: + ------ + - result: model with given id + + """ + url = get_api_url(protocol=protocol, host=host, port=port, endpoint="models") + + + headers = {} + + _token = get_token(token) if _token: @@ -44,32 +82,10 @@ def list_models(ctx, protocol: str, host: str, port: str, token: str = None, id: url = f"{url}{id}" headers["id"] = id - - click.echo(f"\nListing models: {url}\n") + click.echo(f"\nRetrieving model: {url}\n") click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) - if session_id: - if response.status_code == 200: - json_data = response.json() - count, result = json_data.values() - click.echo(f"Found {count} models") - click.echo("\n---------------------------------\n") - for obj in result: - if obj.get("session_id")==session_id: - click.echo("{") - for k, v in obj.items(): - click.echo(f"\t{k}: {v}") - click.echo("}") - - elif response.status_code == 500: - json_data = response.json() - click.echo(f'Error: {json_data["message"]}') - else: - click.echo(f"Error: {response.status_code}") - elif id: - print_response(response, "model", True, session_id) - else: - print_response(response, "models", False, session_id) + print_response(response, "model", id) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") diff --git a/fedn/cli/package_cmd.py b/fedn/cli/package_cmd.py index 7dab52231..30998b828 100644 --- a/fedn/cli/package_cmd.py +++ b/fedn/cli/package_cmd.py @@ -45,11 +45,10 @@ def create_cmd(ctx, path, name): @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=False, help="Package ID") @click.option("--n_max", required=False, help="Number of items to list") @package_cmd.command("list") @click.pass_context -def list_packages(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, n_max: int = None): +def list_packages(ctx, protocol: str, host: str, port: str, token: str = None, n_max: int = None): """Return: ------ - count: number of packages @@ -62,6 +61,38 @@ def list_packages(ctx, protocol: str, host: str, port: str, token: str = None, i if n_max: headers["X-Limit"] = n_max + _token = get_token(token) + + if _token: + headers["Authorization"] = _token + + + click.echo(f"\nListing packages: {url}\n") + click.echo(f"Headers: {headers}") + try: + response = requests.get(url, headers=headers) + print_response(response, "packages", None) + except requests.exceptions.ConnectionError: + click.echo(f"Error: Could not connect to {url}") + + +@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") +@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") +@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") +@click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=False, help="Package ID") +@package_cmd.command("get") +@click.pass_context +def get_package(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): + """Return: + ------ + - result: package with given id + + """ + url = get_api_url(protocol=protocol, host=host, port=port, endpoint="packages") + headers = {} + + _token = get_token(token) if _token: @@ -72,13 +103,10 @@ def list_packages(ctx, protocol: str, host: str, port: str, token: str = None, i headers["id"] = id - click.echo(f"\nListing packages: {url}\n") + click.echo(f"\nretrieving package: {url}\n") click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) - if id: - print_response(response, "package", True) - else: - print_response(response, "packages", False) + print_response(response, "package", id) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") diff --git a/fedn/cli/round_cmd.py b/fedn/cli/round_cmd.py index 68364202c..d60ff66e4 100644 --- a/fedn/cli/round_cmd.py +++ b/fedn/cli/round_cmd.py @@ -16,13 +16,12 @@ def round_cmd(ctx): @click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") -@click.option("-id", "--id", required=False, help="Round ID") @click.option("-session_id", "--session_id", required=False, help="Rounds in session with given session id") @click.option("-t", "--token", required=False, help="Authentication token") @click.option("--n_max", required=False, help="Number of items to list") @round_cmd.command("list") @click.pass_context -def list_rounds(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, session_id: str = None, n_max: int = None): +def list_rounds(ctx, protocol: str, host: str, port: str, token: str = None, session_id: str = None, n_max: int = None): """Return: ------ - count: number of rounds @@ -30,11 +29,49 @@ def list_rounds(ctx, protocol: str, host: str, port: str, token: str = None, id: """ url = get_api_url(protocol=protocol, host=host, port=port, endpoint="rounds") + headers = {} if n_max: headers["X-Limit"] = n_max + _token = get_token(token) + + if _token: + headers["Authorization"] = _token + + if session_id: + url = f"{url}?round_config.session_id={session_id}" + headers["session_id"] = session_id + + click.echo(f"\nListing rounds: {url}\n") + click.echo(f"Headers: {headers}") + try: + response = requests.get(url, headers=headers) + print_response(response, "rounds", None) + + except requests.exceptions.ConnectionError: + click.echo(f"Error: Could not connect to {url}") + + +@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") +@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") +@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") +@click.option("-id", "--id", required=False, help="Round ID") +@click.option("-t", "--token", required=False, help="Authentication token") +@round_cmd.command("get") +@click.pass_context +def get_round(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): + """Return: + ------ + - result: round with given id + + """ + url = get_api_url(protocol=protocol, host=host, port=port, endpoint="rounds") + + headers = {} + + _token = get_token(token) if _token: @@ -44,33 +81,12 @@ def list_rounds(ctx, protocol: str, host: str, port: str, token: str = None, id: url = f"{url}{id}" headers["id"] = id - click.echo(f"\nListing rounds: {url}\n") + + click.echo(f"\nRetrieving round: {url}\n") click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) - if session_id: - if response.status_code == 200: - json_data = response.json() - count, result = json_data.values() - click.echo(f"Found {count} rounds") - click.echo("\n---------------------------------\n") - for obj in result: - if obj.get("round_config").get("session_id")==session_id: - click.echo("{") - for k, v in obj.items(): - click.echo(f"\t{k}: {v}") - click.echo("}") - - elif response.status_code == 500: - json_data = response.json() - click.echo(f'Error: {json_data["message"]}') - else: - click.echo(f"Error: {response.status_code}") - elif id: - print_response(response, "round", True, session_id) - else: - print_response(response, "rounds", False, session_id) - + print_response(response, "round", id) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") diff --git a/fedn/cli/session_cmd.py b/fedn/cli/session_cmd.py index 28f630880..56184ef2e 100644 --- a/fedn/cli/session_cmd.py +++ b/fedn/cli/session_cmd.py @@ -17,11 +17,10 @@ def session_cmd(ctx): @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=False, help="Session ID") @click.option("--n_max", required=False, help="Number of items to list") @session_cmd.command("list") @click.pass_context -def list_sessions(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, n_max: int = None): +def list_sessions(ctx, protocol: str, host: str, port: str, token: str = None, n_max: int = None): """Return: ------ - count: number of sessions @@ -36,6 +35,37 @@ def list_sessions(ctx, protocol: str, host: str, port: str, token: str = None, i _token = get_token(token) + if _token: + headers["Authorization"] = _token + + + click.echo(f"\nListing sessions: {url}\n") + click.echo(f"Headers: {headers}") + try: + response = requests.get(url, headers=headers) + print_response(response, "sessions", None) + except requests.exceptions.ConnectionError: + click.echo(f"Error: Could not connect to {url}") + + +@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") +@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") +@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") +@click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=True, help="Session ID") +@session_cmd.command("get") +@click.pass_context +def get_session(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): + """Return: + ------ + - result: session with given session id + + """ + url = get_api_url(protocol=protocol, host=host, port=port, endpoint="sessions") + headers = {} + + _token = get_token(token) + if _token: headers["Authorization"] = _token @@ -44,13 +74,10 @@ def list_sessions(ctx, protocol: str, host: str, port: str, token: str = None, i headers["id"] = id - click.echo(f"\nListing sessions: {url}\n") + click.echo(f"\nRetrieving session: {url}\n") click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) - if id: - print_response(response, "session", True) - else: - print_response(response, "sessions", False) + print_response(response, "session", id) except requests.exceptions.ConnectionError: - click.echo(f"Error: Could not connect to {url}") + click.echo(f"Error: Could not connect to {url}") \ No newline at end of file diff --git a/fedn/cli/shared.py b/fedn/cli/shared.py index 4fb05590d..5876828fb 100644 --- a/fedn/cli/shared.py +++ b/fedn/cli/shared.py @@ -64,7 +64,7 @@ def get_client_package_dir(path: str) -> str: # Print response from api (list of entities) -def print_response(response, entity_name: str, so, session_id): +def print_response(response, entity_name: str, so): """Prints the api response to the cli. :param response: type: array @@ -89,6 +89,7 @@ def print_response(response, entity_name: str, so, session_id): click.echo(f"Found {count} {entity_name}") click.echo("\n---------------------------------\n") for obj in result: + print(obj.get("session_id")) click.echo("{") for k, v in obj.items(): click.echo(f"\t{k}: {v}") diff --git a/fedn/cli/status_cmd.py b/fedn/cli/status_cmd.py index 01f7c497a..ea064a857 100644 --- a/fedn/cli/status_cmd.py +++ b/fedn/cli/status_cmd.py @@ -16,12 +16,11 @@ def status_cmd(ctx): @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=False, help="Status ID") @click.option("-session_id", "--session_id", required=False, help="statuses with given session id") @click.option("--n_max", required=False, help="Number of items to list") @status_cmd.command("list") @click.pass_context -def list_statuses(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, session_id: str = None, n_max: int = None): +def list_statuses(ctx, protocol: str, host: str, port: str, token: str = None, session_id: str = None, n_max: int = None): """Return: ------ - count: number of statuses @@ -34,6 +33,42 @@ def list_statuses(ctx, protocol: str, host: str, port: str, token: str = None, i if n_max: headers["X-Limit"] = n_max + _token = get_token(token) + + if _token: + headers["Authorization"] = _token + + if session_id: + url = f"{url}?sessionId={session_id}" + headers["session_id"] = session_id + + + click.echo(f"\nListing statuses: {url}\n") + click.echo(f"Headers: {headers}") + try: + response = requests.get(url, headers=headers) + print_response(response, "statuses", None) + except requests.exceptions.ConnectionError: + click.echo(f"Error: Could not connect to {url}") + + +@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") +@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") +@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") +@click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=False, help="Status ID") +@status_cmd.command("get") +@click.pass_context +def get_status(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): + """Return: + ------ + - result: status with given id + + """ + url = get_api_url(protocol=protocol, host=host, port=port, endpoint="statuses") + headers = {} + + _token = get_token(token) if _token: @@ -44,31 +79,10 @@ def list_statuses(ctx, protocol: str, host: str, port: str, token: str = None, i headers["id"] = id - click.echo(f"\nListing statuses: {url}\n") + click.echo(f"\nRetrieving status: {url}\n") click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) - if session_id: - if response.status_code == 200: - json_data = response.json() - count, result = json_data.values() - click.echo(f"Found {count} statuses") - click.echo("\n---------------------------------\n") - for obj in result: - if obj.get("session_id")==session_id: - click.echo("{") - for k, v in obj.items(): - click.echo(f"\t{k}: {v}") - click.echo("}") - - elif response.status_code == 500: - json_data = response.json() - click.echo(f'Error: {json_data["message"]}') - else: - click.echo(f"Error: {response.status_code}") - elif id: - print_response(response, "status", True) - else: - print_response(response, "statuses", False) + print_response(response, "status", id) except requests.exceptions.ConnectionError: - click.echo(f"Error: Could not connect to {url}") + click.echo(f"Error: Could not connect to {url}") \ No newline at end of file diff --git a/fedn/cli/validation_cmd.py b/fedn/cli/validation_cmd.py index 1dc68c311..10c594398 100644 --- a/fedn/cli/validation_cmd.py +++ b/fedn/cli/validation_cmd.py @@ -17,12 +17,11 @@ def validation_cmd(ctx): @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=False, help="validation ID") @click.option("-session_id", "--session_id", required=False, help="validations in session with given session id") @click.option("--n_max", required=False, help="Number of items to list") @validation_cmd.command("list") @click.pass_context -def list_validations(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None, session_id: str = None, n_max: int = None): +def list_validations(ctx, protocol: str, host: str, port: str, token: str = None, session_id: str = None, n_max: int = None): """Return: ------ - count: number of validations @@ -37,6 +36,40 @@ def list_validations(ctx, protocol: str, host: str, port: str, token: str = None _token = get_token(token) + if _token: + headers["Authorization"] = _token + + if session_id: + url = f"{url}?sessionId={session_id}" + headers["session_id"] = session_id + + click.echo(f"\nListing validations: {url}\n") + click.echo(f"Headers: {headers}") + try: + response = requests.get(url, headers=headers) + print_response(response, "validations", None) + except requests.exceptions.ConnectionError: + click.echo(f"Error: Could not connect to {url}") + + +@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") +@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") +@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") +@click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=False, help="validation ID") +@validation_cmd.command("get") +@click.pass_context +def get_validation(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): + """Return: + ------ + - result: validation with given id + + """ + url = get_api_url(protocol=protocol, host=host, port=port, endpoint="validations") + headers = {} + + _token = get_token(token) + if _token: headers["Authorization"] = _token @@ -45,31 +78,10 @@ def list_validations(ctx, protocol: str, host: str, port: str, token: str = None headers["id"] = id - click.echo(f"\nListing validations: {url}\n") + click.echo(f"\nRetrieving validation: {url}\n") click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) - if session_id: - if response.status_code == 200: - json_data = response.json() - count, result = json_data.values() - click.echo(f"Found {count} statuses") - click.echo("\n---------------------------------\n") - for obj in result: - if obj.get("session_id")==session_id: - click.echo("{") - for k, v in obj.items(): - click.echo(f"\t{k}: {v}") - click.echo("}") - - elif response.status_code == 500: - json_data = response.json() - click.echo(f'Error: {json_data["message"]}') - else: - click.echo(f"Error: {response.status_code}") - elif id: - print_response(response, "validation", True) - else: - print_response(response, "validations", False) + print_response(response, "validation", id) except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") From c83e928531bce6b4d4879a71e6a570f3303232ce Mon Sep 17 00:00:00 2001 From: KatHellg Date: Wed, 13 Nov 2024 14:58:10 +0100 Subject: [PATCH 05/11] code fix --- fedn/cli/model_cmd.py | 4 ++-- fedn/cli/session_cmd.py | 2 +- fedn/cli/status_cmd.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fedn/cli/model_cmd.py b/fedn/cli/model_cmd.py index ebf6e6dca..810b573ab 100644 --- a/fedn/cli/model_cmd.py +++ b/fedn/cli/model_cmd.py @@ -30,7 +30,7 @@ def list_models(ctx, protocol: str, host: str, port: str, token: str = None, ses """ url = get_api_url(protocol=protocol, host=host, port=port, endpoint="models") - + headers = {} if n_max: @@ -69,7 +69,7 @@ def get_model(ctx, protocol: str, host: str, port: str, token: str = None, id: s """ url = get_api_url(protocol=protocol, host=host, port=port, endpoint="models") - + headers = {} diff --git a/fedn/cli/session_cmd.py b/fedn/cli/session_cmd.py index 56184ef2e..65f45ac16 100644 --- a/fedn/cli/session_cmd.py +++ b/fedn/cli/session_cmd.py @@ -80,4 +80,4 @@ def get_session(ctx, protocol: str, host: str, port: str, token: str = None, id: response = requests.get(url, headers=headers) print_response(response, "session", id) except requests.exceptions.ConnectionError: - click.echo(f"Error: Could not connect to {url}") \ No newline at end of file + click.echo(f"Error: Could not connect to {url}") diff --git a/fedn/cli/status_cmd.py b/fedn/cli/status_cmd.py index ea064a857..5b445f07e 100644 --- a/fedn/cli/status_cmd.py +++ b/fedn/cli/status_cmd.py @@ -85,4 +85,4 @@ def get_status(ctx, protocol: str, host: str, port: str, token: str = None, id: response = requests.get(url, headers=headers) print_response(response, "status", id) except requests.exceptions.ConnectionError: - click.echo(f"Error: Could not connect to {url}") \ No newline at end of file + click.echo(f"Error: Could not connect to {url}") From 7c24f1a97baed23f2af75cb92b2e7458eac75c6c Mon Sep 17 00:00:00 2001 From: KatHellg Date: Wed, 13 Nov 2024 15:14:37 +0100 Subject: [PATCH 06/11] fixed conflict --- fedn/cli/client_cmd.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/fedn/cli/client_cmd.py b/fedn/cli/client_cmd.py index 00f903926..8cc4343ec 100644 --- a/fedn/cli/client_cmd.py +++ b/fedn/cli/client_cmd.py @@ -106,6 +106,7 @@ def get_client(ctx, protocol: str, host: str, port: str, token: str = None, id: click.echo(f"Error: Could not connect to {url}") @client_cmd.command("start") +@client_cmd.command("start-v1") @click.option("-d", "--discoverhost", required=False, help="Hostname for discovery services(reducer).") @click.option("-p", "--discoverport", required=False, help="Port for discovery services (reducer).") @click.option("--token", required=False, help="Set token provided by reducer if enabled") @@ -243,18 +244,18 @@ def _complement_client_params(config: dict): click.echo(f"Protocol missing, complementing api_url with protocol: {result}") -@client_cmd.command("start-v2") +@client_cmd.command("start") @click.option("-u", "--api-url", required=False, help="Hostname for fedn api.") @click.option("-p", "--api-port", required=False, help="Port for discovery services (reducer).") @click.option("--token", required=False, help="Set token provided by reducer if enabled") -@click.option("-n", "--name", required=False, default="client" + str(uuid.uuid4())[:8]) +@click.option("-n", "--name", required=False) @click.option("-i", "--client-id", required=False) @click.option("--local-package", is_flag=True, help="Enable local compute package") @click.option("-c", "--preferred-combiner", type=str, required=False, default="", help="name of the preferred combiner") @click.option("--combiner", type=str, required=False, default=None, help="Skip combiner assignment from discover service and attach directly to combiner host.") @click.option("--combiner-port", type=str, required=False, default=None, help="Combiner port, need to be used with --combiner") -@click.option("-va", "--validator", required=False, default=True) -@click.option("-tr", "--trainer", required=False, default=True) +@click.option("-va", "--validator", required=False, default=None) +@click.option("-tr", "--trainer", required=False, default=None) @click.option("-h", "--helper_type", required=False, default=None) @click.option("-in", "--init", required=False, default=None, help="Set to a filename to (re)init client from file state.") @click.pass_context @@ -274,8 +275,6 @@ def client_start_v2_cmd( helper_type: str, init: str, ): - click.echo(click.style("\n*** fedn client start-v2 is experimental ***\n", blink=True, bold=True, fg="red")) - package = "local" if local_package else "remote" config = { @@ -326,6 +325,8 @@ def client_start_v2_cmd( config["name"] = name if config["name"]: click.echo(f"Input param name: {name} overrides value from file") + elif config["name"] is None: + config["name"] = "client" + str(uuid.uuid4())[:8] if client_id and client_id != "": config["client_id"] = client_id @@ -351,11 +352,15 @@ def client_start_v2_cmd( config["validator"] = validator if config["validator"] is not None: click.echo(f"Input param validator: {validator} overrides value from file") + elif config["validator"] is None: + config["validator"] = True if trainer is not None: config["trainer"] = trainer if config["trainer"] is not None: click.echo(f"Input param trainer: {trainer} overrides value from file") + elif config["trainer"] is None: + config["trainer"] = True if helper_type and helper_type != "": config["helper_type"] = helper_type From 4a1d0355d7ca02b120e6fd357c1f088fb1e5bddc Mon Sep 17 00:00:00 2001 From: KatHellg Date: Wed, 13 Nov 2024 15:41:03 +0100 Subject: [PATCH 07/11] conflict + minor fix --- fedn/cli/client_cmd.py | 6 ++---- fedn/cli/combiner_cmd.py | 3 +-- fedn/cli/model_cmd.py | 4 +--- fedn/cli/package_cmd.py | 3 +-- fedn/cli/round_cmd.py | 4 +--- fedn/cli/session_cmd.py | 1 - fedn/cli/status_cmd.py | 5 +---- fedn/cli/validation_cmd.py | 4 +--- 8 files changed, 8 insertions(+), 22 deletions(-) diff --git a/fedn/cli/client_cmd.py b/fedn/cli/client_cmd.py index 8cc4343ec..073b6bb48 100644 --- a/fedn/cli/client_cmd.py +++ b/fedn/cli/client_cmd.py @@ -60,9 +60,9 @@ def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, n_ if _token: headers["Authorization"] = _token - click.echo(f"\nListing clients: {url}\n") click.echo(f"Headers: {headers}") + try: response = requests.get(url, headers=headers) print_response(response, "clients", None) @@ -74,7 +74,7 @@ def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, n_ @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=False, help="Client ID") +@click.option("-id", "--id", required=True, help="Client ID") @client_cmd.command("get") @click.pass_context def get_client(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): @@ -94,7 +94,6 @@ def get_client(ctx, protocol: str, host: str, port: str, token: str = None, id: if id: url = f"{url}{id}" - headers["id"] = id click.echo(f"\nRetrieving client: {url}\n") @@ -105,7 +104,6 @@ def get_client(ctx, protocol: str, host: str, port: str, token: str = None, id: except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") -@client_cmd.command("start") @client_cmd.command("start-v1") @click.option("-d", "--discoverhost", required=False, help="Hostname for discovery services(reducer).") @click.option("-p", "--discoverport", required=False, help="Port for discovery services (reducer).") diff --git a/fedn/cli/combiner_cmd.py b/fedn/cli/combiner_cmd.py index f7e937261..c6ccbeb19 100644 --- a/fedn/cli/combiner_cmd.py +++ b/fedn/cli/combiner_cmd.py @@ -102,7 +102,7 @@ def list_combiners(ctx, protocol: str, host: str, port: str, token: str = None, @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=False, help="Combiner ID") +@click.option("-id", "--id", required=True, help="Combiner ID") @combiner_cmd.command("get") @click.pass_context def get_combiner(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): @@ -122,7 +122,6 @@ def get_combiner(ctx, protocol: str, host: str, port: str, token: str = None, id if id: url = f"{url}{id}" - headers["id"] = id click.echo(f"\nRetrieving combiner: {url}\n") diff --git a/fedn/cli/model_cmd.py b/fedn/cli/model_cmd.py index 810b573ab..b5f738aad 100644 --- a/fedn/cli/model_cmd.py +++ b/fedn/cli/model_cmd.py @@ -43,7 +43,6 @@ def list_models(ctx, protocol: str, host: str, port: str, token: str = None, ses if session_id: url = f"{url}?session_id={session_id}" - headers["session_id"] = session_id click.echo(f"\nListing models: {url}\n") click.echo(f"Headers: {headers}") @@ -58,7 +57,7 @@ def list_models(ctx, protocol: str, host: str, port: str, token: str = None, ses @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=False, help="Model ID") +@click.option("-id", "--id", required=True, help="Model ID") @model_cmd.command("get") @click.pass_context def get_model(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): @@ -80,7 +79,6 @@ def get_model(ctx, protocol: str, host: str, port: str, token: str = None, id: s if id: url = f"{url}{id}" - headers["id"] = id click.echo(f"\nRetrieving model: {url}\n") click.echo(f"Headers: {headers}") diff --git a/fedn/cli/package_cmd.py b/fedn/cli/package_cmd.py index 30998b828..f34ea4a75 100644 --- a/fedn/cli/package_cmd.py +++ b/fedn/cli/package_cmd.py @@ -80,7 +80,7 @@ def list_packages(ctx, protocol: str, host: str, port: str, token: str = None, n @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=False, help="Package ID") +@click.option("-id", "--id", required=True, help="Package ID") @package_cmd.command("get") @click.pass_context def get_package(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): @@ -100,7 +100,6 @@ def get_package(ctx, protocol: str, host: str, port: str, token: str = None, id: if id: url = f"{url}{id}" - headers["id"] = id click.echo(f"\nretrieving package: {url}\n") diff --git a/fedn/cli/round_cmd.py b/fedn/cli/round_cmd.py index d60ff66e4..e790a8bdb 100644 --- a/fedn/cli/round_cmd.py +++ b/fedn/cli/round_cmd.py @@ -42,7 +42,6 @@ def list_rounds(ctx, protocol: str, host: str, port: str, token: str = None, ses if session_id: url = f"{url}?round_config.session_id={session_id}" - headers["session_id"] = session_id click.echo(f"\nListing rounds: {url}\n") click.echo(f"Headers: {headers}") @@ -57,7 +56,7 @@ def list_rounds(ctx, protocol: str, host: str, port: str, token: str = None, ses @click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") -@click.option("-id", "--id", required=False, help="Round ID") +@click.option("-id", "--id", required=True, help="Round ID") @click.option("-t", "--token", required=False, help="Authentication token") @round_cmd.command("get") @click.pass_context @@ -79,7 +78,6 @@ def get_round(ctx, protocol: str, host: str, port: str, token: str = None, id: s if id: url = f"{url}{id}" - headers["id"] = id click.echo(f"\nRetrieving round: {url}\n") diff --git a/fedn/cli/session_cmd.py b/fedn/cli/session_cmd.py index 65f45ac16..4cafa9e6b 100644 --- a/fedn/cli/session_cmd.py +++ b/fedn/cli/session_cmd.py @@ -71,7 +71,6 @@ def get_session(ctx, protocol: str, host: str, port: str, token: str = None, id: if id: url = f"{url}{id}" - headers["id"] = id click.echo(f"\nRetrieving session: {url}\n") diff --git a/fedn/cli/status_cmd.py b/fedn/cli/status_cmd.py index 5b445f07e..d47e4ab18 100644 --- a/fedn/cli/status_cmd.py +++ b/fedn/cli/status_cmd.py @@ -40,7 +40,6 @@ def list_statuses(ctx, protocol: str, host: str, port: str, token: str = None, s if session_id: url = f"{url}?sessionId={session_id}" - headers["session_id"] = session_id click.echo(f"\nListing statuses: {url}\n") @@ -56,7 +55,7 @@ def list_statuses(ctx, protocol: str, host: str, port: str, token: str = None, s @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=False, help="Status ID") +@click.option("-id", "--id", required=True, help="Status ID") @status_cmd.command("get") @click.pass_context def get_status(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): @@ -76,8 +75,6 @@ def get_status(ctx, protocol: str, host: str, port: str, token: str = None, id: if id: url = f"{url}{id}" - headers["id"] = id - click.echo(f"\nRetrieving status: {url}\n") click.echo(f"Headers: {headers}") diff --git a/fedn/cli/validation_cmd.py b/fedn/cli/validation_cmd.py index 10c594398..27ff8448d 100644 --- a/fedn/cli/validation_cmd.py +++ b/fedn/cli/validation_cmd.py @@ -41,7 +41,6 @@ def list_validations(ctx, protocol: str, host: str, port: str, token: str = None if session_id: url = f"{url}?sessionId={session_id}" - headers["session_id"] = session_id click.echo(f"\nListing validations: {url}\n") click.echo(f"Headers: {headers}") @@ -56,7 +55,7 @@ def list_validations(ctx, protocol: str, host: str, port: str, token: str = None @click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") @click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") @click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=False, help="validation ID") +@click.option("-id", "--id", required=True, help="validation ID") @validation_cmd.command("get") @click.pass_context def get_validation(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): @@ -75,7 +74,6 @@ def get_validation(ctx, protocol: str, host: str, port: str, token: str = None, if id: url = f"{url}{id}" - headers["id"] = id click.echo(f"\nRetrieving validation: {url}\n") From 282c81b7c2f537d5679dd6815d60f11f42951e0b Mon Sep 17 00:00:00 2001 From: KatHellg Date: Wed, 13 Nov 2024 15:43:01 +0100 Subject: [PATCH 08/11] spelling fix:) --- fedn/cli/package_cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fedn/cli/package_cmd.py b/fedn/cli/package_cmd.py index f34ea4a75..13eb582ea 100644 --- a/fedn/cli/package_cmd.py +++ b/fedn/cli/package_cmd.py @@ -102,7 +102,7 @@ def get_package(ctx, protocol: str, host: str, port: str, token: str = None, id: url = f"{url}{id}" - click.echo(f"\nretrieving package: {url}\n") + click.echo(f"\nRetrieving package: {url}\n") click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) From 2500829fc384c8bfaa7610299e5ef5412a0ac583 Mon Sep 17 00:00:00 2001 From: KatHellg Date: Wed, 13 Nov 2024 15:52:40 +0100 Subject: [PATCH 09/11] resolving conflict --- fedn/cli/client_cmd.py | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/fedn/cli/client_cmd.py b/fedn/cli/client_cmd.py index 073b6bb48..586b124ed 100644 --- a/fedn/cli/client_cmd.py +++ b/fedn/cli/client_cmd.py @@ -70,40 +70,6 @@ def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, n_ click.echo(f"Error: Could not connect to {url}") -@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") -@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") -@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") -@click.option("-t", "--token", required=False, help="Authentication token") -@click.option("-id", "--id", required=True, help="Client ID") -@client_cmd.command("get") -@click.pass_context -def get_client(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): - """Return: - ------ - - count: number of clients - - result: list of clients - - """ - url = get_api_url(protocol=protocol, host=host, port=port, endpoint="clients") - headers = {} - - _token = get_token(token) - - if _token: - headers["Authorization"] = _token - - if id: - url = f"{url}{id}" - - - click.echo(f"\nRetrieving client: {url}\n") - click.echo(f"Headers: {headers}") - try: - response = requests.get(url, headers=headers) - print_response(response, "client", id) - except requests.exceptions.ConnectionError: - click.echo(f"Error: Could not connect to {url}") - @client_cmd.command("start-v1") @click.option("-d", "--discoverhost", required=False, help="Hostname for discovery services(reducer).") @click.option("-p", "--discoverport", required=False, help="Port for discovery services (reducer).") From f2854687fdfcdd374af1c103e14a55246be7e3cb Mon Sep 17 00:00:00 2001 From: KatHellg Date: Wed, 13 Nov 2024 16:20:20 +0100 Subject: [PATCH 10/11] trying to add get_client function again --- fedn/cli/client_cmd.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/fedn/cli/client_cmd.py b/fedn/cli/client_cmd.py index 586b124ed..12a19c2ed 100644 --- a/fedn/cli/client_cmd.py +++ b/fedn/cli/client_cmd.py @@ -69,6 +69,40 @@ def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, n_ except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") +@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") +@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") +@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") +@click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=True, help="Client ID") +@client_cmd.command("get") +@click.pass_context +def get_client(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): + """Return: + ------ + - result: client with given id + + """ + url = get_api_url(protocol=protocol, host=host, port=port, endpoint="clients") + headers = {} + + + _token = get_token(token) + + if _token: + headers["Authorization"] = _token + + if id: + url = f"{url}{id}" + + + click.echo(f"\nRetrieving client: {url}\n") + click.echo(f"Headers: {headers}") + try: + response = requests.get(url, headers=headers) + print_response(response, "client", id) + except requests.exceptions.ConnectionError: + click.echo(f"Error: Could not connect to {url}") + @client_cmd.command("start-v1") @click.option("-d", "--discoverhost", required=False, help="Hostname for discovery services(reducer).") From 581cfbc7eb14f25fb03929c1c540f31fcd8509cb Mon Sep 17 00:00:00 2001 From: KatHellg Date: Fri, 15 Nov 2024 11:43:32 +0100 Subject: [PATCH 11/11] header prints removed --- fedn/cli/client_cmd.py | 4 ---- fedn/cli/combiner_cmd.py | 4 ---- fedn/cli/model_cmd.py | 6 ++---- fedn/cli/package_cmd.py | 4 ---- fedn/cli/round_cmd.py | 5 +---- fedn/cli/session_cmd.py | 4 ---- fedn/cli/shared.py | 2 +- fedn/cli/status_cmd.py | 5 +---- fedn/cli/validation_cmd.py | 5 +---- 9 files changed, 6 insertions(+), 33 deletions(-) diff --git a/fedn/cli/client_cmd.py b/fedn/cli/client_cmd.py index 12a19c2ed..7c9ffc1e7 100644 --- a/fedn/cli/client_cmd.py +++ b/fedn/cli/client_cmd.py @@ -60,8 +60,6 @@ def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, n_ if _token: headers["Authorization"] = _token - click.echo(f"\nListing clients: {url}\n") - click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) @@ -95,8 +93,6 @@ def get_client(ctx, protocol: str, host: str, port: str, token: str = None, id: url = f"{url}{id}" - click.echo(f"\nRetrieving client: {url}\n") - click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) print_response(response, "client", id) diff --git a/fedn/cli/combiner_cmd.py b/fedn/cli/combiner_cmd.py index c6ccbeb19..dd45fbd1b 100644 --- a/fedn/cli/combiner_cmd.py +++ b/fedn/cli/combiner_cmd.py @@ -89,8 +89,6 @@ def list_combiners(ctx, protocol: str, host: str, port: str, token: str = None, headers["Authorization"] = _token - click.echo(f"\nListing combiners: {url}\n") - click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) print_response(response, "combiners", None) @@ -124,8 +122,6 @@ def get_combiner(ctx, protocol: str, host: str, port: str, token: str = None, id url = f"{url}{id}" - click.echo(f"\nRetrieving combiner: {url}\n") - click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) print_response(response, "combiner", id) diff --git a/fedn/cli/model_cmd.py b/fedn/cli/model_cmd.py index b5f738aad..2e522e5a1 100644 --- a/fedn/cli/model_cmd.py +++ b/fedn/cli/model_cmd.py @@ -44,8 +44,7 @@ def list_models(ctx, protocol: str, host: str, port: str, token: str = None, ses if session_id: url = f"{url}?session_id={session_id}" - click.echo(f"\nListing models: {url}\n") - click.echo(f"Headers: {headers}") + try: response = requests.get(url, headers=headers) print_response(response, "models", None) @@ -80,8 +79,7 @@ def get_model(ctx, protocol: str, host: str, port: str, token: str = None, id: s if id: url = f"{url}{id}" - click.echo(f"\nRetrieving model: {url}\n") - click.echo(f"Headers: {headers}") + try: response = requests.get(url, headers=headers) print_response(response, "model", id) diff --git a/fedn/cli/package_cmd.py b/fedn/cli/package_cmd.py index 13eb582ea..b8a130f68 100644 --- a/fedn/cli/package_cmd.py +++ b/fedn/cli/package_cmd.py @@ -67,8 +67,6 @@ def list_packages(ctx, protocol: str, host: str, port: str, token: str = None, n headers["Authorization"] = _token - click.echo(f"\nListing packages: {url}\n") - click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) print_response(response, "packages", None) @@ -102,8 +100,6 @@ def get_package(ctx, protocol: str, host: str, port: str, token: str = None, id: url = f"{url}{id}" - click.echo(f"\nRetrieving package: {url}\n") - click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) print_response(response, "package", id) diff --git a/fedn/cli/round_cmd.py b/fedn/cli/round_cmd.py index e790a8bdb..2f889fef3 100644 --- a/fedn/cli/round_cmd.py +++ b/fedn/cli/round_cmd.py @@ -43,8 +43,7 @@ def list_rounds(ctx, protocol: str, host: str, port: str, token: str = None, ses if session_id: url = f"{url}?round_config.session_id={session_id}" - click.echo(f"\nListing rounds: {url}\n") - click.echo(f"Headers: {headers}") + try: response = requests.get(url, headers=headers) print_response(response, "rounds", None) @@ -80,8 +79,6 @@ def get_round(ctx, protocol: str, host: str, port: str, token: str = None, id: s url = f"{url}{id}" - click.echo(f"\nRetrieving round: {url}\n") - click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) print_response(response, "round", id) diff --git a/fedn/cli/session_cmd.py b/fedn/cli/session_cmd.py index 4cafa9e6b..a0f1e64c3 100644 --- a/fedn/cli/session_cmd.py +++ b/fedn/cli/session_cmd.py @@ -39,8 +39,6 @@ def list_sessions(ctx, protocol: str, host: str, port: str, token: str = None, n headers["Authorization"] = _token - click.echo(f"\nListing sessions: {url}\n") - click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) print_response(response, "sessions", None) @@ -73,8 +71,6 @@ def get_session(ctx, protocol: str, host: str, port: str, token: str = None, id: url = f"{url}{id}" - click.echo(f"\nRetrieving session: {url}\n") - click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) print_response(response, "session", id) diff --git a/fedn/cli/shared.py b/fedn/cli/shared.py index 5876828fb..21fa2b072 100644 --- a/fedn/cli/shared.py +++ b/fedn/cli/shared.py @@ -74,7 +74,7 @@ def print_response(response, entity_name: str, so): description: name of entity :param so: type: boolean - desriptions: single output format (y/n) + desriptions: single output format return: None """ if response.status_code == 200: diff --git a/fedn/cli/status_cmd.py b/fedn/cli/status_cmd.py index d47e4ab18..9b751f65b 100644 --- a/fedn/cli/status_cmd.py +++ b/fedn/cli/status_cmd.py @@ -42,8 +42,6 @@ def list_statuses(ctx, protocol: str, host: str, port: str, token: str = None, s url = f"{url}?sessionId={session_id}" - click.echo(f"\nListing statuses: {url}\n") - click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) print_response(response, "statuses", None) @@ -76,8 +74,7 @@ def get_status(ctx, protocol: str, host: str, port: str, token: str = None, id: if id: url = f"{url}{id}" - click.echo(f"\nRetrieving status: {url}\n") - click.echo(f"Headers: {headers}") + try: response = requests.get(url, headers=headers) print_response(response, "status", id) diff --git a/fedn/cli/validation_cmd.py b/fedn/cli/validation_cmd.py index 27ff8448d..b7417af5e 100644 --- a/fedn/cli/validation_cmd.py +++ b/fedn/cli/validation_cmd.py @@ -42,8 +42,7 @@ def list_validations(ctx, protocol: str, host: str, port: str, token: str = None if session_id: url = f"{url}?sessionId={session_id}" - click.echo(f"\nListing validations: {url}\n") - click.echo(f"Headers: {headers}") + try: response = requests.get(url, headers=headers) print_response(response, "validations", None) @@ -76,8 +75,6 @@ def get_validation(ctx, protocol: str, host: str, port: str, token: str = None, url = f"{url}{id}" - click.echo(f"\nRetrieving validation: {url}\n") - click.echo(f"Headers: {headers}") try: response = requests.get(url, headers=headers) print_response(response, "validation", id)