def run(self, prefixes: List[str], labels: List[int], json_opt: bool = False): routes = [] mpls_routes = [] try: routes = self.client.getRouteTableByClient(self.client.client_id) except Exception as e: print("Failed to get routes from Fib.") print("Exception: {}".format(e)) return 1 host_id = utils.get_connected_node_name(self.cli_opts) client_id = self.client.client_id try: mpls_routes = self.client.getMplsRouteTableByClient(self.client.client_id) except platform_types.PlatformError as e: print("Pls check Open/R version. Exception: {}".format(e)) 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
def run(self, src, dst, max_hop): if not src or not dst: host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port) src = src or host_id dst = dst or host_id paths = self.get_paths(self.client, src, dst, max_hop) self.print_paths(paths)
def run(self, prefixes): try: routes = self.client.getKernelRouteTable() except Exception as e: print('Failed to get routes from Fib.') print('Exception: {}'.format(e)) sys.exit(1) host_id = utils.get_connected_node_name(self.client.host, self.lm_cmd_port) caption = '{}\'s kernel routes'.format(host_id) utils.print_routes(caption, routes, prefixes)
def print_counters(self, counters): ''' print the Fib counters ''' host_id = utils.get_connected_node_name(self.client.host, self.lm_cmd_port) caption = '{}\'s Fib counters'.format(host_id) rows = [] for key in counters: rows.append(['{} : {}'.format(key, counters[key])]) print(printing.render_horizontal_table(rows, caption=caption, tablefmt='plain')) print()
def run(self): try: routes = self.client.getRouteTableByClient(self.client.client_id) except Exception as e: print('Failed to get routes from Fib.') print('Exception: {}'.format(e)) sys.exit(1) host_id = utils.get_connected_node_name(self.client.host, self.lm_cmd_port) caption = '{}\'s FIB routes by client {}'.format( host_id, self.client.client_id) print_routes(caption, routes)
def config(ctx, config_store_url, verbose): # noqa: B902 ''' CLI tool to peek into Config Store module. ''' config_store_url = config_store_url or "{}_{}".format( Consts.CONFIG_STORE_URL_PREFIX, utils.get_connected_node_name( ctx.obj.hostname, ctx.obj.ports_config.get('lm_cmd_port', None) or Consts.LINK_MONITOR_CMD_PORT)) override_url = ctx.obj.ports_config.get('config_store_url', None) ctx.obj = ConfigContext(verbose, zmq.Context(), ctx.obj.timeout, override_url or config_store_url)
def print_peers(self, peers: kv_store_types.PeersMap) -> None: """ print the Kv Store peers """ host_id = utils.get_connected_node_name(self.cli_opts) caption = "{}'s peers".format(host_id) rows = [] for (key, value) in sorted(peers.items(), key=lambda x: x[0]): row = [key] row.append("cmd via {}".format(value.cmdUrl)) row.append("pub via {}".format(value.pubUrl)) rows.append(row) print(printing.render_vertical_table(rows, caption=caption))
def print_peers(self, peers_reply): ''' print the Kv Store peers ''' host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port) caption = '{}\'s peers'.format(host_id) rows = [] for (key, value) in sorted(peers_reply.peers.items(), key=lambda x: x[0]): row = [key] row.append('cmd via {}'.format(value.cmdUrl)) row.append('pub via {}'.format(value.pubUrl)) row.append('Public Key: {}'.format(value.publicKey.encode("hex"))) rows.append(row) print(printing.render_vertical_table(rows, caption=caption))
def run(self, src, dst, max_hop): if not src or not dst: host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port) src = src or host_id dst = dst or host_id # Get prefix_dbs from KvStore self.prefix_dbs = {} pub = self.kvstore_client.dump_all_with_filter(Consts.PREFIX_DB_MARKER) for v in pub.keyVals.values(): prefix_db = deserialize_thrift_object(v.value, lsdb_types.PrefixDatabase) self.prefix_dbs[prefix_db.thisNodeName] = prefix_db paths = self.get_paths(src, dst, max_hop) self.print_paths(paths)
def print_peers(self, peers_reply): """ print the Kv Store peers """ host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port) caption = "{}'s peers".format(host_id) rows = [] for (key, value) in sorted(peers_reply.peers.items(), key=lambda x: x[0]): row = [key] row.append("cmd via {}".format(value.cmdUrl)) row.append("pub via {}".format(value.pubUrl)) rows.append(row) print(printing.render_vertical_table(rows, caption=caption))
def print_counters(self, counters, json_opt): """ print the Fib counters """ host_id = utils.get_connected_node_name(self.cli_opts) 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()
def print_counters(self, resp, prefix): ''' print the Kv Store counters ''' host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port) caption = '{}\'s counters'.format(host_id) rows = [] for key, counter in sorted(resp.counters.items()): if not key.startswith(prefix): continue rows.append(['{} : {}'.format(key, counter.value)]) print( printing.render_horizontal_table(rows, caption=caption, tablefmt='plain')) print()
def _run(self, client: OpenrCtrl.Client, src: str, dst: str, max_hop: int) -> None: if not src or not dst: host_id = utils.get_connected_node_name(self.cli_opts) src = src or host_id dst = dst or host_id # Get prefix_dbs from KvStore self.prefix_dbs = {} pub = client.getKvStoreKeyValsFiltered( kv_store_types.KeyDumpParams(Consts.PREFIX_DB_MARKER)) for v in pub.keyVals.values(): prefix_db = deserialize_thrift_object(v.value, lsdb_types.PrefixDatabase) self.prefix_dbs[prefix_db.thisNodeName] = prefix_db paths = self.get_paths(client, src, dst, max_hop) self.print_paths(paths)
def run(self, prefixes, json_opt=False): try: routes = self.client.getRouteTableByClient(self.client.client_id) except Exception as e: print("Failed to get routes from Fib.") print("Exception: {}".format(e)) return 1 host_id = utils.get_connected_node_name(self.cli_opts) client_id = self.client.client_id if json_opt: utils.print_json( utils.get_routes_json(host_id, client_id, routes, prefixes)) else: caption = "{}'s FIB routes by client {}".format(host_id, client_id) utils.print_unicast_routes(caption, routes, prefixes) return 0
def run(self, prefixes, json_opt=False): try: routes = self.client.getRouteTableByClient(self.client.client_id) except Exception as e: print('Failed to get routes from Fib.') print('Exception: {}'.format(e)) return 1 host_id = utils.get_connected_node_name(self.client.host, self.lm_cmd_port) client_id = self.client.client_id if json_opt: utils.print_json(utils.get_routes_json( host_id, client_id, routes, prefixes)) else: caption = '{}\'s FIB routes by client {}'.format(host_id, client_id) utils.print_routes(caption, routes, prefixes) return 0
def run(self, nodes): if nodes: nodes = set(nodes.strip().split(',')) if 'all' in nodes: nodes = self.get_node_list() host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port) if host_id in nodes: nodes.remove(host_id) our_kvs = self.client.dump_all_with_prefix().keyVals kv_dict = self.dump_nodes_kvs(nodes) for node in kv_dict: self.compare(our_kvs, kv_dict[node], host_id, node) else: nodes = self.get_node_list() kv_dict = self.dump_nodes_kvs(nodes) for our_node, other_node in combinations(kv_dict.keys(), 2): self.compare(kv_dict[our_node], kv_dict[other_node], our_node, other_node)
def run(self, nodes): all_nodes_to_ips = self.get_node_to_ips() if nodes: nodes = set(nodes.strip().split(",")) if "all" in nodes: nodes = list(all_nodes_to_ips.keys()) host_id = utils.get_connected_node_name(self.cli_opts) if host_id in nodes: nodes.remove(host_id) our_kvs = self.client.dump_all_with_filter().keyVals kv_dict = self.dump_nodes_kvs(nodes, all_nodes_to_ips) for node in kv_dict: self.compare(our_kvs, kv_dict[node], host_id, node) else: nodes = list(all_nodes_to_ips.keys()) kv_dict = self.dump_nodes_kvs(nodes, all_nodes_to_ips) for our_node, other_node in combinations(kv_dict.keys(), 2): self.compare(kv_dict[our_node], kv_dict[other_node], our_node, other_node)
def print_counters(self, resp, prefix, is_json): """ print the Kv Store counters """ host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port) caption = "{}'s counters".format(host_id) rows = [] for key, counter in sorted(resp.counters.items()): if not key.startswith(prefix): continue rows.append([key, ":", counter.value]) if is_json: json_data = {k: v for k, _, v in rows} print(utils.json_dumps(json_data)) else: print( printing.render_horizontal_table(rows, caption=caption, tablefmt="plain")) print()
def print_counters(self, resp: Dict, prefix: str, json: bool) -> None: """ print the Kv Store counters """ host_id = utils.get_connected_node_name(self.cli_opts) caption = "{}'s counters".format(host_id) rows = [] for key, counter in sorted(resp.items()): if not key.startswith(prefix): continue rows.append([key, ":", counter]) if json: json_data = {k: v for k, _, v in rows} print(utils.json_dumps(json_data)) else: print( printing.render_horizontal_table( rows, caption=caption, tablefmt="plain" ) ) print()
def _run(self, client: OpenrCtrl.Client, nodes: set) -> None: all_nodes_to_ips = self.get_node_to_ips(client) if nodes: nodes = set(nodes.strip().split(",")) if "all" in nodes: nodes = list(all_nodes_to_ips.keys()) host_id = utils.get_connected_node_name(self.cli_opts) if host_id in nodes: nodes.remove(host_id) keyDumpParams = self.buildKvStoreKeyDumpParams( Consts.ALL_DB_MARKER) pub = client.getKvStoreKeyValsFiltered(keyDumpParams) kv_dict = self.dump_nodes_kvs(nodes, all_nodes_to_ips) for node in kv_dict: self.compare(pub.keyVals, kv_dict[node], host_id, node) else: nodes = list(all_nodes_to_ips.keys()) kv_dict = self.dump_nodes_kvs(nodes, all_nodes_to_ips) for our_node, other_node in combinations(kv_dict.keys(), 2): self.compare(kv_dict[our_node], kv_dict[other_node], our_node, other_node)
def run(self): resp = self.client.dump_all_with_filter(prefix=Consts.PREFIX_DB_MARKER) host_id = utils.get_connected_node_name(self.cli_opts) self.print_kvstore_nodes(resp, host_id)
def run(self): resp = self.client.dump_all_with_prefix(Consts.PREFIX_DB_MARKER) host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port) self.print_kvstore_nodes(resp, host_id)
def _run(self, client: OpenrCtrl.Client) -> None: keyDumpParams = self.buildKvStoreKeyDumpParams(Consts.PREFIX_DB_MARKER) resp = client.getKvStoreKeyValsFiltered(keyDumpParams) host_id = utils.get_connected_node_name(self.cli_opts) self.print_kvstore_nodes(resp, host_id)