Merge "Add formatting function and apply to deploy state"

This commit is contained in:
Zuul 2024-06-19 19:36:07 +00:00 committed by Gerrit Code Review
commit f84a382b0c
2 changed files with 13 additions and 0 deletions

View File

@ -157,6 +157,18 @@ def _display_error(status_code, text):
print(HTTP_ERRORS[status_code])
def format_data(data, header, format_func):
"""
Format data applying a formatting function to all values under specified header
:param data: list of dict with the data
:param header: string with the header of the data that must be formatted
:param format_func: function to be applied to change the value
"""
for d in data:
if header in d:
d[header] = format_func(d[header])
def display_info(resp):
'''
This function displays basic REST API return, w/ info json object:

View File

@ -34,6 +34,7 @@ def do_show(cc, args):
"To Release": "to_release",
"RR": "reboot_required",
"State": "state"}
utils.format_data(data, header="state", format_func=lambda x: f"deploy-{x}")
utils.display_result_list(header_data_list, data)
else:
utils.display_info(resp)