Skip to content

Commit

Permalink
Add forward networks mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
jtdub committed Jan 31, 2024
1 parent b0171d6 commit 20d6d52
Show file tree
Hide file tree
Showing 44 changed files with 1,028 additions and 998 deletions.
1 change: 1 addition & 0 deletions development_scripts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Developer script to generate markdown tables."""

from jinja2 import Environment, BaseLoader, select_autoescape
from netutils.utils import _JINJA2_FUNCTION_MAPPINGS
from netutils import lib_mapper
Expand Down
1 change: 1 addition & 0 deletions flat_postprocess/oui_postprocess.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Python code used to postprocess Flat github action data related to OUI mappings."""

import sys
import re
from urllib.request import urlopen
Expand Down
1 change: 1 addition & 0 deletions flat_postprocess/protocol_postprocess.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Python code used to postprocess Flat github action data related to Protocol mappings."""

import csv
import os
import sys
Expand Down
1 change: 0 additions & 1 deletion netutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Initialization file for library."""


from importlib import metadata


Expand Down
1 change: 1 addition & 0 deletions netutils/bandwidth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for performing bandwidth calculations."""

import re
import typing as t

Expand Down
1 change: 1 addition & 0 deletions netutils/banner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for working with the banner configuration."""

import re

from netutils.constants import CARET_C
Expand Down
1 change: 1 addition & 0 deletions netutils/config/clean.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for working with configuration to clean the config."""

# pylint: disable=anomalous-backslash-in-string

import re
Expand Down
1 change: 1 addition & 0 deletions netutils/config/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Parsers for different network operating systems."""

# pylint: disable=no-member,super-with-arguments,invalid-overridden-method,raise-missing-from,invalid-overridden-method,inconsistent-return-statements,super-with-arguments,redefined-argument-from-local,no-else-break,useless-super-delegation,too-many-lines

import re
Expand Down
1 change: 1 addition & 0 deletions netutils/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Constant definitions used in project."""

from netutils.data_files.protocol_mappings import ( # noqa: F401 # pylint:disable=unused-import
PROTOCOLS,
)
Expand Down
1 change: 1 addition & 0 deletions netutils/dns.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for working with DNS."""

import socket


Expand Down
1 change: 1 addition & 0 deletions netutils/hash.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for hashing data."""

import hashlib
import typing as t

Expand Down
1 change: 1 addition & 0 deletions netutils/interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for working with interface."""

import itertools
import re
import typing as t
Expand Down
1 change: 1 addition & 0 deletions netutils/ip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for working with IP addresses."""

import ipaddress
import typing as t
from operator import attrgetter
Expand Down
37 changes: 37 additions & 0 deletions netutils/lib_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,26 @@
"ubiquiti_airos": "ubiquiti_airos",
}

# Forward Networks Parser | Normalized
FORWARDNETWORKS_LIB_MAPPER = {
"ARISTA_EOS": "arista_eos",
"ARUBA_SWITCH": "aruba_aoscx",
"ASA": "cisco_asa",
"EXTREME_NOS": "extreme_netiron",
"FORTINET": "fortinet_fortios",
"F5": "bigip_f5",
"IOS": "cisco_ios",
"IOS_XE": "cisco_ios",
"IOS_XR": "cisco_iosxr",
"JUNOS": "juniper_junos",
"LINUX": "linux",
"LINUX_OVS_OFCTL": "linux",
"NETSCALER": "netscaler",
"NXOS": "cisco_nxos",
"PAN_OS": "paloalto_panos",
"SRX": "juniper_junos",
}

# Normalized | NAPALM
NAPALM_LIB_MAPPER_REVERSE = {
"arista_eos": "eos",
Expand Down Expand Up @@ -491,6 +511,23 @@
"ubiquiti_airos": "ubiquiti_airos",
}

# Normalized | Forward Networks Parser
FORWARDNETWORKS_LIB_MAPPER_REVERSE = {
"arista_eos": "ARISTA_EOS",
"aruba_aoscx": "ARUBA_SWITCH",
"bigip_f5": "F5",
"cisco_asa": "ASA",
"cisco_ios": "IOS",
"cisco_iosxr": "IOS_XR",
"cisco_nxos": "NXOS",
"extreme_netiron": "EXTREME_NOS",
"fortinet_fortios": "FORTINET",
"juniper_junos": "JUNOS",
"linux": "LINUX",
"netscaler": "NETSCALER",
"paloalto_panos": "PAN_OS",
}

# Deep copy the reverse, where there is no actual translation happening.
NETMIKO_LIB_MAPPER_REVERSE = copy.deepcopy(NETMIKO_LIB_MAPPER)
NTCTEMPLATES_LIB_MAPPER_REVERSE = copy.deepcopy(NTCTEMPLATES_LIB_MAPPER)
Expand Down
1 change: 1 addition & 0 deletions netutils/os_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for working with OS Versions."""

