diff --git a/hyperglass/.gitignore b/hyperglass/.gitignore
index bb7d937..9aa4ea5 100644
--- a/hyperglass/.gitignore
+++ b/hyperglass/.gitignore
@@ -6,6 +6,5 @@ gunicorn_config.py
gunicorn_dev_config.py
test.py
__pycache__/
-parsing/
*_old
certs/
diff --git a/hyperglass/cli/util.py b/hyperglass/cli/util.py
index 873b8eb..dc25954 100644
--- a/hyperglass/cli/util.py
+++ b/hyperglass/cli/util.py
@@ -165,7 +165,7 @@ def build_ui():
ClickException: Raised on any errors.
"""
try:
- from hyperglass.compat import aiorun
+ from hyperglass.compat._asyncio import aiorun
from hyperglass.util import build_frontend
from hyperglass.configuration import params, frontend_params, CONFIG_PATH
except ImportError as e:
diff --git a/hyperglass/configuration/models/routers.py b/hyperglass/configuration/models/routers.py
index 88e3150..43f7758 100644
--- a/hyperglass/configuration/models/routers.py
+++ b/hyperglass/configuration/models/routers.py
@@ -11,7 +11,7 @@ from pydantic import StrictInt, StrictStr, validator
# Project
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.configuration.models.ssl import Ssl
from hyperglass.configuration.models.vrfs import Vrf, Info
@@ -65,8 +65,12 @@ class Router(HyperglassModel):
Returns:
{str} -- Valid NOS
"""
- if not Supported.is_supported(value):
- raise UnsupportedDevice(f'"{value}" device type is not supported.')
+ if value in SCRAPE_HELPERS.keys():
+ value = SCRAPE_HELPERS[value]
+
+ if value not in (*TRANSPORT_REST, *TRANSPORT_SCRAPE):
+ raise UnsupportedDevice('NOS "{n}" is not supported.', n=value)
+
return value
@validator("name")
diff --git a/hyperglass/constants.py b/hyperglass/constants.py
index 64b48d0..7b74b37 100644
--- a/hyperglass/constants.py
+++ b/hyperglass/constants.py
@@ -4,7 +4,7 @@ import sys
from datetime import datetime
__name__ = "hyperglass"
-__version__ = "1.0.0-beta.17"
+__version__ = "1.0.0-beta.18"
__author__ = "Matt Love"
__copyright__ = f"Copyright {datetime.now().year} Matthew Love"
__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_JUNIPER_ASPATH = ("juniper", "juniper_junos")
+
LOG_FMT = (
"[{level}] {time:YYYYMMDD} {time:HH:mm:ss} | {name}:"
"{line} | {function} → {message}"
@@ -260,6 +262,11 @@ TRANSPORT_SCRAPE = (
"oneaccess_oneos",
)
+SCRAPE_HELPERS = {
+ "junos": "juniper",
+ "ios": "cisco_ios",
+}
+
class Supported:
"""Define items supported by hyperglass.
diff --git a/hyperglass/examples/commands.yaml b/hyperglass/examples/commands.yaml
index 1e0944e..e69de29 100644
--- a/hyperglass/examples/commands.yaml
+++ b/hyperglass/examples/commands.yaml
@@ -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}
diff --git a/hyperglass/execution/construct.py b/hyperglass/execution/construct.py
index 23912c9..27d82be 100644
--- a/hyperglass/execution/construct.py
+++ b/hyperglass/execution/construct.py
@@ -7,14 +7,16 @@ hyperglass API modules.
# Standard Library
import re
+import json as _json
import operator
-# Third Party
-import ujson
-
# Project
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
@@ -72,6 +74,20 @@ class Construct:
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):
"""Return JSON version of validated query for REST devices.
@@ -82,7 +98,7 @@ class Construct:
{str} -- JSON query string
"""
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,
"vrf": self.query_data.query_vrf.name,