def set_property(lib, argv, modifiers): """ Options: * --force - allow unknown options * -f - CIB file """ del lib modifiers.ensure_only_supported( "--force", "-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 not argv: raise CmdLineInputError() prop_def_dict = utils.get_cluster_properties_definition() failed = False forced = modifiers.get("--force") properties = {} for arg in argv: args = arg.split("=") if len(args) != 2: utils.err("invalid property format: '{0}'".format(arg), False) failed = True elif not args[0]: utils.err("empty property name: '{0}'".format(arg), False) failed = True elif forced or args[1].strip() == "": properties[args[0]] = args[1] else: try: if utils.is_valid_cluster_property(prop_def_dict, args[0], args[1]): properties[args[0]] = args[1] else: utils.err( "invalid value of property: '{0}', (use --force to " "override)".format(arg), False, ) failed = True except utils.UnknownPropertyException: utils.err( "unknown cluster property: '{0}', (use --force to " "override)".format(args[0]), False, ) failed = True if failed: sys.exit(1) cib_dom = utils.get_cib_dom() for prop, value in properties.items(): utils.set_cib_property(prop, value, cib_dom) utils.replace_cib_configuration(cib_dom)
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 set_property(lib, argv, modifiers): """ Options: * --force - allow unknown options * -f - CIB file """ del lib modifiers.ensure_only_supported( "--force", "-f", ) if not argv: raise CmdLineInputError() prop_def_dict = utils.get_cluster_properties_definition() failed = False forced = modifiers.get("--force") properties = {} for arg in argv: args = arg.split("=") if len(args) != 2: utils.err("invalid property format: '{0}'".format(arg), False) failed = True elif not args[0]: utils.err("empty property name: '{0}'".format(arg), False) failed = True elif forced or args[1].strip() == "": properties[args[0]] = args[1] else: try: if utils.is_valid_cluster_property(prop_def_dict, args[0], args[1]): properties[args[0]] = args[1] else: utils.err( "invalid value of property: '{0}', (use --force to " "override)".format(arg), False, ) failed = True except utils.UnknownPropertyException: utils.err( "unknown cluster property: '{0}', (use --force to " "override)".format(args[0]), False, ) failed = True if failed: sys.exit(1) cib_dom = utils.get_cib_dom() for prop, value in properties.items(): utils.set_cib_property(prop, value, cib_dom) utils.replace_cib_configuration(cib_dom)
def set_property(lib, argv, modifiers): """ Options: * --force - allow unknown options * -f - CIB file """ del lib modifiers.ensure_only_supported("--force", "-f") if not argv: raise CmdLineInputError() prop_def_dict = utils.get_cluster_properties_definition() failed = False forced = modifiers.get("--force") properties = {} for arg in argv: args = arg.split('=') if len(args) != 2: utils.err("invalid property format: '{0}'".format(arg), False) failed = True elif not args[0]: utils.err("empty property name: '{0}'".format(arg), False) failed = True elif forced or args[1].strip() == "": properties[args[0]] = args[1] else: try: if utils.is_valid_cluster_property( prop_def_dict, args[0], args[1] ): properties[args[0]] = args[1] else: utils.err( "invalid value of property: '{0}', (use --force to " "override)".format(arg), False ) failed = True except utils.UnknownPropertyException: utils.err( "unknown cluster property: '{0}', (use --force to " "override)".format(args[0]), False ) failed = True if failed: sys.exit(1) cib_dom = utils.get_cib_dom() for prop, value in properties.items(): utils.set_cib_property(prop, value, cib_dom) utils.replace_cib_configuration(cib_dom)
def set_property(argv): if not argv: usage.property(['set']) sys.exit(1) prop_def_dict = utils.get_cluster_properties_definition() nodes_attr = "--node" in utils.pcs_options failed = False forced = "--force" in utils.pcs_options properties = {} for arg in argv: args = arg.split('=') if len(args) != 2: utils.err("invalid property format: '{0}'".format(arg), False) failed = True elif not args[0]: utils.err("empty property name: '{0}'".format(arg), False) failed = True elif nodes_attr or forced or args[1].strip() == "": properties[args[0]] = args[1] else: try: if utils.is_valid_cluster_property( prop_def_dict, args[0], args[1] ): properties[args[0]] = args[1] else: utils.err( "invalid value of property: '{0}', (use --force to " "override)".format(arg), False ) failed = True except utils.UnknownPropertyException: utils.err( "unknown cluster property: '{0}', (use --force to " "override)".format(args[0]), False ) failed = True if failed: sys.exit(1) if nodes_attr: for prop, value in properties.items(): utils.set_node_attribute(prop, value, utils.pcs_options["--node"]) else: cib_dom = utils.get_cib_dom() for prop, value in properties.items(): utils.set_cib_property(prop, value, cib_dom) utils.replace_cib_configuration(cib_dom)
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 set_property(argv): if not argv: usage.property(['set']) sys.exit(1) prop_def_dict = utils.get_cluster_properties_definition() nodes_attr = "--node" in utils.pcs_options failed = False forced = "--force" in utils.pcs_options properties = {} for arg in argv: args = arg.split('=') if len(args) != 2: utils.err("invalid property format: '{0}'".format(arg), False) failed = True elif not args[0]: utils.err("empty property name: '{0}'".format(arg), False) failed = True elif nodes_attr or forced or args[1].strip() == "": properties[args[0]] = args[1] else: try: if utils.is_valid_cluster_property( prop_def_dict, args[0], args[1] ): properties[args[0]] = args[1] else: utils.err( "invalid value of property: '{0}', (use --force to " "override)".format(arg), False ) failed = True except utils.UnknownPropertyException: utils.err( "unknown cluster property: '{0}', (use --force to " "override)".format(args[0]), False ) failed = True if failed: sys.exit(1) if nodes_attr: for prop, value in properties.items(): utils.set_node_attribute(prop, value, utils.pcs_options["--node"]) else: cib_dom = utils.get_cib_dom() for prop, value in properties.items(): utils.set_cib_property(prop, value, cib_dom) utils.replace_cib_configuration(cib_dom)
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 unset_property(argv): if len(argv) < 1: usage.property() sys.exit(1) if "--node" in utils.pcs_options: for arg in argv: utils.set_node_attribute(arg, "",utils.pcs_options["--node"]) else: cib_dom = utils.get_cib_dom() for arg in argv: utils.set_cib_property(arg, "", cib_dom) utils.replace_cib_configuration(cib_dom)
def unset_property(argv): if len(argv) < 1: usage.property() sys.exit(1) if "--node" in utils.pcs_options: for arg in argv: utils.set_node_attribute(arg, "",utils.pcs_options["--node"]) else: cib_dom = utils.get_cib_dom() for arg in argv: utils.set_cib_property(arg, "", cib_dom) utils.replace_cib_configuration(cib_dom)
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 unset_property(lib, argv, modifiers): """ Options: * --force - no error when removing not existing properties * -f - CIB file """ modifiers.ensure_only_supported("--force", "-f") if len(argv) < 1: raise CmdLineInputError() cib_dom = utils.get_cib_dom() for arg in argv: utils.set_cib_property(arg, "", cib_dom) utils.replace_cib_configuration(cib_dom)
def unset_property(lib, argv, modifiers): """ Options: * --force - no error when removing not existing properties * -f - CIB file """ del lib modifiers.ensure_only_supported("--force", "-f") if not argv: raise CmdLineInputError() cib_dom = utils.get_cib_dom() for arg in argv: utils.set_cib_property(arg, "", cib_dom) utils.replace_cib_configuration(cib_dom)
def unset_property(lib, argv, modifiers): """ Options: * --force - no error when removing not existing properties * -f - CIB file """ del lib modifiers.ensure_only_supported( "--force", "-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 not argv: raise CmdLineInputError() cib_dom = utils.get_cib_dom() for arg in argv: utils.set_cib_property(arg, "", cib_dom) utils.replace_cib_configuration(cib_dom)