def show_acl_config(lib, argv, modifiers): """ Options: * -f - CIB file """ # TODO move to lib once lib supports cluster properties # enabled/disabled should be part of the structure returned # by lib.acl.get_config modifiers.ensure_only_supported("-f") if argv: raise CmdLineInputError() properties = utils.get_set_properties( defaults=prop.get_default_properties() ) acl_enabled = properties.get("enable-acl", "").lower() if is_true(acl_enabled): print("ACLs are enabled") else: print("ACLs are disabled, run 'pcs acl enable' to enable") print() data = lib.acl.get_config() _print_list_of_objects(data.get("target_list", []), target_to_str) _print_list_of_objects(data.get("group_list", []), group_to_str) _print_list_of_objects(data.get("role_list", []), role_to_str)
def list_property(argv): print_all = len(argv) == 0 if "--all" in utils.pcs_options and "--defaults" in utils.pcs_options: utils.err("you cannot specify both --all and --defaults") if "--all" in utils.pcs_options or "--defaults" in utils.pcs_options: if len(argv) != 0: utils.err("you cannot specify a property when using --all or --defaults") properties = get_default_properties() else: properties = {} if "--defaults" not in utils.pcs_options: properties = utils.get_set_properties( None if print_all else argv[0], properties ) print("Cluster Properties:") for prop,val in sorted(properties.items()): print(" " + prop + ": " + val) node_attributes = utils.get_node_attributes( filter_attr=(None if print_all else argv[0]) ) if node_attributes: print("Node Attributes:") node.attribute_print(node_attributes)
def list_property(lib, argv, modifiers): """ Options: * -f - CIB file * --all - list all properties * --defaults - list only default values of properties """ modifiers.ensure_only_supported("--defaults", "--all", "-f") if len(argv) > 1: raise CmdLineInputError() print_all = len(argv) == 0 if modifiers.is_specified("--all") and modifiers.is_specified( "--defaults"): utils.err("you cannot specify both --all and --defaults") if modifiers.get("--all") or modifiers.get("--defaults"): if not print_all: utils.err( "you cannot specify a property when using --all or --defaults") properties = get_default_properties() else: properties = {} if not modifiers.get("--defaults"): configured_properties = utils.get_set_properties( None if print_all else argv[0], properties) if modifiers.get("--all"): properties.update(configured_properties) else: properties = configured_properties print("Cluster Properties:") for prop, val in sorted(properties.items()): print(" {0}: {1}".format(prop, val))
def list_property(argv): print_all = len(argv) == 0 if "--all" in utils.pcs_options and "--defaults" in utils.pcs_options: utils.err("you cannot specify both --all and --defaults") if "--all" in utils.pcs_options or "--defaults" in utils.pcs_options: if len(argv) != 0: utils.err("you cannot specify a property when using --all or --defaults") properties = get_default_properties() else: properties = {} if "--defaults" not in utils.pcs_options: properties = utils.get_set_properties( None if print_all else argv[0], properties ) print("Cluster Properties:") for prop,val in sorted(properties.items()): print(" {0}: {1}".format(prop, val)) node_attributes = utils.get_node_attributes( filter_attr=(None if print_all else argv[0]) ) if node_attributes: print("Node Attributes:") node.attribute_print(node_attributes)
def quorum_unblock_cmd(lib, argv, modifiers): """ Options: * --force - no error when removing non existing property and no warning about this action """ modifiers.ensure_only_supported("--force") if argv: raise CmdLineInputError() output, retval = utils.run( ["corosync-cmapctl", "-g", "runtime.votequorum.wait_for_all_status"] ) if retval != 0: utils.err("unable to check quorum status") if output.split("=")[-1].strip() != "1": utils.err("cluster is not waiting for nodes to establish quorum") all_nodes, report_list = get_existing_nodes_names( utils.get_corosync_conf_facade() ) if report_list: utils.process_library_reports(report_list) unjoined_nodes = set(all_nodes) - set(utils.getCorosyncActiveNodes()) if not unjoined_nodes: utils.err("no unjoined nodes found") if not modifiers.get("--force"): answer = utils.get_terminal_input( ( "WARNING: If node(s) {nodes} are not powered off or they do" + " have access to shared resources, data corruption and/or" + " cluster failure may occur. Are you sure you want to" + " continue? [y/N] " ).format(nodes=", ".join(unjoined_nodes)) ) if answer.lower() not in ["y", "yes"]: print("Canceled") return for node in unjoined_nodes: # pass --force so no warning will be displayed stonith.stonith_confirm( lib, [node], parse_args.InputModifiers({"--force": ""}) ) output, retval = utils.run( ["corosync-cmapctl", "-s", "quorum.cancel_wait_for_all", "u8", "1"] ) if retval != 0: utils.err("unable to cancel waiting for nodes") print("Quorum unblocked") startup_fencing = utils.get_set_properties().get("startup-fencing", "") utils.set_cib_property( "startup-fencing", "false" if startup_fencing.lower() != "false" else "true" ) utils.set_cib_property("startup-fencing", startup_fencing) print("Waiting for nodes canceled")
def quorum_unblock_cmd(lib, argv, modifiers): """ Options: * --force - no error when removing non existing property and no warning about this action """ modifiers.ensure_only_supported("--force") if argv: raise CmdLineInputError() output, retval = utils.run( ["corosync-cmapctl", "-g", "runtime.votequorum.wait_for_all_status"] ) if retval != 0: utils.err("unable to check quorum status") if output.split("=")[-1].strip() != "1": utils.err("cluster is not waiting for nodes to establish quorum") all_nodes, report_list = get_existing_nodes_names( utils.get_corosync_conf_facade() ) if report_list: process_library_reports(report_list) unjoined_nodes = set(all_nodes) - set(utils.getCorosyncActiveNodes()) if not unjoined_nodes: utils.err("no unjoined nodes found") if not modifiers.get("--force"): answer = utils.get_terminal_input( ( "WARNING: If node(s) {nodes} are not powered off or they do" + " have access to shared resources, data corruption and/or" + " cluster failure may occur. Are you sure you want to" + " continue? [y/N] " ).format(nodes=", ".join(unjoined_nodes)) ) if answer.lower() not in ["y", "yes"]: print("Canceled") return for node in unjoined_nodes: # pass --force so no warning will be displayed stonith.stonith_confirm( lib, [node], parse_args.InputModifiers({"--force": ""}) ) output, retval = utils.run( ["corosync-cmapctl", "-s", "quorum.cancel_wait_for_all", "u8", "1"] ) if retval != 0: utils.err("unable to cancel waiting for nodes") print("Quorum unblocked") startup_fencing = utils.get_set_properties().get("startup-fencing", "") utils.set_cib_property( "startup-fencing", "false" if startup_fencing.lower() != "false" else "true" ) utils.set_cib_property("startup-fencing", startup_fencing) print("Waiting for nodes canceled")
def quorum_unblock_cmd(argv): if len(argv) > 0: usage.quorum(["unblock"]) sys.exit(1) if utils.is_rhel6(): utils.err("operation is not supported on CMAN clusters") output, retval = utils.run( ["corosync-cmapctl", "-g", "runtime.votequorum.wait_for_all_status"] ) if retval != 0: utils.err("unable to check quorum status") if output.split("=")[-1].strip() != "1": utils.err("cluster is not waiting for nodes to establish quorum") unjoined_nodes = ( set(utils.getNodesFromCorosyncConf()) - set(utils.getCorosyncActiveNodes()) ) if not unjoined_nodes: utils.err("no unjoined nodes found") if "--force" not in utils.pcs_options: answer = utils.get_terminal_input( ( "WARNING: If node(s) {nodes} are not powered off or they do" + " have access to shared resources, data corruption and/or" + " cluster failure may occur. Are you sure you want to" + " continue? [y/N] " ).format(nodes=", ".join(unjoined_nodes)) ) if answer.lower() not in ["y", "yes"]: print("Canceled") return for node in unjoined_nodes: stonith.stonith_confirm([node], skip_question=True) output, retval = utils.run( ["corosync-cmapctl", "-s", "quorum.cancel_wait_for_all", "u8", "1"] ) if retval != 0: utils.err("unable to cancel waiting for nodes") print("Quorum unblocked") startup_fencing = utils.get_set_properties().get("startup-fencing", "") utils.set_cib_property( "startup-fencing", "false" if startup_fencing.lower() != "false" else "true" ) utils.set_cib_property("startup-fencing", startup_fencing) print("Waiting for nodes canceled")
def quorum_unblock_cmd(lib, argv, modifiers): """ Options: * --force - no error when removing non existing property and no warning about this action """ modifiers.ensure_only_supported("--force") if argv: raise CmdLineInputError() output, retval = utils.run( ["corosync-cmapctl", "-g", "runtime.votequorum.wait_for_all_status"]) if (retval == 1 and "Error CS_ERR_NOT_EXIST" in output) or ( retval == 0 and output.rsplit("=", maxsplit=1)[-1].strip() != "1"): utils.err("cluster is not waiting for nodes to establish quorum") if retval != 0: utils.err("unable to check quorum status") all_nodes, report_list = get_existing_nodes_names( utils.get_corosync_conf_facade()) if report_list: process_library_reports(report_list) unjoined_nodes = set(all_nodes) - set(utils.getCorosyncActiveNodes()) if not unjoined_nodes: utils.err("no unjoined nodes found") if not utils.get_continue_confirmation_or_force( f"If node(s) {format_list(unjoined_nodes)} are not powered off or they " "do have access to shared resources, data corruption and/or cluster " "failure may occur", modifiers.get("--force"), ): return for node in unjoined_nodes: # pass --force so no warning will be displayed stonith.stonith_confirm(lib, [node], parse_args.InputModifiers({"--force": ""})) output, retval = utils.run( ["corosync-cmapctl", "-s", "quorum.cancel_wait_for_all", "u8", "1"]) if retval != 0: utils.err("unable to cancel waiting for nodes") print_to_stderr("Quorum unblocked") startup_fencing = utils.get_set_properties().get("startup-fencing", "") utils.set_cib_property( "startup-fencing", "false" if startup_fencing.lower() != "false" else "true", ) utils.set_cib_property("startup-fencing", startup_fencing) print_to_stderr("Waiting for nodes canceled")
def acl_show(argv): dom = utils.get_cib_dom() properties = utils.get_set_properties(defaults=prop.get_default_properties()) acl_enabled = properties.get("enable-acl", "").lower() if is_true(acl_enabled): print("ACLs are enabled") else: print("ACLs are disabled, run 'pcs acl enable' to enable") print() print_targets(dom) print_groups(dom) print_roles(dom)
def list_property(lib, argv, modifiers): """ Options: * -f - CIB file * --all - list all properties * --defaults - list only default values of properties """ del lib modifiers.ensure_only_supported( "--defaults", "--all", "-f", # The hint is defined to print error messages which point users to the # changes section in pcs manpage. # To be removed in the next significant version. hint_syntax_changed=modifiers.is_specified("--node"), ) if len(argv) > 1: raise CmdLineInputError() print_all = len(argv) == 0 if modifiers.is_specified("--all") and modifiers.is_specified( "--defaults"): utils.err("you cannot specify both --all and --defaults") if modifiers.get("--all") or modifiers.get("--defaults"): if not print_all: utils.err( "you cannot specify a property when using --all or --defaults") properties = get_default_properties() else: properties = {} if not modifiers.get("--defaults"): configured_properties = utils.get_set_properties( None if print_all else argv[0], properties) if modifiers.get("--all"): properties.update(configured_properties) else: properties = configured_properties print("Cluster Properties:") for prop, val in sorted(properties.items()): print(" {0}: {1}".format(prop, val))
def list_property(lib, argv, modifiers): """ Options: * -f - CIB file * --all - list all properties * --defaults - list only default values of properties """ del lib modifiers.ensure_only_supported("--defaults", "--all", "-f") if len(argv) > 1: raise CmdLineInputError() print_all = len(argv) == 0 if modifiers.is_specified("--all") and modifiers.is_specified("--defaults"): utils.err("you cannot specify both --all and --defaults") if modifiers.get("--all") or modifiers.get("--defaults"): if not print_all: utils.err( "you cannot specify a property when using --all or --defaults" ) properties = get_default_properties() else: properties = {} if not modifiers.get("--defaults"): configured_properties = utils.get_set_properties( None if print_all else argv[0], properties ) if modifiers.get("--all"): properties.update(configured_properties) else: properties = configured_properties print("Cluster Properties:") for prop, val in sorted(properties.items()): print(" {0}: {1}".format(prop, val))
def _config_show_cib_lines(lib): """ Commandline options: * -f - CIB file """ # update of pcs_options will change output of constraint show utils.pcs_options["--full"] = 1 # get latest modifiers object after updating pcs_options modifiers = utils.get_input_modifiers() cib_xml = utils.get_cib() cib_etree = utils.get_cib_etree(cib_xml=cib_xml) cib_dom = utils.get_cib_dom(cib_xml=cib_xml) resource_lines = [] stonith_lines = [] for resource_el in cib_etree.find(".//resources"): is_stonith = ("class" in resource_el.attrib and resource_el.attrib["class"] == "stonith") resource_el_lines = resource.resource_node_lines(resource_el) if is_stonith: stonith_lines += resource_el_lines else: resource_lines += resource_el_lines all_lines = [] all_lines.append("Resources:") all_lines.extend(indent(resource_lines, indent_step=1)) all_lines.append("") all_lines.append("Stonith Devices:") all_lines.extend(indent(stonith_lines, indent_step=1)) all_lines.append("Fencing Levels:") levels_lines = stonith.stonith_level_config_to_str( lib.fencing_topology.get_config()) if levels_lines: all_lines.extend(indent(levels_lines, indent_step=2)) all_lines.append("") constraints_element = cib_dom.getElementsByTagName("constraints")[0] all_lines.extend( constraint.location_lines( constraints_element, showDetail=True, show_expired=True, verify_expiration=False, )) all_lines.extend( constraint_command.show( "Ordering Constraints:", lib.constraint_order.show, constraints_reports.order_plain, modifiers.get_subset("-f", "--full"), )) all_lines.extend( constraint_command.show( "Colocation Constraints:", lib.constraint_colocation.show, constraints_reports.colocation_plain, modifiers.get_subset("-f", "--full"), )) all_lines.extend( constraint_command.show( "Ticket Constraints:", lib.constraint_ticket.show, constraints_reports.ticket_plain, modifiers.get_subset("-f", "--full"), )) all_lines.append("") all_lines.extend(alert.alert_config_lines(lib)) all_lines.append("") all_lines.append("Resources Defaults:") all_lines.extend( indent(resource.show_defaults(cib_dom, "rsc_defaults"), indent_step=1)) all_lines.append("Operations Defaults:") all_lines.extend( indent(resource.show_defaults(cib_dom, "op_defaults"), indent_step=1)) all_lines.append("") all_lines.append("Cluster Properties:") properties = utils.get_set_properties() all_lines.extend( indent( [ "{0}: {1}".format(prop, val) for prop, val in sorted(properties.items()) ], indent_step=1, )) all_lines.append("") all_lines.append("Tags:") tags = lib.tag.config([]) if not tags: all_lines.append(" No tags defined") tag_lines = [] for tag in tags: tag_lines.append(tag["tag_id"]) tag_lines.extend(indent(tag["idref_list"])) all_lines.extend(indent(tag_lines, indent_step=1)) return all_lines
def _config_show_cib_lines(lib): """ Commandline options: * -f - CIB file """ # update of pcs_options will change output of constraint show utils.pcs_options["--full"] = 1 # get latest modifiers object after updating pcs_options modifiers = utils.get_input_modifiers() cib_xml = utils.get_cib() cib_etree = utils.get_cib_etree(cib_xml=cib_xml) cib_dom = utils.get_cib_dom(cib_xml=cib_xml) resource_lines = [] stonith_lines = [] for resource_el in cib_etree.find(".//resources"): is_stonith = ( "class" in resource_el.attrib and resource_el.attrib["class"] == "stonith" ) resource_el_lines = resource.resource_node_lines(resource_el) if is_stonith: stonith_lines += resource_el_lines else: resource_lines += resource_el_lines all_lines = [] all_lines.append("Resources:") all_lines.extend(indent(resource_lines, indent_step=1)) all_lines.append("") all_lines.append("Stonith Devices:") all_lines.extend(indent(stonith_lines, indent_step=1)) all_lines.append("Fencing Levels:") levels_lines = stonith.stonith_level_config_to_str( lib.fencing_topology.get_config() ) if levels_lines: all_lines.extend(indent(levels_lines, indent_step=2)) all_lines.append("") constraints_element = cib_dom.getElementsByTagName('constraints')[0] all_lines.extend( constraint.location_lines(constraints_element, showDetail=True) ) all_lines.extend(constraint_command.show( "Ordering Constraints:", lib.constraint_order.show, order_console_report.constraint_plain, modifiers.get_subset("-f", "--full"), )) all_lines.extend(constraint_command.show( "Colocation Constraints:", lib.constraint_colocation.show, colocation_console_report.constraint_plain, modifiers.get_subset("-f", "--full"), )) all_lines.extend(constraint_command.show( "Ticket Constraints:", lib.constraint_ticket.show, ticket_console_report.constraint_plain, modifiers.get_subset("-f", "--full"), )) all_lines.append("") all_lines.extend(alert.alert_config_lines(lib)) all_lines.append("") all_lines.append("Resources Defaults:") all_lines.extend(indent( resource.show_defaults(cib_dom, "rsc_defaults"), indent_step=1 )) all_lines.append("Operations Defaults:") all_lines.extend(indent( resource.show_defaults(cib_dom, "op_defaults"), indent_step=1 )) all_lines.append("") all_lines.append("Cluster Properties:") properties = utils.get_set_properties() all_lines.extend(indent( [ "{0}: {1}".format(prop, val) for prop, val in sorted(properties.items()) ], indent_step=1 )) return all_lines
def _config_show_cib_lines(lib): """ Commandline options: * -f - CIB file """ # update of pcs_options will change output of constraint show and # displaying resources and operations defaults utils.pcs_options["--full"] = 1 # get latest modifiers object after updating pcs_options modifiers = utils.get_input_modifiers() cib_dom = utils.get_cib_dom() resources_facade = ResourcesConfigurationFacade.from_resources_dto( lib.resource.get_configured_resources()) all_lines = [] all_lines.append("Resources:") all_lines.extend( smart_wrap_text( indent( resources_to_text(resources_facade.filter_stonith(False)), indent_step=INDENT_STEP, ))) all_lines.append("") all_lines.append("Stonith Devices:") all_lines.extend( smart_wrap_text( indent( resources_to_text(resources_facade.filter_stonith(True)), indent_step=INDENT_STEP, ))) all_lines.append("Fencing Levels:") levels_lines = stonith.stonith_level_config_to_str( lib.fencing_topology.get_config()) if levels_lines: all_lines.extend(indent(levels_lines, indent_step=2)) all_lines.append("") constraints_element = cib_dom.getElementsByTagName("constraints")[0] all_lines.extend( constraint.location_lines( constraints_element, showDetail=True, show_expired=True, verify_expiration=False, )) all_lines.extend( constraint_command.config_cmd( "Ordering Constraints:", lib.constraint_order.config, constraints_reports.order_plain, modifiers.get_subset("-f", "--full"), )) all_lines.extend( constraint_command.config_cmd( "Colocation Constraints:", lib.constraint_colocation.config, constraints_reports.colocation_plain, modifiers.get_subset("-f", "--full"), )) all_lines.extend( constraint_command.config_cmd( "Ticket Constraints:", lib.constraint_ticket.config, constraints_reports.ticket_plain, modifiers.get_subset("-f", "--full"), )) all_lines.append("") all_lines.extend(alert.alert_config_lines(lib)) all_lines.append("") all_lines.append("Resources Defaults:") all_lines.extend( indent( nvset_dto_list_to_lines( lib.cib_options.resource_defaults_config( evaluate_expired=False).meta_attributes, nvset_label="Meta Attrs", with_ids=modifiers.get("--full"), text_if_empty="No defaults set", ))) all_lines.append("Operations Defaults:") all_lines.extend( indent( nvset_dto_list_to_lines( lib.cib_options.operation_defaults_config( evaluate_expired=False).meta_attributes, nvset_label="Meta Attrs", with_ids=modifiers.get("--full"), text_if_empty="No defaults set", ))) all_lines.append("") all_lines.append("Cluster Properties:") properties = utils.get_set_properties() all_lines.extend( indent( [ "{0}: {1}".format(prop, val) for prop, val in sorted(properties.items()) ], indent_step=1, )) all_lines.append("") all_lines.append("Tags:") tags = lib.tag.config([]) if not tags: all_lines.append(" No tags defined") tag_lines = [] for tag in tags: tag_lines.append(tag["tag_id"]) tag_lines.extend(indent(tag["idref_list"])) all_lines.extend(indent(tag_lines, indent_step=1)) return all_lines