Skip to content

Commit

Permalink
add TSNR support, closes #87
Browse files Browse the repository at this point in the history
  • Loading branch information
thatmattlove committed Oct 18, 2020
1 parent 1fc9e55 commit 67fed4e
Show file tree
Hide file tree
Showing 9 changed files with 766 additions and 549 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ hyperglass is intended to make implementing a looking glass too easy not to do,
- Full IPv6 support
- Customizable everything: features, theme, UI/API text, error messages, commands
- Built in support for:
- Arista EOS
- BIRD
- Cisco IOS-XR
- Cisco IOS/IOS-XE
- Cisco NX-OS
- Cisco IOS-XR
- Juniper JunOS
- Arista EOS
- FRRouting
- Huawei
- Juniper JunOS
- Mikrotik
- TNSR
- VyOS
- FRRouting
- BIRD
- Configurable support for any other [supported platform](https://hyperglass.io/docs/platforms)
- Optionally access devices via an SSH proxy/jump server
- VRF support
Expand Down
11 changes: 6 additions & 5 deletions docs/docs/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ hyperglass was created with the lofty goal of benefiting the internet community
- Full IPv6 support
- Customizable everything: features, theme, UI/API text, error messages, commands
- Built in support for:
- Arista EOS
- BIRD
- Cisco IOS-XR
- Cisco IOS/IOS-XE
- Cisco NX-OS
- Cisco IOS-XR
- Juniper JunOS
- Arista EOS
- FRRouting
- Huawei
- Juniper JunOS
- Mikrotik
- TNSR
- VyOS
- FRRouting
- BIRD
- Configurable support for any other [supported platform](platforms.mdx)
- Optionally access devices via an SSH proxy/jump server
- VRF support
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/platforms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The following platforms use [hyperglass-agent](agent/installation.mdx) for conne

## SSH

The following platforms use [Netmiko](https://github.com/ktbyers/netmiko) for connection handling. When configuring the `nos` property of a device, use the value in the **Key** column.
The following platforms use [Netmiko](https://github.com/ktbyers/netmiko) or [Scrapli](https://github.com/carlmontanari/scrapli) for connection handling. When configuring the `nos` property of a device, use the value in the **Key** column.

| Name | Key |
| ------------------------- | --------------------- |
Expand Down Expand Up @@ -92,6 +92,7 @@ The following platforms use [Netmiko](https://github.com/ktbyers/netmiko) for co
| RAD ETX | `rad_etx` |
| Ruckus/Brocade FastIron | `ruckus_fastiron` |
| Ruijie OS | `ruijie_os` |
| TNSR | `tnsr` |
| Ubuiquiti EdgeRouter | `ubiquiti_edge` |
| Ubuiquiti EdgeSwitch | `ubiquiti_edgeswitch` |
| Vyatta VyOS | `vyatta_vyos` |
Expand Down
2 changes: 2 additions & 0 deletions hyperglass/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"junos": "juniper",
"ios": "cisco_ios",
"mikrotik": "mikrotik_routeros",
"tsnr": "tnsr",
}

DRIVER_MAP = {
Expand All @@ -75,6 +76,7 @@
"cisco_xr": "scrapli",
"cisco_nxos": "scrapli",
"juniper": "scrapli",
"tnsr": "scrapli",
"frr": "hyperglass_agent",
"bird": "hyperglass_agent",
}
15 changes: 12 additions & 3 deletions hyperglass/execution/drivers/ssh_scrapli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Standard Library
import math
from typing import Iterable
from typing import Sequence

# Third Party
from scrapli.driver import AsyncGenericDriver
Expand Down Expand Up @@ -37,11 +37,17 @@
from .ssh import SSHConnection

SCRAPLI_DRIVER_MAP = {
"arista_eos": AsyncEOSDriver,
"cisco_ios": AsyncIOSXEDriver,
"cisco_nxos": AsyncNXOSDriver,
"cisco_xr": AsyncIOSXRDriver,
"juniper": AsyncJunosDriver,
"arista_eos": AsyncEOSDriver,
"tnsr": AsyncGenericDriver,
}

driver_global_args = {
# Per-NOS driver keyword arguments
"tnsr": {"comms_prompt_pattern": r"\S+\s\S+[\#\>]"},
}


Expand All @@ -55,7 +61,7 @@ def _map_driver(nos: str) -> AsyncGenericDriver:
class ScrapliConnection(SSHConnection):
"""Handle a device connection via Scrapli."""

async def collect(self, host: str = None, port: int = None) -> Iterable:
async def collect(self, host: str = None, port: int = None) -> Sequence:
"""Connect directly to a device.
Directly connects to the router via Netmiko library, returns the
Expand All @@ -73,6 +79,8 @@ async def collect(self, host: str = None, port: int = None) -> Iterable:
else:
log.debug("Connecting directly to {}", self.device.name)

global_args = driver_global_args.get(self.device.nos, {})

driver_kwargs = {
"host": host or self.device._target,
"port": port or self.device.port,
Expand All @@ -82,6 +90,7 @@ async def collect(self, host: str = None, port: int = None) -> Iterable:
"auth_strict_key": False,
"ssh_known_hosts_file": False,
"ssh_config_file": False,
**global_args,
}

if self.device.credential._method == "password":
Expand Down
11 changes: 7 additions & 4 deletions hyperglass/models/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Validate command configuration variables."""

# Local
from .tnsr import TNSRCommands
from .vyos import VyosCommands
from ..main import HyperglassModelExtra
from .arista import AristaCommands
Expand All @@ -14,14 +15,15 @@
from .mikrotik_switchos import MikrotikSwitchOS

_NOS_MAP = {
"juniper": JuniperCommands,
"arista": AristaCommands,
"cisco_ios": CiscoIOSCommands,
"cisco_xr": CiscoXRCommands,
"cisco_nxos": CiscoNXOSCommands,
"arista": AristaCommands,
"cisco_xr": CiscoXRCommands,
"huawei": HuaweiCommands,
"juniper": JuniperCommands,
"mikrotik_routeros": MikrotikRouterOS,
"mikrotik_switchos": MikrotikSwitchOS,
"tnsr": TNSRCommands,
"vyos": VyosCommands,
}

Expand All @@ -36,7 +38,8 @@ class Commands(HyperglassModelExtra):
cisco_nxos: CommandGroup = CiscoNXOSCommands()
huawei: CommandGroup = HuaweiCommands()
mikrotik_routeros: CommandGroup = MikrotikRouterOS()
mikortik_switchos: CommandGroup = MikrotikSwitchOS()
mikrotik_switchos: CommandGroup = MikrotikSwitchOS()
tnsr: CommandGroup = TNSRCommands()
vyos: CommandGroup = VyosCommands()

@classmethod
Expand Down
56 changes: 56 additions & 0 deletions hyperglass/models/commands/tnsr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Netgate TNSR Command Model."""

# Third Party
from pydantic import StrictStr

# Local
from .common import CommandSet, CommandGroup


class _IPv4(CommandSet):
"""Validation model for default VRF IPv4 commands."""

bgp_community: StrictStr = 'dataplane shell sudo vtysh -c "show bgp ipv4 unicast community {target}"'
bgp_aspath: StrictStr = 'dataplane shell sudo vtysh -c "show bgp ipv4 unicast regexp {target}"'
bgp_route: StrictStr = 'dataplane shell sudo vtysh -c "show bgp ipv4 unicast {target}"'
ping: StrictStr = "ping {target} ipv4 source {source} count 5 timeout 1"
traceroute: StrictStr = "traceroute {target} ipv4 source {source} timeout 1 waittime 1"


class _IPv6(CommandSet):
"""Validation model for default VRF IPv6 commands."""

bgp_community: StrictStr = 'dataplane shell sudo vtysh -c "show bgp ipv6 unicast community {target}"'
bgp_aspath: StrictStr = 'dataplane shell sudo vtysh -c "show bgp ipv6 unicast regexp {target}"'
bgp_route: StrictStr = 'dataplane shell sudo vtysh -c "show bgp ipv6 unicast {target}"'
ping: StrictStr = "ping {target} ipv6 source {source} count 5 timeout 1"
traceroute: StrictStr = "traceroute {target} ipv6 source {source} timeout 1 waittime 1"


class _VPNIPv4(CommandSet):
"""Validation model for non-default ipv6 commands."""

bgp_community: StrictStr = 'dataplane shell sudo vtysh -c "show bgp vrf {vrf} ipv4 unicast community {target}"'
bgp_aspath: StrictStr = 'dataplane shell sudo vtysh -c "show bgp vrf {vrf} ipv4 unicast regexp {target}"'
bgp_route: StrictStr = 'dataplane shell sudo vtysh -c "show bgp vrf {vrf} ipv4 unicast {target}"'
ping: StrictStr = "dataplane shell ping -4 -c 5 -W 1 -I {vrf} -S {source} {target}"
traceroute: StrictStr = "dataplane shell traceroute -4 -w 1 -q 1 -i {vrf} -s {source} {target}"


class _VPNIPv6(CommandSet):
"""Validation model for non-default ipv6 commands."""

bgp_community: StrictStr = 'dataplane shell sudo vtysh -c "show bgp vrf {vrf} ipv6 unicast community {target}"'
bgp_aspath: StrictStr = 'dataplane shell sudo vtysh -c "show bgp vrf {vrf} ipv6 unicast regexp {target}"'
bgp_route: StrictStr = 'dataplane shell sudo vtysh -c "show bgp vrf {vrf} ipv6 unicast {target}"'
ping: StrictStr = "dataplane shell ping -6 -c 5 -W 1 -I {vrf} -S {source} {target}"
traceroute: StrictStr = "dataplane shell traceroute -6 -w 1 -q 1 -i {vrf} -s {source} {target}"


class TNSRCommands(CommandGroup):
"""Validation model for default tnsr commands."""

ipv4_default: _IPv4 = _IPv4()
ipv6_default: _IPv6 = _IPv6()
ipv4_vpn: _VPNIPv4 = _VPNIPv4()
ipv6_vpn: _VPNIPv6 = _VPNIPv6()
2 changes: 1 addition & 1 deletion hyperglass/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"emotion-theming": "^10.0.27",
"framer-motion": "^1.10.0",
"lodash": "^4.17.15",
"next": "^9.5",
"next": "^9.5.4",
"react": "^16.13.1",
"react-countdown": "^2.2.1",
"react-dom": "^16.13.1",
Expand Down
Loading

0 comments on commit 67fed4e

Please sign in to comment.