def get_bgp_summary_from_all_bgp_instances(af, namespace, display): device = multi_asic_util.MultiAsic(display, namespace) ctx = click.get_current_context() if af is constants.IPV4: vtysh_cmd = "show ip bgp summary json" key = 'ipv4Unicast' else: vtysh_cmd = "show bgp ipv6 summary json" key = 'ipv6Unicast' bgp_summary = {} cmd_output_json = {} for ns in device.get_ns_list_based_on_options(): cmd_output = run_bgp_command(vtysh_cmd, ns) try: cmd_output_json = json.loads(cmd_output) except ValueError: ctx.fail("bgp summary from bgp container not in json format") if key not in cmd_output_json: ctx.fail("bgp summary from bgp container in invalid format") device.current_namespace = ns process_bgp_summary_json(bgp_summary, cmd_output_json[key], device) return bgp_summary
def __init__(self, db=None): self.cli_mode = None self.addr_family = None self.res_type = None self.db = None self.cfgdb = db self.multi_asic = multi_asic_util.MultiAsic()
def __init__(self, namespace_option, display_option): self.teams = [] self.teamsraw = {} self.summary = {} self.err = None self.db = None self.multi_asic = multi_asic_util.MultiAsic(display_option, namespace_option)
def __init__( self, db=None, namespace=None, display=constants.DISPLAY_ALL ): self.db = None self.config_db = None self.multi_asic = multi_asic_util.MultiAsic( display, namespace, db ) self.table = [] self.all_ports = []
def mpls(ctx, interfacename, namespace, display): """Show Interface MPLS status""" #Edge case: Force show frontend interfaces on single asic if not (multi_asic.is_multi_asic()): if (display == 'frontend' or display == 'all' or display is None): display = None else: print("Error: Invalid display option command for single asic") return display = "all" if interfacename else display masic = multi_asic_util.MultiAsic(display_option=display, namespace_option=namespace) ns_list = masic.get_ns_list_based_on_options() intfs_data = {} intf_found = False for ns in ns_list: appl_db = multi_asic.connect_to_all_dbs_for_ns(namespace=ns) if interfacename is not None: interfacename = try_convert_interfacename_from_alias( ctx, interfacename) # Fetching data from appl_db for intfs keys = appl_db.keys(appl_db.APPL_DB, "INTF_TABLE:*") for key in keys if keys else []: tokens = key.split(":") ifname = tokens[1] # Skip INTF_TABLE entries with address information if len(tokens) != 2: continue if (interfacename is not None): if (interfacename != ifname): continue intf_found = True if (display != "all"): if ("Loopback" in ifname): continue if ifname.startswith( "Ethernet") and multi_asic.is_port_internal( ifname, ns): continue if ifname.startswith( "PortChannel") and multi_asic.is_port_channel_internal( ifname, ns): continue mpls_intf = appl_db.get_all(appl_db.APPL_DB, key) if 'mpls' not in mpls_intf or mpls_intf['mpls'] == 'disable': intfs_data.update({ifname: 'disable'}) else: intfs_data.update({ifname: mpls_intf['mpls']}) # Check if interface is valid if (interfacename is not None and not intf_found): ctx.fail('interface {} doesn`t exist'.format(interfacename)) header = ['Interface', 'MPLS State'] body = [] # Output name and alias for all interfaces for intf_name in natsorted(list(intfs_data.keys())): if clicommon.get_interface_naming_mode() == "alias": alias = clicommon.InterfaceAliasConverter().name_to_alias( intf_name) body.append([alias, intfs_data[intf_name]]) else: body.append([intf_name, intfs_data[intf_name]]) click.echo(tabulate(body, header))
def show_routes(args, namespace, display, verbose, ipver): import utilities_common.bgp_util as bgp_util """Show IPv4/IPV6 routing table""" filter_back_end = False if display is None: if multi_asic.is_multi_asic(): display = constants.DISPLAY_EXTERNAL filter_back_end = True else: if multi_asic.is_multi_asic(): if display not in multi_asic_util.multi_asic_display_choices(): print("dislay option '{}' is not a valid option.".format( display)) return else: if display == constants.DISPLAY_EXTERNAL: filter_back_end = True else: if display not in ['frontend', 'all']: print("dislay option '{}' is not a valid option.".format( display)) return device = multi_asic_util.MultiAsic(display, namespace) arg_strg = "" found_json = 0 found_other_parms = 0 ns_l = [] print_ns_str = False filter_by_ip = False asic_cnt = 0 try: ns_l = device.get_ns_list_based_on_options() except ValueError: print("namespace '{}' is not valid. valid name spaces are:\n{}".format( namespace, multi_asic_util.multi_asic_ns_choices())) return asic_cnt = len(ns_l) if asic_cnt > 1 and display == constants.DISPLAY_ALL: print_ns_str = True if namespace is not None: if not multi_asic.is_multi_asic(): print( "namespace option is not applicable for non-multi-asic platform" ) return # build the filter set only if necessary if filter_back_end: back_end_intf_set = multi_asic.get_back_end_interface_set() else: back_end_intf_set = None # get all the other arguments except json that needs to be the last argument of the cmd if present # For Multi-ASIC platform the support for combining routes will be supported for "show ip/v6 route" # and optionally with specific IP address as parameter and the json option. If any other option is # specified, the handling will always be handled by the specific namespace FRR. for arg in args: arg_strg += str(arg) + " " if str(arg) == "json": found_json = 1 else: try: filter_by_ip = ipaddress.ip_network(arg) except ValueError: # Not ip address just ignore it found_other_parms = 1 if multi_asic.is_multi_asic(): if not found_json and not found_other_parms: arg_strg += "json" combined_route = {} for ns in ns_l: # Need to add "ns" to form bgpX so it is sent to the correct bgpX docker to handle the request # If not MultiASIC, skip namespace argument cmd = "show {} route {}".format(ipver, arg_strg) if multi_asic.is_multi_asic(): output = bgp_util.run_bgp_show_command(cmd, ns) else: output = bgp_util.run_bgp_show_command(cmd) print("{}".format(output)) return # in case no output or something went wrong with user specified cmd argument(s) error it out # error from FRR always start with character "%" if output == "": return if output[0] == "%": # remove the "json" keyword that was added by this handler to show original cmd user specified json_str = output[-5:-1] if json_str == "json": error_msg = output[:-5] else: error_msg = output print(error_msg) return # Multi-asic show ip route with additional parms are handled by going to FRR directly and get those outputs from each namespace if found_other_parms: print("{}:".format(ns)) print(output) continue route_info = json.loads(output) if filter_back_end or print_ns_str: # clean up the dictionary to remove all the nexthops that are back-end interface process_route_info(route_info, device, filter_back_end, print_ns_str, asic_cnt, ns, combined_route, back_end_intf_set) else: combined_route = route_info if not combined_route: return if not found_json: #print out the header if this is not a json request if not filter_by_ip: print_show_ip_route_hdr() if print_ns_str: for name_space, ns_route in sorted(combined_route.items()): print("{}:".format(name_space)) print_ip_routes(ns_route, filter_by_ip) else: print_ip_routes(combined_route, filter_by_ip) else: new_string = json.dumps(combined_route, sort_keys=True, indent=4) print(new_string)