# py312
# requirements:
# pyeapi==1.0.4
import ssl
from typing import TypedDict
from urllib.parse import urlsplit
import pyeapi
class arista_eos(TypedDict):
host: str
username: str
password: str
port: int
verify_tls: bool
def main(auth: arista_eos, vrf: str = "all"):
"""
Get BGP Summary
BGP peers per VRF with their state (Established, Active...), ASN and prefix counts (show ip bgp summary vrf <vrf>).
"""
[result] = node(auth).run_commands([f"show ip bgp summary vrf {vrf or 'all'}"])
return result["vrfs"]
# host is an address or a URL (https://10.0.0.11:8443). pyeapi skips certificate checks unless it is given a context,
# so one is always passed: verifying, or not when the resource unticks verify_tls (EOS ships a self-signed cert).
def node(auth: arista_eos, timeout: float = 60):
url = urlsplit(auth["host"] if "://" in auth["host"] else f"https://{auth['host']}")
context = ssl.create_default_context()
if auth.get("verify_tls") is False:
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
return pyeapi.connect(
transport=url.scheme,
host=url.hostname,
port=url.port or auth.get("port") or None,
username=auth["username"],
password=auth["password"],
context=context,
timeout=timeout,
return_node=True,
)
Submitted by hugo989 4 hours ago