1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

318 lines
8.0 KiB
Python
Raw Normal View History

"""Constant definitions used throughout the application."""
2019-12-30 09:47:31 -07:00
# Standard Library Imports
import sys
from datetime import datetime
__name__ = "hyperglass"
__version__ = "1.0.0"
__author__ = "Matt Love"
__copyright__ = f"Copyright {datetime.now().year} Matthew Love"
__license__ = "BSD 3-Clause Clear License"
METADATA = (__name__, __version__, __author__, __copyright__, __license__)
MIN_PYTHON_VERSION = (3, 7)
protocol_map = {80: "http", 8080: "http", 443: "https", 8443: "https"}
target_format_space = ("huawei", "huawei_vrpv8")
2019-09-13 00:36:58 -07:00
LOG_FMT = (
2019-12-30 01:44:19 -07:00
"<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}"
)
LOG_LEVELS = [
{"name": "DEBUG", "no": 10, "color": "<c>"},
{"name": "INFO", "no": 20, "color": "<le>"},
{"name": "SUCCESS", "no": 25, "color": "<g>"},
{"name": "WARNING", "no": 30, "color": "<y>"},
{"name": "ERROR", "no": 40, "color": "<y>"},
{"name": "CRITICAL", "no": 50, "color": "<r>"},
]
LOG_HANDLER = {"sink": sys.stdout, "format": LOG_FMT, "level": "INFO"}
2020-01-03 03:04:50 -07:00
LOG_HANDLER_FILE = {"format": LOG_FMT, "level": "INFO"}
2020-01-17 02:50:57 -07:00
CREDIT = """
Powered by [**hyperglass**](https://github.com/checktheroads/hyperglass). Source code \
licensed \
[_BSD 3-Clause Clear_](https://github.com/checktheroads/hyperglass/blob/master/LICENSE).
"""
2020-01-16 02:51:10 -07:00
DEFAULT_TERMS = """
2020-01-17 02:50:57 -07:00
By using {site_title}, you agree to be bound by the following terms of use:
All queries executed on this page are logged for analysis and troubleshooting. \
2020-01-16 02:51:10 -07:00
Users are prohibited from automating queries, or attempting to process queries in \
2020-01-17 02:50:57 -07:00
bulk. This service is provided on a best effort basis, and {org_name} \
2020-01-16 02:51:10 -07:00
makes no availability or performance warranties or guarantees whatsoever.
"""
DEFAULT_DETAILS = {
2020-01-17 02:50:57 -07:00
"bgp_aspath": """
{site_title} accepts the following `AS_PATH` regular expression patterns:
2020-01-16 02:51:10 -07:00
| Expression | Match |
| :------------------- | :-------------------------------------------- |
| `_65000$` | Originated by 65000 |
| `^65000_` | Received from 65000 |
| `_65000_` | Via 65000 |
| `_65000_65001_` | Via 65000 and 65001 |
| `_65000(_.+_)65001$` | Anything from 65001 that passed through 65000 |
""",
"bgp_community": """
2020-01-17 02:50:57 -07:00
{site_title} makes use of the following BGP communities:
2020-01-16 02:51:10 -07:00
| Community | Description |
| :-------- | :---------- |
| `65000:1` | Example 1 |
| `65000:2` | Example 2 |
| `65000:3` | Example 3 |
2020-01-17 02:50:57 -07:00
""",
"bgp_route": """
Performs BGP table lookup based on IPv4/IPv6 prefix.
""",
"ping": """
Sends 5 ICMP echo requests to the target.
""",
"traceroute": """
Performs UDP Based traceroute to the target. \
For information about how to interpret traceroute results, [click here]\
(https://hyperglass.readthedocs.io/en/latest/assets/traceroute_nanog.pdf).
2020-01-16 02:51:10 -07:00
""",
}
DEFAULT_INFO = {
"bgp_route": """
---
template: bgp_route
---
Performs BGP table lookup based on IPv4/IPv6 prefix.
""",
"bgp_community": """
---
template: bgp_community
---
Performs BGP table lookup based on <a href="https://tools.ietf.org/html/rfc4360" target\
="_blank">Extended</a> or <a href="https://tools.ietf.org/html/rfc8195" target=\
"_blank">Large</a> community value.
""",
"bgp_aspath": """
---
template: bgp_aspath
---
Performs BGP table lookup based on `AS_PATH` regular expression.
""",
"ping": """
---
template: ping
---
Sends 5 ICMP echo requests to the target.
""",
"traceroute": """
---
template: traceroute
---
Performs UDP Based traceroute to the target.<br>For information about how to \
interpret traceroute results, <a href="https://hyperglass.readthedocs.io/en/latest/ass\
ets/traceroute_nanog.pdf" target="_blank">click here</a>.
""",
}
DEFAULT_HELP = """
##### BGP Route
2020-01-17 02:50:57 -07:00
2020-01-16 02:51:10 -07:00
Performs BGP table lookup based on IPv4/IPv6 prefix.
2020-01-17 02:50:57 -07:00
---
2020-01-16 02:51:10 -07:00
##### BGP Community
2020-01-17 02:50:57 -07:00
Performs BGP table lookup based on [Extended](https://tools.ietf.org/html/rfc4360) \
or [Large](https://tools.ietf.org/html/rfc8195) community value.
---
2020-01-16 02:51:10 -07:00
##### BGP AS Path
2020-01-17 02:50:57 -07:00
2020-01-16 02:51:10 -07:00
Performs BGP table lookup based on `AS_PATH` regular expression.
2020-01-17 02:50:57 -07:00
---
2020-01-16 02:51:10 -07:00
##### Ping
2020-01-17 02:50:57 -07:00
2020-01-16 02:51:10 -07:00
Sends 5 ICMP echo requests to the target.
2020-01-17 02:50:57 -07:00
---
2020-01-16 02:51:10 -07:00
##### Traceroute
2020-01-17 02:50:57 -07:00
Performs UDP Based traceroute to the target.
For information about how to interpret traceroute results, [click here]\
(https://hyperglass.readthedocs.io/en/latest/assets/traceroute_nanog.pdf).
2020-01-16 02:51:10 -07:00
"""
class Supported:
2019-12-31 01:08:15 -07:00
"""Define items supported by hyperglass.
query_types: Supported query types used to validate Flask input.
rest: Supported REST API platforms
scrape: Supported "scrape" platforms which will be accessed via
Netmiko. List updated 07/2019.
"""
2019-09-09 12:18:26 -07:00
query_parameters = ("query_location", "query_type", "query_target", "query_vrf")
query_types = ("bgp_route", "bgp_community", "bgp_aspath", "ping", "traceroute")
rest = ("frr", "bird")
scrape = (
"a10",
"accedian",
"alcatel_aos",
"alcatel_sros",
"apresia_aeos",
"arista_eos",
"aruba_os",
"avaya_ers",
"avaya_vsp",
"brocade_fastiron",
"brocade_netiron",
"brocade_nos",
"brocade_vdx",
"brocade_vyos",
"checkpoint_gaia",
"calix_b6",
"ciena_saos",
"cisco_asa",
"cisco_ios",
"cisco_ios_telnet",
"cisco_nxos",
"cisco_s300",
"cisco_tp",
"cisco_wlc",
"cisco_xe",
"cisco_xr",
"coriant",
"dell_dnos9",
"dell_force10",
"dell_os6",
"dell_os9",
"dell_os10",
"dell_powerconnect",
"dell_isilon",
"eltex",
"enterasys",
"extreme",
"extreme_ers",
"extreme_exos",
"extreme_netiron",
"extreme_nos",
"extreme_slx",
"extreme_vdx",
"extreme_vsp",
"extreme_wing",
"f5_ltm",
"f5_tmsh",
"f5_linux",
"fortinet",
"generic_termserver",
"hp_comware",
"hp_procurve",
"huawei",
"huawei_vrpv8",
"ipinfusion_ocnos",
"juniper",
"juniper_junos",
"linux",
"mellanox",
"mrv_optiswitch",
"netapp_cdot",
"netscaler",
"ovs_linux",
"paloalto_panos",
"pluribus",
"quanta_mesh",
"rad_etx",
"ruckus_fastiron",
"ubiquiti_edge",
"ubiquiti_edgeswitch",
"vyatta_vyos",
"vyos",
"oneaccess_oneos",
)
@staticmethod
def is_supported(nos):
2019-12-31 01:08:15 -07:00
"""Verify if NOS is supported.
Arguments:
nos {str} -- NOS short name
Returns:
{bool} -- True if supported
"""
2019-07-07 22:38:46 -07:00
return bool(nos in Supported.rest + Supported.scrape)
@staticmethod
def is_scrape(nos):
2019-12-31 01:08:15 -07:00
"""Verify if NOS transport is scrape.
Arguments:
nos {str} -- NOS short name
Returns:
{bool} -- True if scrape
"""
return bool(nos in Supported.scrape)
@staticmethod
def is_rest(nos):
2019-12-31 01:08:15 -07:00
"""Verify if NOS transport is REST.
Arguments:
nos {str} -- NOS short name
Returns:
{bool} -- True if REST
"""
return bool(nos in Supported.rest)
@staticmethod
def is_supported_query(query_type):
2019-12-31 01:08:15 -07:00
"""Verify if query type is supported.
Arguments:
query_type {str} -- query type
Returns:
{bool} -- True if supported
"""
return bool(query_type in Supported.query_types)
@staticmethod
def map_transport(nos):
2019-12-31 01:08:15 -07:00
"""Map NOS to transport name.
Arguments:
nos {str} -- NOS short name
Returns:
{str} -- Transport name
"""
transport = None
if nos in Supported.scrape:
transport = "scrape"
elif nos in Supported.rest:
transport = "rest"
return transport