mirror of
https://github.com/napalm-automation-community/napalm-vyos.git
synced 2026-09-23 12:41:16 +00:00
fixes functions and adds cli support
- implements cli - fixes get_bgp_neighbors #44 - fixes get_lldp_neighbors(multiple neighbors)
This commit is contained in:
@@ -472,12 +472,14 @@ class VyOSDriver(NetworkDriver):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
output = self.device.send_command("show ip bgp summary")
|
output = self.device.send_command("show ip bgp summary")
|
||||||
output = output.split("\n")
|
match = re.search(
|
||||||
|
r"bgp router identifier (\d+\.\d+\.\d+\.\d+), local as number (\d+) vrf-id (\d+)",
|
||||||
match = re.search(r".* router identifier (\d+\.\d+\.\d+\.\d+), local AS number (\d+)",
|
output,
|
||||||
output[0])
|
re.MULTILINE | re.IGNORECASE
|
||||||
|
)
|
||||||
if not match:
|
if not match:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
router_id = match.group(1)
|
router_id = match.group(1)
|
||||||
local_as = int(match.group(2))
|
local_as = int(match.group(2))
|
||||||
|
|
||||||
@@ -486,13 +488,24 @@ class VyOSDriver(NetworkDriver):
|
|||||||
bgp_neighbor_data["global"]["router_id"] = router_id
|
bgp_neighbor_data["global"]["router_id"] = router_id
|
||||||
bgp_neighbor_data["global"]["peers"] = {}
|
bgp_neighbor_data["global"]["peers"] = {}
|
||||||
|
|
||||||
# delete the header and empty element
|
re_neighbor = re.compile(
|
||||||
bgp_info = [i.strip() for i in output[6:-2] if i]
|
'^([\w\d:\.]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\w+)'
|
||||||
|
)
|
||||||
|
for bgp_line in output.split("\n"):
|
||||||
|
match = re_neighbor.search(bgp_line)
|
||||||
|
if not match:
|
||||||
|
continue
|
||||||
|
|
||||||
for i in bgp_info:
|
peer_id = match.group(1)
|
||||||
if len(i) > 0:
|
bgp_version = match.group(2)
|
||||||
peer_id, bgp_version, remote_as, msg_rcvd, msg_sent, table_version, \
|
remote_as = match.group(3)
|
||||||
in_queue, out_queue, up_time, state_prefix = i.split()
|
msg_rcvd = match.group(4)
|
||||||
|
msg_sent = match.group(5)
|
||||||
|
table_version = match.group(6)
|
||||||
|
in_queue = match.group(7)
|
||||||
|
out_queue = match.group(8)
|
||||||
|
up_time = match.group(9)
|
||||||
|
state_prefix = match.group(10)
|
||||||
|
|
||||||
is_enabled = "(Admin)" not in state_prefix
|
is_enabled = "(Admin)" not in state_prefix
|
||||||
|
|
||||||
@@ -586,27 +599,28 @@ class VyOSDriver(NetworkDriver):
|
|||||||
return uptime
|
return uptime
|
||||||
|
|
||||||
def get_lldp_neighbors(self):
|
def get_lldp_neighbors(self):
|
||||||
# Multiple neighbors per port are not implemented
|
ret = []
|
||||||
# The show lldp neighbors commands lists port descriptions, not IDs
|
|
||||||
output = self.device.send_command("show lldp neighbors detail")
|
output = self.device.send_command("show lldp neighbors detail")
|
||||||
pattern = r'''(?s)Interface: +(?P<interface>\S+), [^\n]+
|
regex = '{},.+?{}.+?{}'.format(
|
||||||
.+?
|
"Interface:\s+(\S+)",
|
||||||
+SysName: +(?P<hostname>\S+)
|
"SysName:\s+(\S+)",
|
||||||
.+?
|
"PortID:\s+ifname (\S+)"
|
||||||
+PortID: +ifname (?P<port>\S+)'''
|
)
|
||||||
|
re_lldp = re.compile(
|
||||||
|
regex,
|
||||||
|
re.MULTILINE|re.DOTALL
|
||||||
|
)
|
||||||
|
match = re_lldp.findall(output)
|
||||||
|
if not match:
|
||||||
|
return []
|
||||||
|
|
||||||
def _get_interface(match):
|
for ocurrence in match:
|
||||||
return [
|
ret.append({
|
||||||
{
|
'hostname' : ocurrence[0],
|
||||||
'hostname': match.group('hostname'),
|
'port' : ocurrence[1],
|
||||||
'port': match.group('port'),
|
'interface' : ocurrence[2]
|
||||||
}
|
})
|
||||||
]
|
return ret
|
||||||
|
|
||||||
return {
|
|
||||||
match.group('interface'): _get_interface(match)
|
|
||||||
for match in re.finditer(pattern, output)
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_interfaces_counters(self):
|
def get_interfaces_counters(self):
|
||||||
# 'rx_unicast_packet', 'rx_broadcast_packets', 'tx_unicast_packets',
|
# 'rx_unicast_packet', 'rx_broadcast_packets', 'tx_unicast_packets',
|
||||||
@@ -958,3 +972,17 @@ class VyOSDriver(NetworkDriver):
|
|||||||
config = config[:config.rfind('\n')]
|
config = config[:config.rfind('\n')]
|
||||||
self.device.exit_config_mode()
|
self.device.exit_config_mode()
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
def cli(self, commands):
|
||||||
|
cli_output = {}
|
||||||
|
|
||||||
|
if not isinstance(commands, list):
|
||||||
|
raise TypeError("Please enter a valid list of commands!")
|
||||||
|
|
||||||
|
for command in commands:
|
||||||
|
try:
|
||||||
|
cli_output[command] = self.device.send_command(command)
|
||||||
|
except Exception:
|
||||||
|
cli_output[command] = 'error running command'
|
||||||
|
|
||||||
|
return cli_output
|
||||||
|
|||||||
Reference in New Issue
Block a user