def config_show(lib, argv, modifiers): """ Options: * -f - CIB file, when getting cluster name on remote node (corosync.conf doesn't exist) * --corosync_conf - corosync.conf file """ modifiers.ensure_only_supported("-f", "--corosync_conf") if argv: raise CmdLineInputError() print("Cluster Name: %s" % utils.getClusterName()) status.nodes_status(lib, ["config"], modifiers.get_subset("-f")) print() print("\n".join(_config_show_cib_lines(lib))) if (utils.hasCorosyncConf() and not modifiers.is_specified("-f") and not modifiers.is_specified("--corosync_conf")): cluster.cluster_uidgid(lib, [], modifiers.get_subset(), silent_list=True) if modifiers.is_specified("--corosync_conf") or utils.hasCorosyncConf(): print() print("Quorum:") try: config = lib_quorum.get_config(utils.get_lib_env()) print("\n".join(indent(quorum.quorum_config_to_str(config)))) except LibraryError as e: process_library_reports(e.args)
def config_show(argv): print("Cluster Name: %s" % utils.getClusterName()) status.nodes_status(["config"]) print() config_show_cib() if ( utils.hasCorosyncConf() and ( utils.is_rhel6() or (not utils.usefile and "--corosync_conf" not in utils.pcs_options) ) ): # with corosync 1 and cman, uid gid is part of cluster.conf file # with corosync 2, uid gid is in a separate directory cluster.cluster_uidgid([], True) if ( "--corosync_conf" in utils.pcs_options or (not utils.is_rhel6() and utils.hasCorosyncConf()) ): print() print("Quorum:") try: config = lib_quorum.get_config(utils.get_lib_env()) print("\n".join(indent(quorum.quorum_config_to_str(config)))) except LibraryError as e: utils.process_library_reports(e.args)
def full_status(): if "--hide-inactive" in utils.pcs_options and "--full" in utils.pcs_options: utils.err("you cannot specify both --hide-inactive and --full") monitor_command = ["crm_mon", "--one-shot"] if "--hide-inactive" not in utils.pcs_options: monitor_command.append('--inactive') if "--full" in utils.pcs_options: monitor_command.extend( ["--show-detail", "--show-node-attributes", "--failcounts"]) output, retval = utils.run(monitor_command) if (retval != 0): utils.err("cluster is not currently running on this node") if not utils.usefile or "--corosync_conf" in utils.pcs_options: cluster_name = utils.getClusterName() print("Cluster name: %s" % cluster_name) status_stonith_check() if (not utils.usefile and not utils.is_rhel6() and utils.corosyncPacemakerNodeCheck()): print( "WARNING: corosync and pacemaker node names do not match (IPs used in setup?)" ) print(output) if not utils.usefile: if "--full" in utils.pcs_options and utils.hasCorosyncConf(): print_pcsd_daemon_status() print() utils.serviceStatus(" ")
def cluster_status(lib, argv, modifiers): """ Options: * -f - CIB file * --request-timeout - HTTP timeout for checking status of pcsd, no effect if -f is specified """ modifiers.ensure_only_supported("-f", "--request-timeout") if argv: raise CmdLineInputError() (output, retval) = utils.run(["crm_mon", "-1", "-r"]) if retval != 0: utils.err("cluster is not currently running on this node") first_empty_line = False print("Cluster Status:") for line in output.splitlines(): if line == "": if first_empty_line: break first_empty_line = True continue print("", line) if not modifiers.is_specified("-f") and utils.hasCorosyncConf(): print() print_pcsd_daemon_status(lib, modifiers)
def config_show(lib, argv, modifiers): """ Options: * -f - CIB file, when getting cluster name on remote node (corosync.conf doesn't exist) * --corosync_conf - corosync.conf file """ modifiers.ensure_only_supported("-f", "--corosync_conf") if argv: raise CmdLineInputError() print("Cluster Name: %s" % utils.getClusterName()) status.nodes_status(lib, ["config"], modifiers.get_subset("-f")) print() print("\n".join(_config_show_cib_lines(lib))) if ( utils.hasCorosyncConf() and not modifiers.is_specified("-f") and not modifiers.is_specified("--corosync_conf") ): cluster.cluster_uidgid( lib, [], modifiers.get_subset(), silent_list=True ) if ( modifiers.is_specified("--corosync_conf") or utils.hasCorosyncConf() ): print() print("Quorum:") try: config = lib_quorum.get_config(utils.get_lib_env()) print("\n".join(indent(quorum.quorum_config_to_str(config)))) except LibraryError as e: utils.process_library_reports(e.args)
def stonith_level_verify(): dom = utils.get_cib_dom() corosync_nodes = [] if utils.hasCorosyncConf(): corosync_nodes = utils.getNodesFromCorosyncConf() pacemaker_nodes = utils.getNodesFromPacemaker() fls = dom.getElementsByTagName("fencing-level") for fl in fls: node = fl.getAttribute("target") devices = fl.getAttribute("devices") for dev in devices.split(","): if not utils.is_stonith_resource(dev): utils.err("%s is not a stonith id" % dev) if node not in corosync_nodes and node not in pacemaker_nodes: utils.err("%s is not currently a node" % node)
def stonith_level_add(level, node, devices): dom = utils.get_cib_dom() if not re.search(r'^\d+$', level) or re.search(r'^0+$', level): utils.err("invalid level '{0}', use a positive integer".format(level)) level = level.lstrip('0') if "--force" not in utils.pcs_options: for dev in devices.split(","): if not utils.is_stonith_resource(dev): utils.err("%s is not a stonith id (use --force to override)" % dev) corosync_nodes = [] if utils.hasCorosyncConf(): corosync_nodes = utils.getNodesFromCorosyncConf() pacemaker_nodes = utils.getNodesFromPacemaker() if node not in corosync_nodes and node not in pacemaker_nodes: utils.err("%s is not currently a node (use --force to override)" % node) ft = dom.getElementsByTagName("fencing-topology") if len(ft) == 0: conf = dom.getElementsByTagName("configuration")[0] ft = dom.createElement("fencing-topology") conf.appendChild(ft) else: ft = ft[0] fls = ft.getElementsByTagName("fencing-level") for fl in fls: if fl.getAttribute("target") == node and fl.getAttribute( "index") == level and fl.getAttribute("devices") == devices: utils.err( "unable to add fencing level, fencing level for node: %s, at level: %s, with device: %s already exists" % (node, level, devices)) new_fl = dom.createElement("fencing-level") ft.appendChild(new_fl) new_fl.setAttribute("target", node) new_fl.setAttribute("index", level) new_fl.setAttribute("devices", devices) new_fl.setAttribute("id", utils.find_unique_id(dom, "fl-" + node + "-" + level)) utils.replace_cib_configuration(dom)
def cluster_status(argv): (output, retval) = utils.run(["crm_mon", "-1", "-r"]) if (retval != 0): utils.err("cluster is not currently running on this node") first_empty_line = False print("Cluster Status:") for line in output.splitlines(): if line == "": if first_empty_line: break first_empty_line = True continue else: print("",line) if not utils.usefile and utils.hasCorosyncConf(): print() print_pcsd_daemon_status()
def cluster_status(argv): (output, retval) = utils.run(["crm_mon", "-1", "-r"]) if (retval != 0): utils.err("cluster is not currently running on this node") first_empty_line = False print("Cluster Status:") for line in output.splitlines(): if line == "": if first_empty_line: break first_empty_line = True continue else: print("", line) if not utils.usefile and utils.hasCorosyncConf(): print() print_pcsd_daemon_status()
def full_status(): if "--hide-inactive" in utils.pcs_options and "--full" in utils.pcs_options: utils.err("you cannot specify both --hide-inactive and --full") monitor_command = ["crm_mon", "--one-shot"] if "--hide-inactive" not in utils.pcs_options: monitor_command.append('--inactive') if "--full" in utils.pcs_options: monitor_command.extend( ["--show-detail", "--show-node-attributes", "--failcounts"] ) output, retval = utils.run(monitor_command) if (retval != 0): utils.err("cluster is not currently running on this node") if not utils.usefile or "--corosync_conf" in utils.pcs_options: cluster_name = utils.getClusterName() print("Cluster name: %s" % cluster_name) if utils.stonithCheck(): print("WARNING: no stonith devices and stonith-enabled is not false") if ( not utils.usefile and not utils.is_rhel6() and utils.corosyncPacemakerNodeCheck() ): print("WARNING: corosync and pacemaker node names do not match (IPs used in setup?)") print(output) if not utils.usefile: if "--full" in utils.pcs_options and utils.hasCorosyncConf(): print_pcsd_daemon_status() print() utils.serviceStatus(" ")
def stonith_level_add(level, node, devices): dom = utils.get_cib_dom() if not re.search(r'^\d+$', level) or re.search(r'^0+$', level): utils.err("invalid level '{0}', use a positive integer".format(level)) level = level.lstrip('0') if "--force" not in utils.pcs_options: for dev in devices.split(","): if not utils.is_stonith_resource(dev): utils.err("%s is not a stonith id (use --force to override)" % dev) corosync_nodes = [] if utils.hasCorosyncConf(): corosync_nodes = utils.getNodesFromCorosyncConf() pacemaker_nodes = utils.getNodesFromPacemaker() if node not in corosync_nodes and node not in pacemaker_nodes: utils.err("%s is not currently a node (use --force to override)" % node) ft = dom.getElementsByTagName("fencing-topology") if len(ft) == 0: conf = dom.getElementsByTagName("configuration")[0] ft = dom.createElement("fencing-topology") conf.appendChild(ft) else: ft = ft[0] fls = ft.getElementsByTagName("fencing-level") for fl in fls: if fl.getAttribute("target") == node and fl.getAttribute("index") == level and fl.getAttribute("devices") == devices: utils.err("unable to add fencing level, fencing level for node: %s, at level: %s, with device: %s already exists" % (node,level,devices)) new_fl = dom.createElement("fencing-level") ft.appendChild(new_fl) new_fl.setAttribute("target", node) new_fl.setAttribute("index", level) new_fl.setAttribute("devices", devices) new_fl.setAttribute("id", utils.find_unique_id(dom, "fl-" + node +"-" + level)) utils.replace_cib_configuration(dom)
def full_status(): if "--hide-inactive" in utils.pcs_options and "--full" in utils.pcs_options: utils.err("you cannot specify both --hide-inactive and --full") monitor_command = ["crm_mon", "--one-shot"] if "--hide-inactive" not in utils.pcs_options: monitor_command.append('--inactive') if "--full" in utils.pcs_options: monitor_command.extend( ["--show-detail", "--show-node-attributes", "--failcounts"]) output, retval = utils.run(monitor_command) if (retval != 0): utils.err("cluster is not currently running on this node") if not utils.usefile or "--corosync_conf" in utils.pcs_options: cluster_name = utils.getClusterName() print("Cluster name: %s" % cluster_name) status_stonith_check() print(output) if "--full" in utils.pcs_options: tickets, retval = utils.run(["crm_ticket", "-L"]) if retval != 0: print("WARNING: Unable to get information about tickets") print() elif tickets: print("Tickets:") print("\n".join(indent(tickets.split("\n")))) if not utils.usefile: if "--full" in utils.pcs_options and utils.hasCorosyncConf(): print_pcsd_daemon_status() print() utils.serviceStatus(" ")
def nodes_status(lib, argv, modifiers): """ Options: * -f - CIB file - for config subcommand and not for both or corosync * --corosync_conf - only for config subcommand NOTE: modifiers check is in subcommand """ del lib if len(argv) == 1 and (argv[0] == "config"): modifiers.ensure_only_supported("-f", "--corosync_conf") if utils.hasCorosyncConf(): corosync_nodes, report_list = get_existing_nodes_names( utils.get_corosync_conf_facade()) if report_list: process_library_reports(report_list) else: corosync_nodes = [] try: pacemaker_nodes = sorted([ node.attrs.name for node in ClusterState( get_cluster_status_dom( utils.cmd_runner())).node_section.nodes if node.attrs.type != "remote" ]) except LibraryError as e: process_library_reports(e.args) print("Corosync Nodes:") if corosync_nodes: print(" " + " ".join(corosync_nodes)) print("Pacemaker Nodes:") if pacemaker_nodes: print(" " + " ".join(pacemaker_nodes)) return if len(argv) == 1 and (argv[0] == "corosync" or argv[0] == "both"): modifiers.ensure_only_supported() all_nodes, report_list = get_existing_nodes_names( utils.get_corosync_conf_facade()) if report_list: process_library_reports(report_list) online_nodes = utils.getCorosyncActiveNodes() offline_nodes = [] for node in all_nodes: if node not in online_nodes: offline_nodes.append(node) online_nodes.sort() offline_nodes.sort() print("Corosync Nodes:") print(" ".join([" Online:"] + online_nodes)) print(" ".join([" Offline:"] + offline_nodes)) if argv[0] != "both": sys.exit(0) modifiers.ensure_only_supported("-f") info_dom = utils.getClusterState() nodes = info_dom.getElementsByTagName("nodes") if nodes.length == 0: utils.err("No nodes section found") onlinenodes = [] offlinenodes = [] standbynodes = [] standbynodes_with_resources = [] maintenancenodes = [] remote_onlinenodes = [] remote_offlinenodes = [] remote_standbynodes = [] remote_standbynodes_with_resources = [] remote_maintenancenodes = [] for node in nodes[0].getElementsByTagName("node"): node_name = node.getAttribute("name") node_remote = node.getAttribute("type") == "remote" if node.getAttribute("online") == "true": if node.getAttribute("standby") == "true": is_running_resources = (node.getAttribute("resources_running") != "0") if node_remote: if is_running_resources: remote_standbynodes_with_resources.append(node_name) else: remote_standbynodes.append(node_name) else: if is_running_resources: standbynodes_with_resources.append(node_name) else: standbynodes.append(node_name) if node.getAttribute("maintenance") == "true": if node_remote: remote_maintenancenodes.append(node_name) else: maintenancenodes.append(node_name) if (node.getAttribute("standby") == "false" and node.getAttribute("maintenance") == "false"): if node_remote: remote_onlinenodes.append(node_name) else: onlinenodes.append(node_name) else: if node_remote: remote_offlinenodes.append(node_name) else: offlinenodes.append(node_name) print("Pacemaker Nodes:") print(" ".join([" Online:"] + onlinenodes)) print(" ".join([" Standby:"] + standbynodes)) print(" ".join([" Standby with resource(s) running:"] + standbynodes_with_resources)) print(" ".join([" Maintenance:"] + maintenancenodes)) print(" ".join([" Offline:"] + offlinenodes)) print("Pacemaker Remote Nodes:") print(" ".join([" Online:"] + remote_onlinenodes)) print(" ".join([" Standby:"] + remote_standbynodes)) print(" ".join([" Standby with resource(s) running:"] + remote_standbynodes_with_resources)) print(" ".join([" Maintenance:"] + remote_maintenancenodes)) print(" ".join([" Offline:"] + remote_offlinenodes))
def nodes_status(argv): if len(argv) == 1 and argv[0] == "pacemaker-id": for node_id, node_name in utils.getPacemakerNodesID().items(): print("{0} {1}".format(node_id, node_name)) return if len(argv) == 1 and argv[0] == "corosync-id": for node_id, node_name in utils.getCorosyncNodesID().items(): print("{0} {1}".format(node_id, node_name)) return if len(argv) == 1 and (argv[0] == "config"): if utils.hasCorosyncConf(): corosync_nodes = utils.getNodesFromCorosyncConf() else: corosync_nodes = [] try: pacemaker_nodes = sorted([ node.attrs.name for node in ClusterState(utils.getClusterStateXml()).node_section.nodes if node.attrs.type != 'remote' ]) except LibraryError as e: utils.process_library_reports(e.args) print("Corosync Nodes:") if corosync_nodes: print(" " + " ".join(corosync_nodes)) print("Pacemaker Nodes:") if pacemaker_nodes: print(" " + " ".join(pacemaker_nodes)) return if len(argv) == 1 and (argv[0] == "corosync" or argv[0] == "both"): all_nodes = utils.getNodesFromCorosyncConf() online_nodes = utils.getCorosyncActiveNodes() offline_nodes = [] for node in all_nodes: if node not in online_nodes: offline_nodes.append(node) online_nodes.sort() offline_nodes.sort() print("Corosync Nodes:") print(" ".join([" Online:"] + online_nodes)) print(" ".join([" Offline:"] + offline_nodes)) if argv[0] != "both": sys.exit(0) info_dom = utils.getClusterState() nodes = info_dom.getElementsByTagName("nodes") if nodes.length == 0: utils.err("No nodes section found") onlinenodes = [] offlinenodes = [] standbynodes = [] maintenancenodes = [] remote_onlinenodes = [] remote_offlinenodes = [] remote_standbynodes = [] remote_maintenancenodes = [] for node in nodes[0].getElementsByTagName("node"): node_name = node.getAttribute("name") node_remote = node.getAttribute("type") == "remote" if node.getAttribute("online") == "true": if node.getAttribute("standby") == "true": if node_remote: remote_standbynodes.append(node_name) else: standbynodes.append(node_name) elif node.getAttribute("maintenance") == "true": if node_remote: remote_maintenancenodes.append(node_name) else: maintenancenodes.append(node_name) else: if node_remote: remote_onlinenodes.append(node_name) else: onlinenodes.append(node_name) else: if node_remote: remote_offlinenodes.append(node_name) else: offlinenodes.append(node_name) print("Pacemaker Nodes:") print(" ".join([" Online:"] + onlinenodes)) print(" ".join([" Standby:"] + standbynodes)) print(" ".join([" Maintenance:"] + maintenancenodes)) print(" ".join([" Offline:"] + offlinenodes)) print("Pacemaker Remote Nodes:") print(" ".join([" Online:"] + remote_onlinenodes)) print(" ".join([" Standby:"] + remote_standbynodes)) print(" ".join([" Maintenance:"] + remote_maintenancenodes)) print(" ".join([" Offline:"] + remote_offlinenodes))
def nodes_status(argv): if len(argv) == 1 and (argv[0] == "config"): if utils.hasCorosyncConf(): corosync_nodes = utils.get_corosync_conf_facade().get_nodes_names() else: corosync_nodes = [] try: pacemaker_nodes = sorted([ node.attrs.name for node in ClusterState( utils.getClusterStateXml()).node_section.nodes if node.attrs.type != 'remote' ]) except LibraryError as e: utils.process_library_reports(e.args) print("Corosync Nodes:") if corosync_nodes: print(" " + " ".join(corosync_nodes)) print("Pacemaker Nodes:") if pacemaker_nodes: print(" " + " ".join(pacemaker_nodes)) return if len(argv) == 1 and (argv[0] == "corosync" or argv[0] == "both"): all_nodes = utils.get_corosync_conf_facade().get_nodes_names() online_nodes = utils.getCorosyncActiveNodes() offline_nodes = [] for node in all_nodes: if node not in online_nodes: offline_nodes.append(node) online_nodes.sort() offline_nodes.sort() print("Corosync Nodes:") print(" ".join([" Online:"] + online_nodes)) print(" ".join([" Offline:"] + offline_nodes)) if argv[0] != "both": sys.exit(0) info_dom = utils.getClusterState() nodes = info_dom.getElementsByTagName("nodes") if nodes.length == 0: utils.err("No nodes section found") onlinenodes = [] offlinenodes = [] standbynodes = [] maintenancenodes = [] remote_onlinenodes = [] remote_offlinenodes = [] remote_standbynodes = [] remote_maintenancenodes = [] for node in nodes[0].getElementsByTagName("node"): node_name = node.getAttribute("name") node_remote = node.getAttribute("type") == "remote" if node.getAttribute("online") == "true": if node.getAttribute("standby") == "true": if node_remote: remote_standbynodes.append(node_name) else: standbynodes.append(node_name) elif node.getAttribute("maintenance") == "true": if node_remote: remote_maintenancenodes.append(node_name) else: maintenancenodes.append(node_name) else: if node_remote: remote_onlinenodes.append(node_name) else: onlinenodes.append(node_name) else: if node_remote: remote_offlinenodes.append(node_name) else: offlinenodes.append(node_name) print("Pacemaker Nodes:") print(" ".join([" Online:"] + onlinenodes)) print(" ".join([" Standby:"] + standbynodes)) print(" ".join([" Maintenance:"] + maintenancenodes)) print(" ".join([" Offline:"] + offlinenodes)) print("Pacemaker Remote Nodes:") print(" ".join([" Online:"] + remote_onlinenodes)) print(" ".join([" Standby:"] + remote_standbynodes)) print(" ".join([" Maintenance:"] + remote_maintenancenodes)) print(" ".join([" Offline:"] + remote_offlinenodes))