Skip to content

Commit

Permalink
maestro_results: return parsable json
Browse files Browse the repository at this point in the history
By returning a json, we can immediatelly parse it in the
cmdline with 'jq'. That will help our scripting.

Ideally we would have a --json for this, but we can change this
later as kci-dev didn't reach 1.0 yet.

Suggested-by:Manu Bretelle <[email protected]>
Signed-off-by: Gustavo Padovan <[email protected]>
  • Loading branch information
padovan committed Jan 16, 2025
1 parent fab5ef9 commit 7a96125
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions kcidev/subcommands/maestro_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@


def print_nodes(nodes, field):
res = []
if not isinstance(nodes, list):
nodes = [nodes]
for node in nodes:
if field:
data = {}
for f in field:
data[f] = node.get(f)
click.secho(pprint.pprint(data), fg="green", nl=False)
res.append(data)
else:
click.secho(pprint.pprint(node), fg="green", nl=False)
res.append(node)
kci_msg(json.dumps(res, sort_keys=True, indent=4))


def get_node(url, nodeid, field):
headers = {
"Content-Type": "application/json; charset=utf-8",
}
url = url + "latest/node/" + nodeid
maestro_print_api_call(url)
response = requests.get(url, headers=headers)
try:
response.raise_for_status()
Expand All @@ -55,7 +56,6 @@ def get_nodes(url, limit, offset, filter, field):
# if we need anything more complex than eq(=)
url = url + "&" + f

maestro_print_api_call(url)
response = requests.get(url, headers=headers)
try:
response.raise_for_status()
Expand Down

0 comments on commit 7a96125

Please sign in to comment.