diff options
author | Benjamin M. Hughes <bmhughes@bmhughes.co.uk> | 2020-10-18 15:29:04 +0100 |
---|---|---|
committer | Benjamin M. Hughes <bmhughes@bmhughes.co.uk> | 2020-10-18 15:29:04 +0100 |
commit | b39d623170377b2e99fd7e88b627afea71e4d00c (patch) | |
tree | c0994a63ef454a2fb5b1c34ba076ae0be48113b1 /src | |
parent | e667e06cffe42744c8cc71be02b080e1bccf241b (diff) | |
download | vyos-1x-b39d623170377b2e99fd7e88b627afea71e4d00c.tar.gz vyos-1x-b39d623170377b2e99fd7e88b627afea71e4d00c.zip |
op-mode: lldp: T2993: Fix 'show lldp neighbors'
'show lldp neighbors' fails with:
Traceback (most recent call last):
File "./lldp_op.py", line 122, in <module>
config_text = tmpl.render(parse_data(neighbors))
File "./lldp_op.py", line 51, in parse_data
for local_if, values in tmp.items():
AttributeError: 'str' object has no attribute 'items'
`parse_data` was expecting data to be provided as a dict within an array
which doesn't match the format from the parsed json output of lldpcli.
Change `parse_data` and `main` to use a dict alone for passing interface
neighbors for rendering.
Diffstat (limited to 'src')
-rwxr-xr-x | src/op_mode/lldp_op.py | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/src/op_mode/lldp_op.py b/src/op_mode/lldp_op.py index 06958c605..5f86ad7a5 100755 --- a/src/op_mode/lldp_op.py +++ b/src/op_mode/lldp_op.py @@ -47,32 +47,31 @@ def get_neighbors(): def parse_data(data): output = [] - for tmp in data: - for local_if, values in tmp.items(): - for chassis, c_value in values.get('chassis', {}).items(): - capabilities = c_value['capability'] - if isinstance(capabilities, dict): - capabilities = [capabilities] - - cap = '' - for capability in capabilities: - if capability['enabled']: - if capability['type'] == 'Router': - cap += 'R' - if capability['type'] == 'Bridge': - cap += 'B' - if capability['type'] == 'Wlan': - cap += 'W' - if capability['type'] == 'Station': - cap += 'S' - if capability['type'] == 'Repeater': - cap += 'r' - if capability['type'] == 'Telephone': - cap += 'T' - if capability['type'] == 'Docsis': - cap += 'D' - if capability['type'] == 'Other': - cap += 'O' + for local_if, values in data.items(): + for chassis, c_value in values.get('chassis', {}).items(): + capabilities = c_value['capability'] + if isinstance(capabilities, dict): + capabilities = [capabilities] + + cap = '' + for capability in capabilities: + if capability['enabled']: + if capability['type'] == 'Router': + cap += 'R' + if capability['type'] == 'Bridge': + cap += 'B' + if capability['type'] == 'Wlan': + cap += 'W' + if capability['type'] == 'Station': + cap += 'S' + if capability['type'] == 'Repeater': + cap += 'r' + if capability['type'] == 'Telephone': + cap += 'T' + if capability['type'] == 'Docsis': + cap += 'D' + if capability['type'] == 'Other': + cap += 'O' remote_if = 'Unknown' @@ -109,10 +108,9 @@ if __name__ == '__main__': if args.all: neighbors = tmp['lldp']['interface'] elif args.interface: - neighbors = [] - for neighbor in tmp['lldp']['interface']: - if args.interface in neighbor: - neighbors.append(neighbor) + neighbors = dict() + if args.interface in tmp['lldp']['interface']: + neighbors[args.interface] = tmp['lldp']['interface'][args.interface] else: parser.print_help() |