def certkey(lib: Any, argv: Sequence[str], modifiers: InputModifiers) -> None: deprecation_warning("This command is deprecated and will be removed. " "Please use 'pcs pcsd certkey' instead.") try: return pcsd.pcsd_certkey_cmd(lib, argv, modifiers) except CmdLineInputError as e: return exit_on_cmdline_input_error(e, "pcsd", ["certkey"])
def _check_is_stonith( lib: Any, resource_id_list: List[str], cmd_to_use: Optional[str] = None, ) -> None: if lib.resource.is_any_resource_except_stonith(resource_id_list): deprecation_warning( reports.messages.ResourceStonithCommandsMismatch( "resources").message + format_optional(cmd_to_use, " Please use '{}' instead."))
def _stonith_level_normalize_devices(argv): """ Commandline options: no options """ # normalize devices - previously it was possible to delimit devices by both # a comma and a space if any("," in arg for arg in argv): deprecation_warning( "Delimiting stonith devices with ',' is deprecated and will be " "removed. Please use a space to delimit stonith devices.") return ",".join(argv).split(",")
def tag_list_cmd( lib: Any, argv: Sequence[str], modifiers: InputModifiers, ) -> None: """ Options: * -f - CIB file """ deprecation_warning("This command is deprecated and will be removed. " "Please use 'pcs tag config' instead.") return tag_config(lib, argv, modifiers)
def stonith_level_remove_cmd(lib, argv, modifiers): """ Options: * -f - CIB file """ modifiers.ensure_only_supported("-f") if not argv: raise CmdLineInputError() target_type, target_value, devices = None, None, None level = argv[0] allowed_keywords = {"target", "stonith"} if len(argv) > 1 and argv[1] in allowed_keywords: ( target_type, target_value, devices, ) = _stonith_level_parse_target_and_stonith(argv[1:]) target_may_be_a_device = False else: # TODO remove, deprecated backward compatibility layer for old syntax if len(argv) > 1: deprecation_warning( "Syntax 'pcs stonith level delete | remove <level> [<target>] " "[<stonith id>...]' is deprecated and will be removed. Please " "use 'pcs stonith level delete | remove <level> " "[target <target>] [stonith <stonith id>...]'.") if not parse_args.ARG_TYPE_DELIMITER in argv[1] and "," in argv[1]: deprecation_warning( "Delimiting stonith devices with ',' is deprecated and " "will be removed. Please use a space to delimit stonith " "devices.") target_type, target_value = _stonith_level_parse_node(argv[1]) if len(argv) > 2: devices = _stonith_level_normalize_devices(argv[2:]) target_may_be_a_device = True lib.fencing_topology.remove_levels_by_params( level, target_type, target_value, devices, # backward compatibility mode, see lib command for details target_may_be_a_device=target_may_be_a_device, )
def disable_cmd(lib: Any, argv: List[str], modifiers: parse_args.InputModifiers) -> None: """ Options: * -f - CIB file * --brief - show brief output of --simulate * --safe - only disable if no other resource gets stopped or demoted * --simulate - do not push the CIB, print its effects * --no-strict - allow disable if other resource is affected * --wait """ if not argv: raise CmdLineInputError( "You must specify stonith resource(s) to disable") _check_is_stonith(lib, argv, "pcs resource disable") if modifiers.is_specified_any(("--safe", "--no-strict", "--simulate")): deprecation_warning( "Options '--safe', '--no-strict' and '--simualte' are deprecated " "and will be removed in a future release.") resource.resource_disable_common(lib, argv, modifiers)
def main(argv=None): # pylint: disable=global-statement # pylint: disable=too-many-branches # pylint: disable=too-many-locals # pylint: disable=too-many-statements if completion.has_applicable_environment(os.environ): print( completion.make_suggestions( os.environ, usage.generate_completion_tree_from_usage())) sys.exit() argv = argv if argv else sys.argv[1:] utils.subprocess_setup() global filename, usefile utils.pcs_options = {} # we want to support optional arguments for --wait, so if an argument # is specified with --wait (ie. --wait=30) then we use them waitsecs = None new_argv = [] for arg in argv: if arg.startswith("--wait="): tempsecs = arg.replace("--wait=", "") if tempsecs: waitsecs = tempsecs arg = "--wait" new_argv.append(arg) argv = new_argv try: if "--" in argv: pcs_options, argv = getopt.gnu_getopt(argv, parse_args.PCS_SHORT_OPTIONS, parse_args.PCS_LONG_OPTIONS) else: # DEPRECATED # TODO remove # We want to support only the -- version ( args_without_negative_nums, args_filtered_out, ) = parse_args.filter_out_non_option_negative_numbers(argv) if args_filtered_out: options_str = "', '".join(args_filtered_out) deprecation_warning( f"Using '{options_str}' without '--' is deprecated, those " "parameters will be considered position independent " "options in future pcs versions") pcs_options, dummy_argv = getopt.gnu_getopt( args_without_negative_nums, parse_args.PCS_SHORT_OPTIONS, parse_args.PCS_LONG_OPTIONS, ) argv = parse_args.filter_out_options(argv) except getopt.GetoptError as err: error(str(err)) print_to_stderr(usage.main()) sys.exit(1) full = False for option, dummy_value in pcs_options: if option == "--full": full = True break for opt, val in pcs_options: if not opt in utils.pcs_options: utils.pcs_options[opt] = val else: # If any options are a list then they've been entered twice which # isn't valid utils.err("%s can only be used once" % opt) if opt in ("-h", "--help"): if not argv: print(usage.main()) sys.exit() else: argv = [argv[0], "help"] + argv[1:] elif opt == "-f": usefile = True filename = val utils.usefile = usefile utils.filename = filename elif opt == "--corosync_conf": settings.corosync_conf_file = val elif opt == "--version": print(settings.pcs_version) if full: print(" ".join( sorted([ feat["id"] for feat in capabilities.get_pcs_capabilities() ]))) sys.exit() elif opt == "--fullhelp": usage.full_usage() sys.exit() elif opt == "--wait": utils.pcs_options[opt] = waitsecs elif opt == "--request-timeout": request_timeout_valid = False try: timeout = int(val) if timeout > 0: utils.pcs_options[opt] = timeout request_timeout_valid = True except ValueError: pass if not request_timeout_valid: utils.err(("'{0}' is not a valid --request-timeout value, use " "a positive integer").format(val)) # initialize logger logging.getLogger("pcs") if (os.getuid() != 0) and (argv and argv[0] != "help") and not usefile: _non_root_run(argv) cmd_map = { "resource": resource.resource_cmd, "cluster": cluster.cluster_cmd, "stonith": stonith.stonith_cmd, "property": prop.property_cmd, "constraint": constraint.constraint_cmd, "acl": acl.acl_cmd, "status": status.status_cmd, "config": config.config_cmd, "pcsd": pcsd.pcsd_cmd, "node": node.node_cmd, "quorum": quorum.quorum_cmd, "qdevice": qdevice.qdevice_cmd, "alert": alert.alert_cmd, "booth": booth.booth_cmd, "host": host.host_cmd, "client": client.client_cmd, "dr": dr.dr_cmd, "tag": tag.tag_cmd, "help": lambda lib, argv, modifiers: print(usage.main()), } try: routing.create_router(cmd_map, [])(utils.get_library_wrapper(), argv, utils.get_input_modifiers()) except LibraryError as e: if e.output: sys.stderr.write(e.output) sys.exit(1) process_library_reports(e.args) except errors.CmdLineInputError: if argv and argv[0] in cmd_map: usage.show(argv[0], []) else: print_to_stderr(usage.main()) sys.exit(1)
def show(lib, argv, modifiers): deprecation_warning("This command is deprecated and will be removed. " "Please use 'pcs constraint ticket config' instead.") return config_cmd(lib, argv, modifiers)
def stonith_level_clear_cmd(lib, argv, modifiers): """ Options: * -f - CIB file """ modifiers.ensure_only_supported("-f") if not argv: lib.fencing_topology.remove_all_levels() return allowed_keywords = {"target", "stonith"} if len(argv) > 1 or (len(argv) == 1 and argv[0] in allowed_keywords): ( target_type, target_value, devices, ) = _stonith_level_parse_target_and_stonith(argv) if devices is not None and target_value is not None: raise CmdLineInputError( "Only one of 'target' and 'stonith' can be used") lib.fencing_topology.remove_levels_by_params( None, target_type, target_value, devices, ) return # TODO remove, deprecated backward compatibility mode for old syntax # Command parameters are: node, stonith-list # Both the node and the stonith list are optional. If the node is omitted # and the stonith list is present, there is no way to figure it out, since # there is no specification of what the parameter is. Hence the pre-lib # code tried both. It deleted all levels having the first parameter as # either a node or a device list. Since it was only possible to specify # node as a target back then, this is enabled only in that case. deprecation_warning( "Syntax 'pcs stonith level clear [<target> | <stonith id(s)>] is " "deprecated and will be removed. Please use 'pcs stonith level clear " "[target <target>] | [stonith <stonith id>...]'.") target_type, target_value = _stonith_level_parse_node(argv[0]) was_error = False try: lib.fencing_topology.remove_levels_by_params( None, target_type, target_value, None, # pre-lib code didn't return any error when no level was found ignore_if_missing=True, ) except LibraryError: was_error = True if target_type == TARGET_TYPE_NODE: try: lib.fencing_topology.remove_levels_by_params( None, None, None, argv[0].split(","), # pre-lib code didn't return any error when no level was found ignore_if_missing=True, ) except LibraryError: was_error = True if was_error: raise LibraryError()
def stonith_create(lib, argv, modifiers): """ Options: * --before - specified resource inside a group before which new resource will be placed inside the group * --after - specified resource inside a group after which new resource will be placed inside the group * --group - specifies group in which resource will be created * --force - allow not existing agent, invalid operations or invalid instance attributes * --disabled - created resource will be disabled * --no-default-ops - do not add default operations * --wait * -f - CIB file """ modifiers.ensure_only_supported( "--before", "--after", "--group", "--force", "--disabled", "--no-default-ops", "--wait", "-f", ) if modifiers.is_specified("--before") and modifiers.is_specified( "--after"): raise error("you cannot specify both --before and --after{0}".format( "" if modifiers. is_specified("--group") else " and you have to specify --group")) if not modifiers.is_specified("--group"): if modifiers.is_specified("--before"): raise error("you cannot use --before without --group") if modifiers.is_specified("--after"): raise error("you cannot use --after without --group") if len(argv) < 2: raise CmdLineInputError() stonith_id = argv[0] stonith_type = argv[1] parts = parse_create_args(argv[2:]) settings = dict( allow_absent_agent=modifiers.get("--force"), allow_invalid_operation=modifiers.get("--force"), allow_invalid_instance_attributes=modifiers.get("--force"), ensure_disabled=modifiers.get("--disabled"), use_default_operations=not modifiers.get("--no-default-ops"), wait=modifiers.get("--wait"), ) if not modifiers.get("--group"): lib.stonith.create( stonith_id, stonith_type, parts["op"], parts["meta"], parts["options"], **settings, ) else: deprecation_warning( "Option to group stonith resource is deprecated and will be " "removed in a future release.") adjacent_resource_id = None put_after_adjacent = False if modifiers.get("--after"): adjacent_resource_id = modifiers.get("--after") put_after_adjacent = True if modifiers.get("--before"): adjacent_resource_id = modifiers.get("--before") put_after_adjacent = False lib.stonith.create_in_group( stonith_id, stonith_type, modifiers.get("--group"), parts["op"], parts["meta"], parts["options"], adjacent_resource_id=adjacent_resource_id, put_after_adjacent=put_after_adjacent, **settings, )
def list_property_deprecated(lib, argv, modifiers): deprecation_warning("This command is deprecated and will be removed. " "Please use 'pcs property config' instead.") return list_property(lib, argv, modifiers)
def print_alert_show(lib, argv, modifiers): deprecation_warning("This command is deprecated and will be removed. " "Please use 'pcs alert config' instead.") return print_alert_config(lib, argv, modifiers)
def show_acl_config(lib, argv, modifiers): deprecation_warning("This command is deprecated and will be removed. " "Please use 'pcs acl config' instead.") return acl_config(lib, argv, modifiers)