Ejemplo n.º 1
0
    def is_object_internal(self, object_type, cli_object):
        '''
        The function checks if a CLI object is internal and returns true or false.
        Internal objects are port or portchannel which are connected to other
        ports or portchannels within a multi ASIC device.

        For single asic, this function is not applicable
        '''
        if object_type == constants.PORT_OBJ:
            return multi_asic.is_port_internal(cli_object)
        elif object_type == constants.PORT_CHANNEL_OBJ:
            return multi_asic.is_port_channel_internal(cli_object)
        elif object_type == constants.BGP_NEIGH_OBJ:
            return multi_asic.is_bgp_session_internal(cli_object)
Ejemplo n.º 2
0
 def get_po_names(self):
     '''
         Collect configured lag interface names
     '''
     for ns in NAMESPACE_LIST:
         rt, out, err = self.module.run_command("sonic-cfggen -m /etc/sonic/minigraph.xml {} -v \"PORTCHANNEL.keys() | join(' ')\"".format('-n ' + ns if ns else ''))
         if rt != 0:
             fail_msg="Command to retrieve portchannel names failed return=%d, out=%s, err=%s" %(rt, out, err)
             self.module.fail_json(msg=fail_msg)
         else:
             for po in out.split():
                 if 'multi_asic' in sys.modules and multi_asic.is_port_channel_internal(po):
                     continue
                 self.lag_names[po] = ns
     return
Ejemplo n.º 3
0
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))