def sync_to_peers(restart=False): if os.path.exists(WEBHOOKS_FILE): try: sync_file_to_peers(WEBHOOKS_FILE_TO_SYNC) except GlusterCmdException as e: output_error("Failed to sync Webhooks file: [Error: {0}]" "{1}".format(e[0], e[2])) if os.path.exists(CUSTOM_CONFIG_FILE): try: sync_file_to_peers(CUSTOM_CONFIG_FILE_TO_SYNC) except GlusterCmdException as e: output_error("Failed to sync Config file: [Error: {0}]" "{1}".format(e[0], e[2])) action = "node-reload" if restart: action = "node-restart" out = execute_in_peers(action) table = PrettyTable(["NODE", "NODE STATUS", "SYNC STATUS"]) table.align["NODE STATUS"] = "r" table.align["SYNC STATUS"] = "r" for p in out: table.add_row([ p.hostname, "UP" if p.node_up else "DOWN", "OK" if p.ok else "NOT OK: {0}".format(p.error) ]) print(table)
def sync_to_peers(): if os.path.exists(WEBHOOKS_FILE): try: sync_file_to_peers(WEBHOOKS_FILE_TO_SYNC) except GlusterCmdException as e: output_error("Failed to sync Webhooks file: [Error: {0}]" "{1}".format(e[0], e[2])) if os.path.exists(CUSTOM_CONFIG_FILE): try: sync_file_to_peers(CUSTOM_CONFIG_FILE_TO_SYNC) except GlusterCmdException as e: output_error("Failed to sync Config file: [Error: {0}]" "{1}".format(e[0], e[2])) out = execute_in_peers("node-reload") table = PrettyTable(["NODE", "NODE STATUS", "SYNC STATUS"]) table.align["NODE STATUS"] = "r" table.align["SYNC STATUS"] = "r" for p in out: table.add_row([p.hostname, "UP" if p.node_up else "DOWN", "OK" if p.ok else "NOT OK: {0}".format( p.error)]) print (table)
def sync_to_peers(args): if os.path.exists(WEBHOOKS_FILE): try: sync_file_to_peers(WEBHOOKS_FILE_TO_SYNC) except GlusterCmdException as e: # Print stdout if stderr is empty errmsg = e.message[2] if e.message[2] else e.message[1] handle_output_error("Failed to sync Webhooks file: [Error: {0}]" "{1}".format(e.message[0], errmsg), errcode=ERROR_WEBHOOK_SYNC_FAILED, json_output=args.json) if os.path.exists(CUSTOM_CONFIG_FILE): try: sync_file_to_peers(CUSTOM_CONFIG_FILE_TO_SYNC) except GlusterCmdException as e: # Print stdout if stderr is empty errmsg = e.message[2] if e.message[2] else e.message[1] handle_output_error("Failed to sync Config file: [Error: {0}]" "{1}".format(e.message[0], errmsg), errcode=ERROR_CONFIG_SYNC_FAILED, json_output=args.json) out = execute_in_peers("node-reload") if not args.json: table = PrettyTable(["NODE", "NODE STATUS", "SYNC STATUS"]) table.align["NODE STATUS"] = "r" table.align["SYNC STATUS"] = "r" json_out = [] if args.json: num_ok_rows = rows_to_json(json_out, "sync_status", out) else: num_ok_rows = rows_to_table(table, out) ret = 0 if num_ok_rows == 0: ret = ERROR_ALL_NODES_STATUS_NOT_OK elif num_ok_rows != len(out): ret = ERROR_PARTIAL_SUCCESS if args.json: print (json.dumps({ "output": json_out, "error": "" })) else: print (table) # If sync status is not ok for any node set error code as partial success sys.exit(ret)