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}")