Пример #1
0
    def __init__(self):
        self.cfgdb_clients = {}
        self.db_clients = {}
        self.cfgdb = ConfigDBConnector()
        self.cfgdb.connect()
        self.cfgdb_pipe = ConfigDBPipeConnector()
        self.cfgdb_pipe.connect()
        self.db = SonicV2Connector(host="127.0.0.1")

        # Skip connecting to chassis databases in line cards
        self.db_list = list(self.db.get_db_list())
        if not device_info.is_supervisor():
            try:
                self.db_list.remove('CHASSIS_APP_DB')
                self.db_list.remove('CHASSIS_STATE_DB')
            except Exception:
                pass

        for db_id in self.db_list:
            self.db.connect(db_id)

        self.cfgdb_clients[constants.DEFAULT_NAMESPACE] = self.cfgdb
        self.db_clients[constants.DEFAULT_NAMESPACE] = self.db

        if multi_asic.is_multi_asic():
            self.ns_list = multi_asic_ns_choices()
            for ns in self.ns_list:
                self.cfgdb_clients[ns] = (
                    multi_asic.connect_config_db_for_ns(ns))
                self.db_clients[ns] = multi_asic.connect_to_all_dbs_for_ns(ns)
Пример #2
0
    def __init__(self):
        self.cfgdb_clients = {}
        self.db_clients = {}
        self.cfgdb = ConfigDBConnector()
        self.cfgdb.connect()
        self.db = SonicV2Connector(host="127.0.0.1")
        for db_id in self.db.get_db_list():
            self.db.connect(db_id)

        self.cfgdb_clients[constants.DEFAULT_NAMESPACE] = self.cfgdb
        self.db_clients[constants.DEFAULT_NAMESPACE] = self.db

        if multi_asic.is_multi_asic():
            self.ns_list = multi_asic_ns_choices()
            for ns in self.ns_list:
                self.cfgdb_clients[ns] = (
                    multi_asic.connect_config_db_for_ns(ns))
                self.db_clients[ns] = multi_asic.connect_to_all_dbs_for_ns(ns)
Пример #3
0
interfaces.add_command(portchannel.portchannel)

#
# transceiver group (show interfaces trasceiver ...)
#
@interfaces.group(cls=clicommon.AliasedGroup)
def transceiver():
    """Show SFP Transceiver information"""
    pass

@transceiver.command()
@click.argument('interfacename', required=False)
@click.option('-d', '--dom', 'dump_dom', is_flag=True, help="Also display Digital Optical Monitoring (DOM) data")
@click.option('--namespace', '-n', 'namespace', default=None, show_default=True,
              type=click.Choice(multi_asic_util.multi_asic_ns_choices()), help='Namespace name or all')
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def eeprom(interfacename, dump_dom, namespace, verbose):
    """Show interface transceiver EEPROM information"""

    ctx = click.get_current_context()

    cmd = "sfpshow eeprom"

    if dump_dom:
        cmd += " --dom"

    if interfacename is not None:
        interfacename = try_convert_interfacename_from_alias(ctx, interfacename)

        cmd += " -p {}".format(interfacename)
Пример #4
0
    clicommon.run_command(cmd, display_cmd=verbose)


@transceiver.command()
@click.argument('interfacename', required=False)
@click.option('-d',
              '--dom',
              'dump_dom',
              is_flag=True,
              help="Also display Digital Optical Monitoring (DOM) data")
@click.option('--namespace',
              '-n',
              'namespace',
              default=None,
              show_default=True,
              type=click.Choice(multi_asic_util.multi_asic_ns_choices()),
              help='Namespace name or all')
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def eeprom(interfacename, dump_dom, namespace, verbose):
    """Show interface transceiver EEPROM information"""

    ctx = click.get_current_context()

    cmd = "sfpshow eeprom"

    if dump_dom:
        cmd += " --dom"

    if interfacename is not None:
        interfacename = try_convert_interfacename_from_alias(
            ctx, interfacename)
Пример #5
0
import click
import utilities_common.cli as clicommon
import utilities_common.multi_asic as multi_asic_util

#
# 'flowcnt-trap' group ###
#

@click.group(cls=clicommon.AliasedGroup)
def flowcnt_trap():
    """Show trap flow counter related information"""
    pass

@flowcnt_trap.command()
@click.option('--verbose', is_flag=True, help="Enable verbose output")
@click.option('--namespace', '-n', 'namespace', default=None, type=click.Choice(multi_asic_util.multi_asic_ns_choices()), show_default=True, help='Namespace name or all')
def stats(verbose, namespace):
    """Show trap flow counter statistic"""
    cmd = "flow_counters_stat -t trap"
    if namespace is not None:
        cmd += " -n {}".format(namespace)
    clicommon.run_command(cmd, display_cmd=verbose)
Пример #6
0
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)