-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/SK-1127 | add session_id flag #742
base: master
Are you sure you want to change the base?
Changes from 3 commits
035f652
131e045
ef2543d
794a0b1
c83e928
7c24f1a
4a1d035
282c81b
2500829
f285468
581cfbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove print of hearder |
||
|
||
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}") | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
|
||
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}") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,36 @@ 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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
|
||
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}") | ||
elif 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}") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,26 +64,35 @@ 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 | ||
description: list of entities | ||
:param entity_name: | ||
type: string | ||
description: name of entity | ||
:param so: | ||
type: boolean | ||
desriptions: single output format (y/n) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove (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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should consider using json pretty prints instead, however I would prefer not introducing a new dependency. Save for other issue |
||
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"]}') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This header should not be needed.