def pre_check(): if sys.version_info < (3, 6): click.secho( f"Hyperglass requires Python 3.6 or higher. Curren version: Python {sys.version.split()[0]}", fg="red", bold=True, ) if sys.version_info >= (3, 6): click.secho( f"✓ Python Version Check passed (Current version: Python {sys.version.split()[0]})", fg="green", bold=True, ) try: from hyperglass import configuration config = configuration.params() status = True while status: if config["general"]["primary_asn"] == "65000" or "": status = False reason = f'Primary ASN is not defined (Current: "{config["general"]["primary_asn"]}")' remediation = f""" To define the Primary ASN paramter, modify your `configuration.toml` and add the following \ configuration:\n [general] primary_asn = "<Your Primary AS Number>" \nIf you do not define a Primary ASN, \"{config["general"]["primary_asn"]}\" will be used.""" break click.secho(reason, fg="red", bold=True) click.secho(remediation, fg="blue") if config["general"]["org_name"] == "The Company" or "": status = False reason = f'Org Name is not defined (Current: "{config["general"]["org_name"]}")' remediation = f""" To define an Org Name paramter, modify your `configuration.toml` and add the following \ configuration:\n [general] org_name = "<Your Org Name>" \nIf you do not define an Org Name, \"{config["general"]["org_name"]}\" will be displayed.""" break click.secho(reason, fg="red", bold=True) click.secho(remediation, fg="blue") click.secho( "✓ All critical hyperglass parameters are defined!", fg="green", bold=True, ) break except Exception as e: click.secho(f"Exception occurred:\n{e}", fg="red")
# Module Imports import logzero from logzero import logger from netaddr.core import AddrFormatError from netaddr import IPNetwork, IPAddress, IPSet # pylint: disable=unused-import # Dear PyLint, the netaddr library is a special snowflake. You might not see `IPAddress` get used, \ # but when you use something like `IPNetwork("192.0.2.1/24").ip`, the returned value is \ # IPAddress("192.0.2.1"), so I do actually need this import. <3, -ML # Project Imports from hyperglass import configuration # Configuration Imports config = configuration.params() # Logzero Configuration if configuration.debug_state(): logzero.loglevel(logging.DEBUG) else: logzero.loglevel(logging.INFO) class IPType: """ Passes input through IPv4/IPv6 regex patterns to determine if input is formatted as a host \ (e.g. 192.0.2.1), or as CIDR (e.g. 192.0.2.0/24). is_host() and is_cidr() return a boolean. """ def __init__(self): self.ipv4_host = (
def get_hyperglass_config(): sys.path.insert(0, parent_directory) from hyperglass import configuration hg_config = configuration.params() return hg_config