def get_lldp_neighbors_detail(self, interface=''):
        """FTOS implementation of get_lldp_neighbors_detail."""
        if interface:
            command = "show lldp neighbors interface {} detail".format(
                interface)
        else:
            command = "show lldp neighbors detail"

        lldp_entries = self._send_command(command)
        lldp_entries = textfsm_extractor(self, 'show_lldp_neighbors_detail',
                                         lldp_entries)

        lldp = {}
        for idx, lldp_entry in enumerate(lldp_entries):
            # TODO: the current textfsm template keeps adding an empty entry at
            # the end of each interface and I couldn't fix it so at some point
            # it was just easier to get rid of these empty entries in code
            nonZero = False
            for key in lldp_entry.keys():
                # local_interface is set to Filldown so that is always filled
                if key == 'local_interface':
                    continue
                if len(lldp_entry[key].strip()) > 0:
                    nonZero = True
                    break
            if not nonZero:
                continue

            # get pretty interface name
            local_intf = canonical_interface_name(
                lldp_entry.pop('local_interface'))

            # cast some mac addresses
            for k in ['remote_port', 'remote_chassis_id']:
                if len(lldp_entry[k].strip()) > 0:
                    try:
                        lldp_entry[k] = mac(lldp_entry[k])
                    except AddrFormatError:
                        pass

            # transform capabilities
            for k in ['remote_system_capab', 'remote_system_enable_capab']:
                lldp_entry[k] = transform_lldp_capab(lldp_entry[k])

            # not implemented
            lldp_entry['parent_interface'] = u''

            lldp.setdefault(local_intf, [])
            lldp[local_intf].append(lldp_entry)

        return lldp
Beispiel #2
0
    def test_transform_lldp_capab(self, test_case):
        """Test transform_lldp_capab."""
        tests = [
            [
                'Bridge WLAN Access Point Router Station only',
                [
                    'bridge',
                    'wlan-access-point',
                    'router',
                    'station',
                ]
            ],
            ['Bridge Router', ['bridge', 'router']],
        ]

        for t in tests:
            out = transform_lldp_capab(t[0])
            assert out == t[1]

        return {}