Пример #1
0
    def _run(self, client: OpenrCtrl.Client):
        policy = None
        try:
            policy = client.getRibPolicy()
        except ctrl_types.OpenrError as e:
            print(f"Error: {e.message}", file=sys.stderr)
            return

        # Convert the prefixes to readable format
        assert policy is not None
        for stmt in policy.statements:
            if stmt.matcher.prefixes:
                stmt.matcher.prefixes = [
                    ipnetwork.sprint_prefix(p) for p in stmt.matcher.prefixes
                ]

        # NOTE: We don't do explicit effor to print policy in
        print("> RibPolicy")
        print(f"  Validity: {policy.ttl_secs}s")
        for stmt in policy.statements:
            prefixes = stmt.matcher.prefixes or []
            action = stmt.action.set_weight or ctrl_types.RibRouteActionWeight(
            )
            print(f"  Statement: {stmt.name}")
            print(f"    Prefix Match List: {', '.join(prefixes)}")
            print("    Action Set Weight:")
            print(f"      Default: {action.default_weight}")
            print("      Area:")
            for area, weight in action.area_to_weight.items():
                print(f"        {area}: {weight}")
            print("      Neighbor:")
            for neighbor, weight in action.neighbor_to_weight.items():
                print(f"        {neighbor}: {weight}")
Пример #2
0
    def _run(self, client: OpenrCtrl.Client, *args, **kwargs):
        policy = None
        try:
            policy = client.getRibPolicy()
        except ctrl_types.OpenrError as e:
            print("Error: ", str(e), "\nSystem standard error: ", sys.stderr)
            return

        # Convert the prefixes to readable format
        assert policy is not None
        for stmt in policy.statements:
            if stmt.matcher.prefixes:
                stmt.matcher.prefixes = [
                    ipnetwork.sprint_prefix(p)
                    # pyre-fixme[16]: `Optional` has no attribute `__iter__`.
                    for p in stmt.matcher.prefixes
                ]

        # NOTE: We don't do explicit effor to print policy in
        print("> RibPolicy")
        print(f"  Validity: {policy.ttl_secs}s")
        for stmt in policy.statements:
            prefixes = stmt.matcher.prefixes or []
            tags = stmt.matcher.tags or []
            action = stmt.action.set_weight or ctrl_types.RibRouteActionWeight(
            )
            print(f"  Statement: {stmt.name}")
            if prefixes:
                # pyre-fixme[6]: Expected `Iterable[str]` for 1st param but got
                #  `Union[List[typing.Any], List[network_types.IpPrefix]]`.
                print(f"    Prefix Match List: {', '.join(prefixes)}")
            if tags:
                print(f"    Tags Match List: {', '.join(tags)}")
            print("    Action Set Weight:")
            print(f"      Default: {action.default_weight}")
            print("      Area:")
            for area, weight in action.area_to_weight.items():
                print(f"        {area}: {weight}")
            print("      Neighbor:")
            for neighbor, weight in action.neighbor_to_weight.items():
                print(f"        {neighbor}: {weight}")