Allow ack/delete of multiple faults at once
This commit is contained in:
parent
b0557edb76
commit
fc443a323b
|
@ -538,14 +538,15 @@ def cli_cluster_fault_list(limit, format_function):
|
||||||
name="ack",
|
name="ack",
|
||||||
short_help="Acknowledge a cluster fault.",
|
short_help="Acknowledge a cluster fault.",
|
||||||
)
|
)
|
||||||
@click.argument("fault_id")
|
@click.argument("fault_id", nargs=-1)
|
||||||
@connection_req
|
@connection_req
|
||||||
def cli_cluster_fault_acknowledge(fault_id):
|
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)
|
finish(retcode, retdata)
|
||||||
|
|
||||||
|
|
||||||
|
@ -574,14 +575,15 @@ def cli_cluster_fault_acknowledge_all():
|
||||||
name="delete",
|
name="delete",
|
||||||
short_help="Delete a cluster fault.",
|
short_help="Delete a cluster fault.",
|
||||||
)
|
)
|
||||||
@click.argument("fault_id")
|
@click.argument("fault_id", nargs=-1)
|
||||||
@connection_req
|
@connection_req
|
||||||
def cli_cluster_fault_delete(fault_id):
|
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)
|
finish(retcode, retdata)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,20 +45,29 @@ def get_list(config, limit=None, sort_key="last_reported"):
|
||||||
return False, response.json().get("message", "")
|
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 arguments:
|
||||||
API schema: {json_message}
|
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:
|
if response.status_code == 200:
|
||||||
return True, response.json().get("message", "")
|
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:
|
else:
|
||||||
return False, response.json().get("message", "")
|
return False, ", ".join(bad_msgs)
|
||||||
|
|
||||||
|
|
||||||
def acknowledge_all(config):
|
def acknowledge_all(config):
|
||||||
|
@ -77,20 +86,29 @@ def acknowledge_all(config):
|
||||||
return False, response.json().get("message", "")
|
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 arguments:
|
||||||
API schema: {json_message}
|
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:
|
if response.status_code == 200:
|
||||||
return True, response.json().get("message", "")
|
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:
|
else:
|
||||||
return False, response.json().get("message", "")
|
return False, ", ".join(bad_msgs)
|
||||||
|
|
||||||
|
|
||||||
def delete_all(config):
|
def delete_all(config):
|
||||||
|
|
Loading…
Reference in New Issue