import typing as t
from distutils.version import LooseVersion # pylint: disable=deprecated-module

Expand Down
1 change: 1 addition & 0 deletions netutils/ping.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to create a ping via pure Python."""

import socket


Expand Down
1 change: 1 addition & 0 deletions netutils/protocol_mapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Protocol Mappers."""

import typing as t

from netutils.constants import PROTOCOLS
Expand Down
1 change: 1 addition & 0 deletions netutils/time.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for working with time."""

import re
import typing as t

Expand Down
1,944 changes: 948 additions & 996 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "netutils"
version = "1.6.0"
version = "1.6.1"
description = "Common helper functions useful in network automation."
authors = ["Network to Code, LLC <[email protected]>"]
license = "Apache-2.0"
Expand Down
1 change: 1 addition & 0 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tasks for use with Invoke."""

import os
import sys
from distutils.util import strtobool # pylint: disable=W0402
Expand Down
1 change: 1 addition & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Used to setup fixtures to be used through tests"""

import json
import os
import importlib.util
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_acl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the BGP ASN functions."""

# pylint: disable=use-dict-literal

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_basics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Basic tests that do not require netutils."""

import os
import unittest
import toml
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_compliance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the config compliance functions."""

import glob
import os

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_config_clean.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the config cleaning functions."""

import glob
import os

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_conversion.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test that configurations properly convert from undesired format to desired"""

import glob
import os

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_docs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Update docs tests to include assurance that development script ran."""

import sys

sys.path.append("...")
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_hash.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the hash functions."""

import pytest

from netutils.hash import hash_data
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the interface functions."""

import pytest

from netutils import interface
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_ip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the IP functions."""

import ipaddress
import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_lib_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the lib_helpers definitions."""

from unittest import mock

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_lib_helpers_optionals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the lib_helpers definitions when optional packages are installed."""

from unittest import mock

import pytest
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_lib_mapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the lib_mapper definitions."""

import pytest

from netutils import lib_mapper
Expand All @@ -23,6 +24,8 @@ def test_lib_mapper():
assert lib_mapper.NAPALM_LIB_MAPPER_REVERSE[lib_mapper.ANSIBLE_LIB_MAPPER["cisco.ios.ios"]] == "ios"
assert lib_mapper.HIERCONFIG_LIB_MAPPER["ios"] == "cisco_ios"
assert lib_mapper.HIERCONFIG_LIB_MAPPER_REVERSE[lib_mapper.HIERCONFIG_LIB_MAPPER["ios"]] == "ios"
assert lib_mapper.FORWARDNETWORKS_LIB_MAPPER["IOS"] == "cisco_ios"
assert lib_mapper.FORWARDNETWORKS_LIB_MAPPER_REVERSE[lib_mapper.FORWARDNETWORKS_LIB_MAPPER["IOS"]] == "IOS"


@pytest.mark.parametrize("lib", LIBRARIES)
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_mac.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the MAC address functions."""

import pytest

from netutils import mac
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_os_versions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the lib_helpers definitions."""

import pytest
from netutils.os_version import get_upgrade_path
from netutils.constants import UPGRADE_PATHS
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the network os parser functions."""

import glob
import os

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_password.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the password functions."""

import pytest

from netutils import password
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_protocol_mapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the lib_mapper definitions."""

import pytest

from netutils.protocol_mapper import (
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_route.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the longest_prefix_match definitions."""

from ipaddress import AddressValueError, NetmaskValueError

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_time.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the time functions."""

import pytest
from netutils.time import uptime_string_to_seconds, uptime_seconds_to_string

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the library utilities."""

import os
from glob import glob
from importlib import import_module
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Basic test for version check."""

import unittest
import os
import toml
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_vlan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test for the VLAN functions."""

import os
import glob

Expand Down

0 comments on commit 20d6d52

Please sign in to comment.