def config( lib: Any, argv: Sequence[str], modifiers: InputModifiers, ) -> None: """ Options: None """ modifiers.ensure_only_supported() if argv: raise CmdLineInputError() config_raw = lib.dr.get_config() try: config_dto = dto.from_dict(DrConfigDto, config_raw) except (KeyError, TypeError, ValueError) as e: raise error( "Unable to communicate with pcsd, received response:\n" f"{config_raw}" ) from e lines = ["Local site:"] lines.extend(indent(_config_site_lines(config_dto.local_site))) for site_dto in config_dto.remote_site_list: lines.append("Remote site:") lines.extend(indent(_config_site_lines(site_dto))) print("\n".join(lines))
def pcsd_status_cmd( lib: Any, argv: Sequence[str], modifiers: InputModifiers, dont_exit: bool = False, ) -> None: """ Options: * --request-timeout - HTTP timeout for node authorization check """ # If no arguments get current cluster node status, otherwise get listed # nodes status del lib modifiers.ensure_only_supported("--request-timeout") bad_nodes = False if not argv: nodes, report_list = get_existing_nodes_names( utils.get_corosync_conf_facade() ) if not nodes and not dont_exit: report_list.append( ReportItem.error( reports.messages.CorosyncConfigNoNodesDefined() ) ) if report_list: process_library_reports(report_list) bad_nodes = _check_nodes(nodes, " ") else: bad_nodes = _check_nodes(argv, " ") if bad_nodes and not dont_exit: sys.exit(2)
def op_delete_cmd(lib: Any, argv: List[str], modifiers: parse_args.InputModifiers) -> None: """ Options: * -f - CIB file """ modifiers.ensure_only_supported("-f") if not argv: raise CmdLineInputError() _check_is_stonith(lib, [argv[0]], "pcs resource op delete") resource.resource_operation_remove(argv[0], argv[1:])
def status( lib: Any, argv: Sequence[str], modifiers: InputModifiers, ) -> None: """ Options: * --full - show full details, node attributes and failcount * --hide-inactive - hide inactive resources * --request-timeout - HTTP timeout for node authorization check """ modifiers.ensure_only_supported( "--full", "--hide-inactive", "--request-timeout", ) if argv: raise CmdLineInputError() status_list_raw = lib.dr.status_all_sites_plaintext( hide_inactive_resources=modifiers.get("--hide-inactive"), verbose=modifiers.get("--full"), ) try: status_list = [ dto.from_dict(DrSiteStatusDto, status_raw) for status_raw in status_list_raw ] except (KeyError, TypeError, ValueError) as e: raise error( "Unable to communicate with pcsd, received response:\n" f"{status_list_raw}" ) from e has_errors = False plaintext_parts = [] for site_status in status_list: plaintext_parts.append( "--- {local_remote} cluster - {role} site ---".format( local_remote=("Local" if site_status.local_site else "Remote"), role=site_status.site_role.capitalize(), ) ) if site_status.status_successfully_obtained: plaintext_parts.append(site_status.status_plaintext.strip()) plaintext_parts.extend(["", ""]) else: has_errors = True plaintext_parts.extend( ["Error: Unable to get status of the cluster from any node", ""] ) print("\n".join(plaintext_parts).strip()) if has_errors: raise error("Unable to get status of all sites")
def tag_remove( lib: Any, argv: Sequence[str], modifiers: InputModifiers, ) -> None: """ Options: * -f - CIB file """ modifiers.ensure_only_supported("-f") if len(argv) < 1: raise CmdLineInputError() lib.tag.remove(argv)
def delete_cmd(lib: Any, argv: List[str], modifiers: parse_args.InputModifiers) -> None: """ Options: * -f - CIB file * --force - don't stop a resource before its deletion """ modifiers.ensure_only_supported("-f", "--force") if len(argv) != 1: raise CmdLineInputError() resource_id = argv[0] _check_is_stonith(lib, [resource_id], "pcs resource delete") resource.resource_remove(resource_id)
def set_recovery_site( lib: Any, argv: Sequence[str], modifiers: InputModifiers, ) -> None: """ Options: * --request-timeout - HTTP timeout for node authorization check """ modifiers.ensure_only_supported("--request-timeout") if len(argv) != 1: raise CmdLineInputError() lib.dr.set_recovery_site(argv[0])
def tag_update( lib: Any, argv: Sequence[str], modifiers: InputModifiers, ) -> None: """ Options: * -f - CIB file * --after - place a reference id in a tag after the specified reference id in the tag * --before - place a reference id in a tag before the specified reference id in the tag """ modifiers.ensure_only_supported("-f", "--after", "--before") if not argv: raise CmdLineInputError() tag_id = argv[0] parsed_args = group_by_keywords( argv[1:], ["add", "remove"], keyword_repeat_allowed=False, only_found_keywords=True, ) no_add_remove_arguments = ("add" not in parsed_args and "remove" not in parsed_args) no_add_id = "add" in parsed_args and not parsed_args["add"] no_remove_id = "remove" in parsed_args and not parsed_args["remove"] if no_add_remove_arguments or no_add_id or no_remove_id: raise CmdLineInputError( show_both_usage_and_message=True, hint=("Specify at least one id for 'add' or 'remove' arguments."), ) adjacent_idref = None after_adjacent = True if modifiers.is_specified("--after") and modifiers.is_specified( "--before"): raise CmdLineInputError("Cannot specify both --before and --after") if modifiers.is_specified("--after"): adjacent_idref = modifiers.get("--after") after_adjacent = True elif modifiers.is_specified("--before"): adjacent_idref = modifiers.get("--before") after_adjacent = False lib.tag.update( tag_id, parsed_args["add"] if "add" in parsed_args else [], parsed_args["remove"] if "remove" in parsed_args else [], adjacent_idref=adjacent_idref, put_after_adjacent=after_adjacent, )
def tag_create( lib: Any, argv: Sequence[str], modifiers: InputModifiers, ) -> None: """ Options: * -f - CIB file """ modifiers.ensure_only_supported("-f") if len(argv) < 2: raise CmdLineInputError() tag_id, idref_list = argv[0], argv[1:] lib.tag.create(tag_id, idref_list)
def enable_cmd(lib: Any, argv: List[str], modifiers: parse_args.InputModifiers) -> None: """ Options: * --wait * -f - CIB file """ modifiers.ensure_only_supported("--wait", "-f") if not argv: raise CmdLineInputError( "You must specify stonith resource(s) to enable") resources = argv _check_is_stonith(lib, resources, "pcs resource enable") lib.resource.enable(resources, modifiers.get("--wait"))
def destroy( lib: Any, argv: Sequence[str], modifiers: InputModifiers, ) -> None: """ Options: * --skip-offline - skip unreachable nodes (including missing auth token) * --request-timeout - HTTP timeout for node authorization check """ modifiers.ensure_only_supported("--skip-offline", "--request-timeout") if argv: raise CmdLineInputError() force_flags = [] if modifiers.get("--skip-offline"): force_flags.append(report_codes.SKIP_OFFLINE_NODES) lib.dr.destroy(force_flags=force_flags)
def show_resource_relations_cmd( lib: Any, argv: Sequence[str], modifiers: InputModifiers, ) -> None: """ Options: * -f - CIB file """ modifiers.ensure_only_supported("-f") if len(argv) != 1: raise CmdLineInputError() tree = ResourcePrintableNode.from_dto( ResourceRelationDto.from_dict( lib.resource.get_resource_relations_tree(argv[0]))) for line in tree_to_lines(tree): print(line)
def stonith_list_options(lib: Any, argv: List[str], modifiers: parse_args.InputModifiers) -> None: """ Options: * --full - show advanced options """ modifiers.ensure_only_supported("--full") if len(argv) != 1: raise CmdLineInputError() agent_name = ResourceAgentNameDto("stonith", None, argv[0]) print("\n".join( smart_wrap_text( resource_agent_metadata_to_text( lib.resource_agent.get_agent_metadata(agent_name), lib.resource_agent.get_agent_default_operations( agent_name).operations, verbose=modifiers.is_specified("--full"), ))))
def tag_config( lib: Any, argv: Sequence[str], modifiers: InputModifiers, ) -> None: """ Options: * -f - CIB file """ modifiers.ensure_only_supported("-f") tag_list = lib.tag.config(argv) if not tag_list: print_to_stderr(" No tags defined") return lines = [] for tag in tag_list: lines.append(tag["tag_id"]) lines.extend(indent(tag["idref_list"])) print("\n".join(lines))
def show_resource_relations_cmd( lib: Any, argv: Sequence[str], modifiers: InputModifiers, ) -> None: """ Options: * -f - CIB file * --full - show constraint ids and resource types """ modifiers.ensure_only_supported("-f", "--full") if len(argv) != 1: raise CmdLineInputError() tree = ResourcePrintableNode.from_dto( dto.from_dict( ResourceRelationDto, lib.resource.get_resource_relations_tree(argv[0]), ) ) for line in tree_to_lines(tree, verbose=modifiers.get("--full")): print(line)