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_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 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 * --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)