mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
cleanup
This commit is contained in:
1
hyperglass/.gitignore
vendored
1
hyperglass/.gitignore
vendored
@@ -6,6 +6,5 @@ gunicorn_config.py
|
|||||||
gunicorn_dev_config.py
|
gunicorn_dev_config.py
|
||||||
test.py
|
test.py
|
||||||
__pycache__/
|
__pycache__/
|
||||||
parsing/
|
|
||||||
*_old
|
*_old
|
||||||
certs/
|
certs/
|
||||||
|
@@ -165,7 +165,7 @@ def build_ui():
|
|||||||
ClickException: Raised on any errors.
|
ClickException: Raised on any errors.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from hyperglass.compat import aiorun
|
from hyperglass.compat._asyncio import aiorun
|
||||||
from hyperglass.util import build_frontend
|
from hyperglass.util import build_frontend
|
||||||
from hyperglass.configuration import params, frontend_params, CONFIG_PATH
|
from hyperglass.configuration import params, frontend_params, CONFIG_PATH
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
|
@@ -11,7 +11,7 @@ from pydantic import StrictInt, StrictStr, validator
|
|||||||
|
|
||||||
# Project
|
# Project
|
||||||
from hyperglass.util import log, clean_name
|
from hyperglass.util import log, clean_name
|
||||||
from hyperglass.constants import Supported
|
from hyperglass.constants import SCRAPE_HELPERS, TRANSPORT_REST, TRANSPORT_SCRAPE
|
||||||
from hyperglass.exceptions import ConfigError, UnsupportedDevice
|
from hyperglass.exceptions import ConfigError, UnsupportedDevice
|
||||||
from hyperglass.configuration.models.ssl import Ssl
|
from hyperglass.configuration.models.ssl import Ssl
|
||||||
from hyperglass.configuration.models.vrfs import Vrf, Info
|
from hyperglass.configuration.models.vrfs import Vrf, Info
|
||||||
@@ -65,8 +65,12 @@ class Router(HyperglassModel):
|
|||||||
Returns:
|
Returns:
|
||||||
{str} -- Valid NOS
|
{str} -- Valid NOS
|
||||||
"""
|
"""
|
||||||
if not Supported.is_supported(value):
|
if value in SCRAPE_HELPERS.keys():
|
||||||
raise UnsupportedDevice(f'"{value}" device type is not supported.')
|
value = SCRAPE_HELPERS[value]
|
||||||
|
|
||||||
|
if value not in (*TRANSPORT_REST, *TRANSPORT_SCRAPE):
|
||||||
|
raise UnsupportedDevice('NOS "{n}" is not supported.', n=value)
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@validator("name")
|
@validator("name")
|
||||||
|
@@ -4,7 +4,7 @@ import sys
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
__name__ = "hyperglass"
|
__name__ = "hyperglass"
|
||||||
__version__ = "1.0.0-beta.17"
|
__version__ = "1.0.0-beta.18"
|
||||||
__author__ = "Matt Love"
|
__author__ = "Matt Love"
|
||||||
__copyright__ = f"Copyright {datetime.now().year} Matthew Love"
|
__copyright__ = f"Copyright {datetime.now().year} Matthew Love"
|
||||||
__license__ = "BSD 3-Clause Clear License"
|
__license__ = "BSD 3-Clause Clear License"
|
||||||
@@ -17,6 +17,8 @@ protocol_map = {80: "http", 8080: "http", 443: "https", 8443: "https"}
|
|||||||
|
|
||||||
TARGET_FORMAT_SPACE = ("huawei", "huawei_vrpv8")
|
TARGET_FORMAT_SPACE = ("huawei", "huawei_vrpv8")
|
||||||
|
|
||||||
|
TARGET_JUNIPER_ASPATH = ("juniper", "juniper_junos")
|
||||||
|
|
||||||
LOG_FMT = (
|
LOG_FMT = (
|
||||||
"<lvl><b>[{level}]</b> {time:YYYYMMDD} {time:HH:mm:ss} <lw>|</lw> {name}<lw>:</lw>"
|
"<lvl><b>[{level}]</b> {time:YYYYMMDD} {time:HH:mm:ss} <lw>|</lw> {name}<lw>:</lw>"
|
||||||
"<b>{line}</b> <lw>|</lw> {function}</lvl> <lvl><b>→</b></lvl> {message}"
|
"<b>{line}</b> <lw>|</lw> {function}</lvl> <lvl><b>→</b></lvl> {message}"
|
||||||
@@ -260,6 +262,11 @@ TRANSPORT_SCRAPE = (
|
|||||||
"oneaccess_oneos",
|
"oneaccess_oneos",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SCRAPE_HELPERS = {
|
||||||
|
"junos": "juniper",
|
||||||
|
"ios": "cisco_ios",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Supported:
|
class Supported:
|
||||||
"""Define items supported by hyperglass.
|
"""Define items supported by hyperglass.
|
||||||
|
@@ -1,126 +0,0 @@
|
|||||||
---
|
|
||||||
# arista:
|
|
||||||
# ipv4_default:
|
|
||||||
# bgp_aspath: show ip bgp regexp {target}
|
|
||||||
# bgp_community: show ip bgp community {target}
|
|
||||||
# bgp_route: show ip bgp {target}
|
|
||||||
# ping: ping ip {target} source {source}
|
|
||||||
# traceroute: traceroute ip {target} source {source}
|
|
||||||
# ipv4_vpn:
|
|
||||||
# bgp_aspath: show ip bgp regexp {target} vrf {vrf}
|
|
||||||
# bgp_community: show ip bgp community {target} vrf {vrf}
|
|
||||||
# bgp_route: show ip bgp {target} vrf {vrf}
|
|
||||||
# ping: ping vrf {vrf} ip {target} source {source}
|
|
||||||
# traceroute: traceroute vrf {vrf} ip {target} source {source}
|
|
||||||
# ipv6_default:
|
|
||||||
# bgp_aspath: show ipv6 bgp regexp {target}
|
|
||||||
# bgp_community: show ipv6 bgp community {target}
|
|
||||||
# bgp_route: show ipv6 bgp {target}
|
|
||||||
# ping: ping ipv6 {target} source {source}
|
|
||||||
# traceroute: traceroute ipv6 {target} source {source}
|
|
||||||
# ipv6_vpn:
|
|
||||||
# bgp_aspath: show ipv6 bgp regexp {target} vrf {vrf}
|
|
||||||
# bgp_community: show ipv6 bgp community {target} vrf {vrf}
|
|
||||||
# bgp_route: show ipv6 bgp {target} vrf {vrf}
|
|
||||||
# ping: ping vrf {vrf} ipv6 {target} source {source}
|
|
||||||
# traceroute: traceroute vrf {vrf} ipv6 {target} source {source}
|
|
||||||
# cisco_ios:
|
|
||||||
# ipv4_default:
|
|
||||||
# bgp_aspath: show bgp ipv4 unicast quote-regexp "{target}"
|
|
||||||
# bgp_community: show bgp ipv4 unicast community {target}
|
|
||||||
# bgp_route: show bgp ipv4 unicast {target} | exclude pathid:|Epoch
|
|
||||||
# ping: ping {target} repeat 5 source {source}
|
|
||||||
# traceroute: traceroute {target} timeout 1 probe 2 source {source}
|
|
||||||
# ipv4_vpn:
|
|
||||||
# bgp_aspath: show bgp vpnv4 unicast vrf {vrf} quote-regexp "{target}"
|
|
||||||
# bgp_community: show bgp vpnv4 unicast vrf {vrf} community {target}
|
|
||||||
# bgp_route: show bgp vpnv4 unicast vrf {vrf} {target}
|
|
||||||
# ping: ping vrf {vrf} {target} repeat 5 source {source}
|
|
||||||
# traceroute: traceroute vrf {vrf} {target} timeout 1 probe 2 source {source}
|
|
||||||
# ipv6_default:
|
|
||||||
# bgp_aspath: show bgp ipv6 unicast quote-regexp "{target}"
|
|
||||||
# bgp_community: show bgp ipv6 unicast community {target}
|
|
||||||
# bgp_route: show bgp ipv6 unicast {target} | exclude pathid:|Epoch
|
|
||||||
# ping: ping ipv6 {target} repeat 5 source {source}
|
|
||||||
# traceroute: traceroute ipv6 {target} timeout 1 probe 2 source {source}
|
|
||||||
# ipv6_vpn:
|
|
||||||
# bgp_aspath: show bgp vpnv6 unicast vrf {vrf} quote-regexp "{target}"
|
|
||||||
# bgp_community: show bgp vpnv6 unicast vrf {vrf} community {target}
|
|
||||||
# bgp_route: show bgp vpnv6 unicast vrf {vrf} {target}
|
|
||||||
# ping: ping vrf {vrf} {target} repeat 5 source {source}
|
|
||||||
# traceroute: traceroute vrf {vrf} {target} timeout 1 probe 2 source {source}
|
|
||||||
# cisco_xr:
|
|
||||||
# ipv4_default:
|
|
||||||
# bgp_aspath: show bgp ipv4 unicast regexp {target} | utility egrep -v \\(BGP |Table |Non-stop\\)
|
|
||||||
# bgp_community: show bgp ipv4 unicast community {target} | utility egrep -v \\(BGP |Table |Non-stop\\)
|
|
||||||
# bgp_route: show bgp ipv4 unicast {target} | util egrep \\(BGP routing table entry|Path \\#|aggregated by|Origin |Community:|validity| from \\)
|
|
||||||
# ping: ping ipv4 {target} count 5 source {source}
|
|
||||||
# traceroute: traceroute ipv4 {target} timeout 1 probe 2 source {source}
|
|
||||||
# ipv4_vpn:
|
|
||||||
# bgp_aspath: show bgp vpnv4 unicast vrf {vrf} regexp {target} | utility egrep -v \\(BGP |Table |Non-stop\\)
|
|
||||||
# bgp_community: show bgp vpnv4 unicast vrf {vrf} community {target} | utility egrep -v \\(BGP |Table |Non-stop\\)
|
|
||||||
# bgp_route: show bgp vpnv4 unicast vrf {vrf} {target} | util egrep \\(BGP routing table entry|Path \\#|aggregated by|Origin |Community:|validity| from \\)
|
|
||||||
# ping: ping vrf {vrf} {target} count 5 source {source}
|
|
||||||
# traceroute: traceroute vrf {vrf} {target} timeout 1 probe 2 source {source}
|
|
||||||
# ipv6_default:
|
|
||||||
# bgp_aspath: show bgp ipv6 unicast regexp {target} | utility egrep -v \\(BGP |Table |Non-stop\\)
|
|
||||||
# bgp_community: show bgp ipv6 unicast community {target} | utility egrep -v \\(BGP |Table |Non-stop\\)
|
|
||||||
# bgp_route: show bgp ipv6 unicast {target} | util egrep \\(BGP routing table entry|Path \\#|aggregated by|Origin |Community:|validity| from \\)
|
|
||||||
# ping: ping ipv6 {target} count 5 source {source}
|
|
||||||
# traceroute: traceroute ipv6 {target} timeout 1 probe 2 source {source}
|
|
||||||
# ipv6_vpn:
|
|
||||||
# bgp_aspath: show bgp vpnv6 unicast vrf {vrf} regexp {target} | utility egrep -v \\(BGP |Table |Non-stop\\)
|
|
||||||
# bgp_community: show bgp vpnv6 unicast vrf {vrf} community {target} | utility egrep -v \\(BGP |Table |Non-stop\\)
|
|
||||||
# bgp_route: show bgp vpnv6 unicast vrf {vrf} {target} | util egrep \\(BGP routing table entry|Path \\#|aggregated by|Origin |Community:|validity| from \\)
|
|
||||||
# ping: ping vrf {vrf} {target} count 5 source {source}
|
|
||||||
# traceroute: traceroute vrf {vrf} {target} timeout 1 probe 2 source {source}
|
|
||||||
# huawei:
|
|
||||||
# ipv4_default:
|
|
||||||
# bgp_aspath: display bgp routing-table regular-expression {target}
|
|
||||||
# bgp_community: display bgp routing-table regular-expression {target}
|
|
||||||
# bgp_route: display bgp routing-table {target}
|
|
||||||
# ping: ping -c 5 -a {source} {target}
|
|
||||||
# traceroute: tracert -q 2 -f 1 -a {source} {target}
|
|
||||||
# ipv4_vpn:
|
|
||||||
# bgp_aspath: display bgp vpnv4 vpn-instance {vrf} routing-table regular-expression {target}
|
|
||||||
# bgp_community: display bgp vpnv4 vpn-instance {vrf} routing-table regular-expression {target}
|
|
||||||
# bgp_route: display bgp vpnv4 vpn-instance {vrf} routing-table {target}
|
|
||||||
# ping: ping -vpn-instance {vrf} -c 5 -a {source} {target}
|
|
||||||
# traceroute: tracert -q 2 -f 1 -vpn-instance {vrf} -a {source} {target}
|
|
||||||
# ipv6_default:
|
|
||||||
# bgp_aspath: display bgp ipv6 routing-table regular-expression {target}
|
|
||||||
# bgp_community: display bgp ipv6 routing-table community {target}
|
|
||||||
# bgp_route: display bgp ipv6 routing-table {target}
|
|
||||||
# ping: ping ipv6 -c 5 -a {source} {target}
|
|
||||||
# traceroute: tracert ipv6 -q 2 -f 1 -a {source} {target}
|
|
||||||
# ipv6_vpn:
|
|
||||||
# bgp_aspath: display bgp vpnv6 vpn-instance {vrf} routing-table regular-expression {target}
|
|
||||||
# bgp_community: display bgp vpnv6 vpn-instance {vrf} routing-table regular-expression {target}
|
|
||||||
# bgp_route: display bgp vpnv6 vpn-instance {vrf} routing-table {target}
|
|
||||||
# ping: ping vpnv6 vpn-instance {vrf} -c 5 -a {source} {target}
|
|
||||||
# traceroute: tracert -q 2 -f 1 vpn-instance {vrf} -a {source} {target}
|
|
||||||
# juniper:
|
|
||||||
# ipv4_default:
|
|
||||||
# bgp_aspath: show route protocol bgp table inet.0 aspath-regex "{target}"
|
|
||||||
# bgp_community: show route protocol bgp table inet.0 community {target}
|
|
||||||
# bgp_route: show route protocol bgp table inet.0 {target} detail
|
|
||||||
# ping: ping inet {target} count 5 source {source}
|
|
||||||
# traceroute: traceroute inet {target} wait 1 source {source}
|
|
||||||
# ipv4_vpn:
|
|
||||||
# bgp_aspath: show route protocol bgp table {vrf}.inet.0 aspath-regex "{target}"
|
|
||||||
# bgp_community: show route protocol bgp table {vrf}.inet.0 community {target}
|
|
||||||
# bgp_route: show route protocol bgp table {vrf}.inet.0 {target} detail
|
|
||||||
# ping: ping inet routing-instance {vrf} {target} count 5 source {source}
|
|
||||||
# traceroute: traceroute inet routing-instance {vrf} {target} wait 1 source {source}
|
|
||||||
# ipv6_default:
|
|
||||||
# bgp_aspath: show route protocol bgp table inet6.0 aspath-regex "{target}"
|
|
||||||
# bgp_community: show route protocol bgp table inet6.0 community {target}
|
|
||||||
# bgp_route: show route protocol bgp table inet6.0 {target} detail
|
|
||||||
# ping: ping inet6 {target} count 5 source {source}
|
|
||||||
# traceroute: traceroute inet6 {target} wait 1 source {source}
|
|
||||||
# ipv6_vpn:
|
|
||||||
# bgp_aspath: show route protocol bgp table {vrf}.inet6.0 aspath-regex "{target}"
|
|
||||||
# bgp_community: show route protocol bgp table {vrf}.inet6.0 community {target}
|
|
||||||
# bgp_route: show route protocol bgp table {vrf}.inet6.0 {target} detail
|
|
||||||
# ping: ping inet6 routing-instance {vrf} {target} count 5 source {source}
|
|
||||||
# traceroute: traceroute inet6 routing-instance {vrf} {target} wait 1 source {source}
|
|
||||||
|
@@ -7,14 +7,16 @@ hyperglass API modules.
|
|||||||
|
|
||||||
# Standard Library
|
# Standard Library
|
||||||
import re
|
import re
|
||||||
|
import json as _json
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
# Third Party
|
|
||||||
import ujson
|
|
||||||
|
|
||||||
# Project
|
# Project
|
||||||
from hyperglass.util import log
|
from hyperglass.util import log
|
||||||
from hyperglass.constants import TRANSPORT_REST, TARGET_FORMAT_SPACE
|
from hyperglass.constants import (
|
||||||
|
TRANSPORT_REST,
|
||||||
|
TARGET_FORMAT_SPACE,
|
||||||
|
TARGET_JUNIPER_ASPATH,
|
||||||
|
)
|
||||||
from hyperglass.configuration import commands
|
from hyperglass.configuration import commands
|
||||||
|
|
||||||
|
|
||||||
@@ -72,6 +74,20 @@ class Construct:
|
|||||||
if v is not None
|
if v is not None
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# For devices that follow Juniper's AS_PATH regex standards,
|
||||||
|
# filter out Cisco-style special characters.
|
||||||
|
|
||||||
|
if self.device.nos in TARGET_JUNIPER_ASPATH:
|
||||||
|
query = str(self.query_data.query_target)
|
||||||
|
asns = re.findall(r"\d+", query)
|
||||||
|
if bool(re.match(r"^\_", query)):
|
||||||
|
# Replace `_65000` with `.* 65000`
|
||||||
|
asns.insert(0, r".*")
|
||||||
|
if bool(re.match(r".*(\_)$", query)):
|
||||||
|
# Replace `65000_` with `65000 .*`
|
||||||
|
asns.append(r".*")
|
||||||
|
self.target = " ".join(asns)
|
||||||
|
|
||||||
def json(self, afi):
|
def json(self, afi):
|
||||||
"""Return JSON version of validated query for REST devices.
|
"""Return JSON version of validated query for REST devices.
|
||||||
|
|
||||||
@@ -82,7 +98,7 @@ class Construct:
|
|||||||
{str} -- JSON query string
|
{str} -- JSON query string
|
||||||
"""
|
"""
|
||||||
log.debug("Building JSON query for {q}", q=repr(self.query_data))
|
log.debug("Building JSON query for {q}", q=repr(self.query_data))
|
||||||
return ujson.dumps(
|
return _json.dumps(
|
||||||
{
|
{
|
||||||
"query_type": self.query_data.query_type,
|
"query_type": self.query_data.query_type,
|
||||||
"vrf": self.query_data.query_vrf.name,
|
"vrf": self.query_data.query_vrf.name,
|
||||||
|
Reference in New Issue
Block a user