Allow ack/delete of multiple faults at once

This commit is contained in:
Joshua Boniface 2023-12-09 17:28:13 -05:00
parent b0557edb76
commit fc443a323b
2 changed files with 40 additions and 20 deletions

View File

@ -538,14 +538,15 @@ def cli_cluster_fault_list(limit, format_function):
name="ack",
short_help="Acknowledge a cluster fault.",
)
@click.argument("fault_id")
@click.argument("fault_id", nargs=-1)
@connection_req
def cli_cluster_fault_acknowledge(fault_id):
"""
Acknowledge the cluster fault FAULT_ID.
Acknowledge the cluster fault FAULT_ID; multiple FAULT_IDs may be specified.
"""
retcode, retdata = pvc.lib.faults.acknowledge(CLI_CONFIG, fault_id)
faults = list(fault_id)
retcode, retdata = pvc.lib.faults.acknowledge(CLI_CONFIG, faults)
finish(retcode, retdata)
@ -574,14 +575,15 @@ def cli_cluster_fault_acknowledge_all():
name="delete",
short_help="Delete a cluster fault.",
)
@click.argument("fault_id")
@click.argument("fault_id", nargs=-1)
@connection_req
def cli_cluster_fault_delete(fault_id):
"""
Delete the cluster fault FAULT_ID.
Delete the cluster fault FAULT_ID; multiple FAULT_IDs may be specified.
"""
retcode, retdata = pvc.lib.faults.delete(CLI_CONFIG, fault_id)
faults = list(fault_id)
retcode, retdata = pvc.lib.faults.delete(CLI_CONFIG, faults)
finish(retcode, retdata)

View File

@ -45,20 +45,29 @@ def get_list(config, limit=None, sort_key="last_reported"):
return False, response.json().get("message", "")
def acknowledge(config, fault_id):
def acknowledge(config, faults):
"""
Acknowledge a PVC fault
Acknowledge one or more PVC faults
API endpoint: PUT /api/v1/faults/<fault_id>
API endpoint: PUT /api/v1/faults/<fault_id> for fault_id in faults
API arguments:
API schema: {json_message}
"""
response = call_api(config, "put", f"/faults/{fault_id}")
status_codes = list()
bad_msgs = list()
for fault_id in faults:
response = call_api(config, "put", f"/faults/{fault_id}")
if response.status_code == 200:
return True, response.json().get("message", "")
if response.status_code == 200:
status_codes.append(True)
else:
status_codes.append(False)
bad_msgs.append(response.json().get("message", ""))
if all(status_codes):
return True, f"Successfully acknowledged fault(s) {', '.join(faults)}"
else:
return False, response.json().get("message", "")
return False, ", ".join(bad_msgs)
def acknowledge_all(config):
@ -77,20 +86,29 @@ def acknowledge_all(config):
return False, response.json().get("message", "")
def delete(config, fault_id):
def delete(config, faults):
"""
Delete a PVC fault
Delete one or more PVC faults
API endpoint: DELETE /api/v1/faults/<fault_id>
API endpoint: DELETE /api/v1/faults/<fault_id> for fault_id in faults
API arguments:
API schema: {json_message}
"""
response = call_api(config, "delete", f"/faults/{fault_id}")
status_codes = list()
bad_msgs = list()
for fault_id in faults:
response = call_api(config, "delete", f"/faults/{fault_id}")
if response.status_code == 200:
return True, response.json().get("message", "")
if response.status_code == 200:
status_codes.append(True)
else:
status_codes.append(False)
bad_msgs.append(response.json().get("message", ""))
if all(status_codes):
return True, f"Successfully deleted fault(s) {', '.join(faults)}"
else:
return False, response.json().get("message", "")
return False, ", ".join(bad_msgs)
def delete_all(config):