def run(self, args): out = execute_in_peers("node-status") table = PrettyTable( ["NODE", "NODE STATUS", "MOUNT ROOT", "GROUP", "USERS"]) table.align["NODE STATUS"] = "r" for p in out: node_data = p.output if node_data == "": node_data = {} users_row_data = "" for k, v in node_data.get("users", {}).items(): users_row_data += "{0}({1}) ".format(k, ", ".join(v)) if not users_row_data: users_row_data = "None" mount_root = node_data.get("mountbroker-root", "None") if mount_root != "None": mount_root += "({0})".format( oknotok(node_data.get("path_exists", False))) grp = node_data.get("geo-replication-log-group", "None") if grp != "None": grp += "({0})".format( oknotok(node_data.get("group_exists", False))) table.add_row([ p.hostname, "UP" if p.node_up else "DOWN", mount_root, grp, users_row_data ]) print(table)
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 run(self, args): url = args.url bearer_token = args.bearer_token if not args.url: url = "." if not args.bearer_token: bearer_token = "." out = execute_in_peers("node-webhook-test", [url, bearer_token]) if not args.json: table = PrettyTable(["NODE", "NODE STATUS", "WEBHOOK STATUS"]) table.align["NODE STATUS"] = "r" table.align["WEBHOOK STATUS"] = "r" num_ok_rows = 0 json_out = [] if args.json: num_ok_rows = rows_to_json(json_out, "webhook_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) sys.exit(ret)
def run(self, args): out = execute_in_peers("node-setup", [args.mount_root, args.group]) table = PrettyTable(["NODE", "NODE STATUS", "SETUP STATUS"]) table.align["NODE STATUS"] = "r" table.align["SETUP 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 run(self, args): out = execute_in_peers("node-remove", [args.volume, args.user]) table = PrettyTable(["NODE", "NODE STATUS", "REMOVE STATUS"]) table.align["NODE STATUS"] = "r" table.align["REMOVE 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)
def action_handle(action, json_output=False): out = execute_in_peers("node-" + action) column_name = action.upper() if action == "status": column_name = EVENTSD.upper() if not json_output: table = PrettyTable(["NODE", "NODE STATUS", column_name + " STATUS"]) table.align["NODE STATUS"] = "r" table.align[column_name + " STATUS"] = "r" json_out = [] if json_output: rows_to_json(json_out, column_name.lower() + "_status", out) else: rows_to_table(table, out) return json_out if json_output else table
def run(self, args): url = args.url bearer_token = args.bearer_token secret = args.secret if not args.url: url = "." if not args.bearer_token: bearer_token = "." if not args.secret: secret = "." out = execute_in_peers("node-webhook-test", [url, bearer_token, secret]) if not args.json: table = PrettyTable(["NODE", "NODE STATUS", "WEBHOOK STATUS"]) table.align["NODE STATUS"] = "r" table.align["WEBHOOK STATUS"] = "r" num_ok_rows = 0 json_out = [] if args.json: num_ok_rows = rows_to_json(json_out, "webhook_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) sys.exit(ret)
def run(self, args): url = args.url bearer_token = args.bearer_token if not args.url: url = "." if not args.bearer_token: bearer_token = "." out = execute_in_peers("node-webhook-test", [url, bearer_token]) table = PrettyTable(["NODE", "NODE STATUS", "WEBHOOK STATUS"]) table.align["NODE STATUS"] = "r" table.align["WEBHOOK 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 action_handle(action): out = execute_in_peers("node-" + action) column_name = action.upper() if action == "status": column_name = EVENTSD.upper() table = PrettyTable(["NODE", "NODE STATUS", column_name + " STATUS"]) table.align["NODE STATUS"] = "r" table.align[column_name + " STATUS"] = "r" for p in out: status_col_val = "OK" if p.ok else "NOT OK: {0}".format(p.error) if action == "status": status_col_val = "DOWN" if p.ok: status_col_val = p.output table.add_row( [p.hostname, "UP" if p.node_up else "DOWN", status_col_val]) print(table)
def run(self, args): url = args.url bearer_token = args.bearer_token if not args.url: url = "." if not args.bearer_token: bearer_token = "." out = execute_in_peers("node-webhook-test", [url, bearer_token]) table = PrettyTable(["NODE", "NODE STATUS", "WEBHOOK STATUS"]) table.align["NODE STATUS"] = "r" table.align["WEBHOOK 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 run(self, args): prefix = "no-prefix" if args.no_prefix else "." out = execute_in_peers("node-generate", [prefix]) common_secrets = [] table = PrettyTable(["NODE", "NODE STATUS", "KEYGEN STATUS"]) table.align["NODE STATUS"] = "r" table.align["KEYGEN STATUS"] = "r" for p in out: if p.ok: common_secrets.append(p.output["default_pub"]) common_secrets.append(p.output["tar_pub"]) table.add_row([ p.hostname, "UP" if p.node_up else "DOWN", "OK" if p.ok else "NOT OK: {0}".format(p.error) ]) with open(COMMON_SECRET_FILE, "w") as f: f.write("\n".join(common_secrets) + "\n") print(table)
def action_handle(action): out = execute_in_peers("node-" + action) column_name = action.upper() if action == "status": column_name = EVENTSD.upper() table = PrettyTable(["NODE", "NODE STATUS", column_name + " STATUS"]) table.align["NODE STATUS"] = "r" table.align[column_name + " STATUS"] = "r" for p in out: status_col_val = "OK" if p.ok else "NOT OK: {0}".format( p.error) if action == "status": status_col_val = "DOWN" if p.ok: status_col_val = p.output table.add_row([p.hostname, "UP" if p.node_up else "DOWN", status_col_val]) print (table)