Skip to content

Commit

Permalink
feat(cli): Add findfast command for /node/fast search
Browse files Browse the repository at this point in the history
We have fast, non-paginated search, implement CLI function
to test it.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
  • Loading branch information
nuclearcat committed Dec 4, 2024
1 parent 2ffaf6d commit d1ec961
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions kernelci/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def _get(self, path, params=None):
session.mount('http://', adapter)
session.mount('https://', adapter)

print(url, params)
resp = session.get(
url, params=params, headers=self.data.headers,
timeout=self.data.timeout
Expand Down Expand Up @@ -208,6 +209,11 @@ def _get_paginated(self, input_params, path, offset=None, limit=None):
offset += limit
return objs

def _get_fast(self, input_params, path):
params = input_params.copy()
resp = self._get(path, params=params)
return resp.json()

def _delete(self, path):
url = self.make_url(path)
retry_strategy = Retry(
Expand Down
6 changes: 6 additions & 0 deletions kernelci/api/latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ def find(
params = attributes.copy() if attributes else {}
return self._get_paginated(params, 'nodes', offset, limit)

def findfast(
self, attributes: Dict[str, str],
) -> dict:
params = attributes.copy() if attributes else {}
return self._get_fast(params, 'nodes/fast')

def count(self, attributes: dict) -> int:
return self._get('count', params=attributes).json()

Expand Down
16 changes: 16 additions & 0 deletions kernelci/cli/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ def find(attributes, config, api, indent, page_length, page_number):
echo(data)


@kci_node.command
@click.argument('attributes', nargs=-1)
@Args.config
@Args.api
@Args.indent
@catch_error
# pylint: disable=too-many-arguments
def findfast(attributes, config, api, indent):
"""Find nodes with arbitrary attributes"""
api = get_api(config, api)
attributes = split_attributes(attributes)
nodes = api.node.findfast(attributes)
data = json.dumps(nodes, indent=indent or None)
click.echo(data)


@kci_node.command
@click.argument('attributes', nargs=-1)
@Args.config
Expand Down

0 comments on commit d1ec961

Please sign in to comment.