From 6fcf8ca837092c2740e3afbc3c80f013118a908f Mon Sep 17 00:00:00 2001 From: thatmattlove Date: Mon, 26 Dec 2022 16:24:24 -0500 Subject: [PATCH] Add OpenBGPD support, closes #206 --- hyperglass/constants.py | 2 + hyperglass/defaults/directives/openbgpd.py | 103 +++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 hyperglass/defaults/directives/openbgpd.py diff --git a/hyperglass/constants.py b/hyperglass/constants.py index b04ea11..561f501 100644 --- a/hyperglass/constants.py +++ b/hyperglass/constants.py @@ -78,10 +78,12 @@ SCRAPE_HELPERS = { DRIVER_MAP = { "bird": "netmiko", "frr": "netmiko", + "openbgpd": "netmiko", "http": "hyperglass_http_client", } LINUX_PLATFORMS = ( "frr", "bird", + "openbgpd", ) diff --git a/hyperglass/defaults/directives/openbgpd.py b/hyperglass/defaults/directives/openbgpd.py new file mode 100644 index 0000000..34836de --- /dev/null +++ b/hyperglass/defaults/directives/openbgpd.py @@ -0,0 +1,103 @@ +"""Default FRRouting Directives.""" + +# Project +from hyperglass.models.directive import Rule, Text, BuiltinDirective + +__all__ = ( + "OpenBGPD_BGPASPath", + "OpenBGPD_BGPCommunity", + "OpenBGPD_BGPRoute", + "OpenBGPD_Ping", + "OpenBGPD_Traceroute", +) + +OpenBGPD_BGPRoute = BuiltinDirective( + id="__hyperglass_openbgpd_bgp_route__", + name="BGP Route", + rules=[ + Rule( + condition="0.0.0.0/0", + action="permit", + command="bgpctl show rib inet {target}", + ), + Rule( + condition="::/0", + action="permit", + command="bgpctl show rib inet6 {target}", + ), + ], + field=Text(description="IP Address, Prefix, or Hostname"), + platforms=["openbgpd"], +) + +OpenBGPD_BGPASPath = BuiltinDirective( + id="__hyperglass_openbgpd_bgp_aspath__", + name="BGP AS Path", + rules=[ + Rule( + condition="*", + action="permit", + commands=[ + "bgpctl show rib inet as {target}", + "bgpctl show rib inet6 as {target}", + ], + ) + ], + field=Text(description="AS Path Regular Expression"), + platforms=["openbgpd"], +) + +OpenBGPD_BGPCommunity = BuiltinDirective( + id="__hyperglass_openbgpd_bgp_community__", + name="BGP Community", + rules=[ + Rule( + condition="*", + action="permit", + commands=[ + "bgpctl show rib inet community {target}", + "bgpctl show rib inet6 community {target}", + ], + ) + ], + field=Text(description="BGP Community String"), + platforms=["openbgpd"], +) + +OpenBGPD_Ping = BuiltinDirective( + id="__hyperglass_openbgpd_ping__", + name="Ping", + rules=[ + Rule( + condition="0.0.0.0/0", + action="permit", + command="ping -4 -c 5 -I {source4} {target}", + ), + Rule( + condition="::/0", + action="permit", + command="ping -6 -c 5 -I {source6} {target}", + ), + ], + field=Text(description="IP Address, Prefix, or Hostname"), + platforms=["openbgpd"], +) + +OpenBGPD_Traceroute = BuiltinDirective( + id="__hyperglass_openbgpd_traceroute__", + name="Traceroute", + rules=[ + Rule( + condition="0.0.0.0/0", + action="permit", + command="traceroute -4 -w 1 -q 1 -s {source4} {target}", + ), + Rule( + condition="::/0", + action="permit", + command="traceroute -6 -w 1 -q 1 -s {source6} {target}", + ), + ], + field=Text(description="IP Address, Prefix, or Hostname"), + platforms=["openbgpd"], +)