Skip to content

Commit

Permalink
list models v1
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Mar 6, 2024
1 parent cf91189 commit 7047ae4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 22 deletions.
42 changes: 40 additions & 2 deletions fedn/cli/list_cmd.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@


import click
import requests

from .main import main
from .shared import API_VERSION, CONTROLLER_DEFAULTS


def print_response(response, entity_name: str):
"""
:param response:
:return:
"""
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():
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}')

@main.group('list')
@click.pass_context
Expand All @@ -13,9 +37,23 @@ def list_cmd(ctx):
pass


@click.option('-h', '--host', required=False, default=CONTROLLER_DEFAULTS['host'], help='Hostname of controller (api).')
@click.option('-i', '--port', required=False, default=CONTROLLER_DEFAULTS['port'], help='Port of controller (api).')
@click.option('--n_max', required=False, help='Number of items to list.')
@list_cmd.command('models')
def list_models():
@click.pass_context
def list_models(ctx, host, port, n_max):
"""
:return:
"""
click.echo('Listing models')
url = f'http://{host}:{port}/api/{API_VERSION}/models'
headers = {}

if n_max:
headers['X-Limit'] = n_max

click.echo(f'\nListing models: {url}\n')

response = requests.get(url, headers=headers)

print_response(response, 'models')
21 changes: 1 addition & 20 deletions fedn/cli/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,7 @@
from fedn.network.combiner.combiner import Combiner

from .main import main

CONTROLLER_DEFAULTS = {
'host': 'localhost',
'port': 8092,
'debug': False
}

COMBINER_DEFAULTS = {
'discover_host': 'localhost',
'discover_port': 8092,
'host': 'localhost',
'port': 12080,
"name": "combiner",
"max_clients": 30
}

CLIENT_DEFAULTS = {
'discover_host': 'localhost',
'discover_port': 8092,
}
from .shared import CLIENT_DEFAULTS, COMBINER_DEFAULTS, CONTROLLER_DEFAULTS


def get_statestore_config_from_file(init):
Expand Down
21 changes: 21 additions & 0 deletions fedn/cli/shared.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CONTROLLER_DEFAULTS = {
'host': 'localhost',
'port': 8092,
'debug': False
}

COMBINER_DEFAULTS = {
'discover_host': 'localhost',
'discover_port': 8092,
'host': 'localhost',
'port': 12080,
"name": "combiner",
"max_clients": 30
}

CLIENT_DEFAULTS = {
'discover_host': 'localhost',
'discover_port': 8092,
}

API_VERSION = 'v1'

0 comments on commit 7047ae4

Please sign in to comment.