Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T6045: Recreate show lldp detail views & improve remote port selection #3590

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions op-mode-definitions/lldp.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
</properties>
<command>${vyos_op_scripts_dir}/lldp.py show_neighbors</command>
<children>
<node name="detail">
<properties>
<help>Show extended detail for LLDP neighbors</help>
</properties>
<command>${vyos_op_scripts_dir}/lldp.py show_neighbors --detail</command>
</node>
<tagNode name="interface">
<properties>
<help>Show LLDP for specified interface</help>
Expand All @@ -21,6 +27,17 @@
</completionHelp>
</properties>
<command>${vyos_op_scripts_dir}/lldp.py show_neighbors --interface $5</command>
<children>
<node name="detail">
<properties>
<help>Show detailed LLDP for specified interface</help>
<completionHelp>
<script>${vyos_completion_dir}/list_interfaces</script>
</completionHelp>
</properties>
<command>${vyos_op_scripts_dir}/lldp.py show_neighbors --interface $5 --detail</command>
</node>
</children>
</tagNode>
</children>
</node>
Expand Down
23 changes: 17 additions & 6 deletions src/op_mode/lldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ def _get_formatted_output(raw_data):
tmp.append('')

# Remote interface
interface = jmespath.search('port.descr', values)
interface = None
if jmespath.search('port.id.type', values) == 'ifname':
# Remote peer has explicitly returned the interface name as the PortID
interface = jmespath.search('port.id.value', values)
if not interface:
interface = jmespath.search('port.descr', values)
if not interface:
interface = jmespath.search('port.id.value', values)
if not interface:
Expand All @@ -136,11 +141,17 @@ def _get_formatted_output(raw_data):

@_verify
def show_neighbors(raw: bool, interface: typing.Optional[str], detail: typing.Optional[bool]):
lldp_data = _get_raw_data(interface=interface, detail=detail)
if raw:
return lldp_data
else:
return _get_formatted_output(lldp_data)
if raw or not detail:
lldp_data = _get_raw_data(interface=interface, detail=detail)
if raw:
return lldp_data
else:
return _get_formatted_output(lldp_data)
else: # non-raw, detail
tmp = 'lldpcli -f text show neighbors details'
if interface:
tmp += f' ports {interface}'
return cmd(tmp)

if __name__ == "__main__":
try:
Expand Down
Loading