Ejemplo n.º 1
0
    def print_counters(self, counters, json_opt):
        """ print the Fib counters """

        with utils.get_openr_ctrl_client(self.cli_opts.host,
                                         self.cli_opts) as client:
            host_id = client.getMyNodeName()
        caption = "{}'s Fib counters".format(host_id)

        if json_opt:
            utils.print_json(counters)
        else:
            rows = []
            for key in counters:
                rows.append(["{} : {}".format(key, counters[key])])
            print(
                printing.render_horizontal_table(rows,
                                                 caption=caption,
                                                 tablefmt="plain"))
            print()
Ejemplo n.º 2
0
    def run(
        self,
        prefixes: List[str],
        labels: List[int] = (),
        json_opt: bool = False,
        client_id: Optional[int] = None,
    ):
        routes = []
        mpls_routes = []
        client_id = client_id if client_id is not None else self.client.client_id

        try:
            routes = self.client.getRouteTableByClient(client_id)
        except Exception as e:
            print("Failed to get routes from Fib.")
            print("Exception: {}".format(e))
            return 1

        with utils.get_openr_ctrl_client(self.cli_opts.host,
                                         self.cli_opts) as client:
            host_id = client.getMyNodeName()

        try:
            mpls_routes = self.client.getMplsRouteTableByClient(client_id)
        except Exception:
            pass

        if json_opt:
            utils.print_json(
                utils.get_routes_json(host_id, client_id, routes, prefixes,
                                      mpls_routes, labels))
        else:
            caption = f"{host_id}'s FIB routes by client {client_id}"
            utils.print_unicast_routes(caption, routes, prefixes)
            caption = f"{host_id}'s MPLS routes by client {client_id}"
            utils.print_mpls_routes(caption, mpls_routes, labels)

        return 0