Skip to content

Commit

Permalink
Intf(platform="hp_procurve").all_names() -> ["interface Trk1", ...]
Browse files Browse the repository at this point in the history
  • Loading branch information
vprusakovs committed Apr 4, 2023
1 parent 82194df commit da3c450
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
CHANGELOG
=========

0.8.2 (2023-04-04)
------------------
Intf(platform="hp_procurve").all_names() -> ["interface Trk1", ...]

0.8.1 (2023-04-04)
------------------
* [change] Intf(platform="hp_procurve").all_names() -> ["interface 1", "1", "interface 1/1"]
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ or install the package from github.com release

.. code:: bash
pip install https://github.com/vladimirs-git/netports/archive/refs/tags/0.8.1.tar.gz
pip install https://github.com/vladimirs-git/netports/archive/refs/tags/0.8.2.tar.gz
or install the package from github.com repository

.. code:: bash
pip install git+https://github.com/vladimirs-git/netports@0.8.1
pip install git+https://github.com/vladimirs-git/netports@0.8.2
Expand Down
23 changes: 14 additions & 9 deletions netports/intf_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
"BAGG": "Bridge-Aggregation",
"Vlan": "Vlan-interface", # overlapped: cisco
}
MAP_HP_PROCURVE = { # hpc
"Trk": "Trk",
}


def long_to_short(platform: str = "", key_lower: bool = False, value_lower: bool = False) -> DStr:
Expand Down Expand Up @@ -103,13 +106,7 @@ def short_to_long(platform: str = "", key_lower: bool = False, value_lower: bool
short_to_long(key_lower=True) -> {"fa": "FastEthernet", ...}
short_to_long(value_lower=True) -> {"Fa": "fastethernet", ...}
"""
if platform in ["", "hp_procurve"]:
data: DStr = MAP_HP_COMWARE.copy()
data.update(MAP_CISCO_ASR)
data.update(MAP_CISCO_NXOS)
data.update(MAP_CISCO_IOS)
data.update(MAP_OTHER)
elif platform == "cisco_asr":
if platform == "cisco_asr":
data = MAP_OTHER.copy()
data.update(MAP_CISCO_IOS)
data.update(MAP_CISCO_ASR)
Expand All @@ -124,9 +121,17 @@ def short_to_long(platform: str = "", key_lower: bool = False, value_lower: bool
data = MAP_OTHER.copy()
data.update(MAP_CISCO_IOS)
data.update(MAP_HP_COMWARE)
elif platform == "hp_procurve": # h3c
data = MAP_OTHER.copy()
data.update(MAP_CISCO_IOS)
data.update(MAP_HP_PROCURVE)
else:
expected = PLATFORMS
raise ValueError(f"{platform=} {expected=}")
data: DStr = MAP_HP_COMWARE.copy()
data.update(MAP_HP_PROCURVE)
data.update(MAP_CISCO_ASR)
data.update(MAP_CISCO_NXOS)
data.update(MAP_CISCO_IOS)
data.update(MAP_OTHER)
data = _lower(data, key_lower, value_lower)
return data

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "netports"
version = "0.8.1"
version = "0.8.2"
authors = [{ name="Vladimir Prusakov", email="vladimir.prusakovs@gmail.com" }]
description = "Python tools for managing ranges of VLANs, TCP/UDP ports, IP protocols, Interfaces"
readme = "README.rst"
Expand All @@ -21,7 +21,7 @@ classifiers = [
"Homepage" = "https://github.com/vladimirs-git/netports"
"Repository" = "https://github.com/vladimirs-git/netports"
"Bug Tracker" = "https://github.com/vladimirs-git/netports/issues"
"Download URL" = "https://github.com/vladimirs-git/netports/archive/refs/tags/0.8.1.tar.gz"
"Download URL" = "https://github.com/vladimirs-git/netports/archive/refs/tags/0.8.2.tar.gz"
[tool.setuptools.packages.find]
include = ["netports"]
[tool.setuptools.package-data]
Expand Down
109 changes: 106 additions & 3 deletions tests/helpers__intf_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"Po": "Port-channel",
"Se": "Serial",
"Te": "TenGigabitEthernet",
"Trk": "Trk",
"Tu": "Tunnel",
"Twe": "TwentyFiveGigE",
"Two": "TwoGigabitEthernet",
Expand Down Expand Up @@ -137,7 +138,31 @@
"Vt": "Virtual-Template",
"XGE": "Ten-GigabitEthernet",
}

SHORT_TO_LONG_HPC = {
"At": "ATM",
"EO": "EOBC",
"Eth": "Ethernet",
"FD": "Fddi",
"Fa": "FastEthernet",
"Fo": "FortyGigabitEthernet",
"Gi": "GigabitEthernet",
"Hu": "HundredGigabitEthernet",
"Lo": "Loopback",
"MFR": "MFR",
"Ma": "Management",
"Mu": "Multilink",
"Po": "Port-channel",
"Se": "Serial",
"Te": "TenGigabitEthernet",
"Trk": "Trk",
"Tu": "Tunnel",
"Twe": "TwentyFiveGigE",
"Two": "TwoGigabitEthernet",
"V": "Vlan",
"Vi": "Virtual-Access",
"Vlan": "Vlan",
"Vt": "Virtual-Template",
}
# ========================== short_to_short ==========================
SHORT_TO_SHORT = {
"At": "At",
Expand All @@ -159,6 +184,7 @@
"Po": "Po",
"Se": "Se",
"Te": "Te",
"Trk": "Trk",
"Tu": "Tu",
"Twe": "Twe",
"Two": "Two",
Expand Down Expand Up @@ -275,6 +301,31 @@
"Vt": "Vt",
"XGE": "XGE",
}
SHORT_TO_SHORT_HPC = {
"At": "At",
"EO": "EO",
"Eth": "Eth",
"FD": "FD",
"Fa": "Fa",
"Fo": "Fo",
"Gi": "Gi",
"Hu": "Hu",
"Lo": "Lo",
"MFR": "MFR",
"Ma": "Ma",
"Mu": "Mu",
"Po": "Po",
"Se": "Se",
"Te": "Te",
"Trk": "Trk",
"Tu": "Tu",
"Twe": "Twe",
"Two": "Two",
"V": "Vlan",
"Vi": "Vi",
"Vlan": "Vlan",
"Vt": "Vt",
}

# ========================== long_to_short ===========================
LONG_TO_SHORT = {
Expand All @@ -297,6 +348,7 @@
"Serial": "Se",
"Ten-GigabitEthernet": "XGE",
"TenGigabitEthernet": "Te",
"Trk": "Trk",
"Tunnel": "Tu",
"TwentyFiveGigE": "Twe",
"TwoGigabitEthernet": "Two",
Expand Down Expand Up @@ -333,8 +385,8 @@
"Virtual-Template": "Vt",
"Vlan": "Vlan",
"tunnel-ip": "ti",
'HundredGigabitEthernet': 'Hu',
'TenGigabitEthernet': "Te",
"HundredGigabitEthernet": "Hu",
"TenGigabitEthernet": "Te",
}
LONG_TO_SHORT_IOS = {
"ATM": "At",
Expand Down Expand Up @@ -411,6 +463,32 @@
"Vlan": "V",
"Vlan-interface": "Vlan",
}
LONG_TO_SHORT_HPC = {
"FortyGigabitEthernet": "Fo",
"HundredGigabitEthernet": "Hu",
"TwoGigabitEthernet": "Two",
"Vlan": "Vlan",
"ATM": "At",
"EOBC": "EO",
"Fddi": "FD",
"MFR": "MFR",
"Management": "Ma",
"Multilink": "Mu",
"Serial": "Se",
"TwentyFiveGigE": "Twe",
"Virtual-Access": "Vi",
"Virtual-Template": "Vt",
"Ethernet": "Eth",
"FastEthernet": "Fa",
"GigabitEthernet": "Gi",
"TenGigabitEthernet": "Te",
"Port-channel": "Po",
"Loopback": "Lo",
"Tunnel": "Tu",
"Trk": "Trk",
}

# long_to_long
LONG_TO_LONG = {
"ATM": "ATM",
"Bridge-Aggregation": "Bridge-Aggregation",
Expand All @@ -431,6 +509,7 @@
"Serial": "Serial",
"Ten-GigabitEthernet": "Ten-GigabitEthernet",
"TenGigabitEthernet": "TenGigabitEthernet",
"Trk": "Trk",
"Tunnel": "Tunnel",
"TwentyFiveGigE": "TwentyFiveGigE",
"TwoGigabitEthernet": "TwoGigabitEthernet",
Expand Down Expand Up @@ -539,3 +618,27 @@
"Vlan": "Vlan",
"Vlan-interface": "Vlan-interface",
}
LONG_TO_LONG_HPC = {
"FortyGigabitEthernet": "FortyGigabitEthernet",
"HundredGigabitEthernet": "HundredGigabitEthernet",
"TwoGigabitEthernet": "TwoGigabitEthernet",
"Vlan": "Vlan",
"ATM": "ATM",
"EOBC": "EOBC",
"Fddi": "Fddi",
"MFR": "MFR",
"Management": "Management",
"Multilink": "Multilink",
"Serial": "Serial",
"TwentyFiveGigE": "TwentyFiveGigE",
"Virtual-Access": "Virtual-Access",
"Virtual-Template": "Virtual-Template",
"Ethernet": "Ethernet",
"FastEthernet": "FastEthernet",
"GigabitEthernet": "GigabitEthernet",
"TenGigabitEthernet": "TenGigabitEthernet",
"Port-channel": "Port-channel",
"Loopback": "Loopback",
"Tunnel": "Tunnel",
"Trk": "Trk",
}
4 changes: 4 additions & 0 deletions tests/test__intf_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_valid__short_to_long(self):
(dict(platform="cisco_ios"), hm.SHORT_TO_LONG_IOS),
(dict(platform="cisco_nxos"), hm.SHORT_TO_LONG_NXOS),
(dict(platform="hp_comware"), hm.SHORT_TO_LONG_H3C),
(dict(platform="hp_procurve"), hm.SHORT_TO_LONG_HPC),
]:
actual = intf_map.short_to_long(**kwargs)
diff = list(dictdiffer.diff(actual, expected))
Expand All @@ -37,6 +38,7 @@ def test_valid__short_to_short(self):
(dict(platform="cisco_ios"), hm.SHORT_TO_SHORT_IOS),
(dict(platform="cisco_nxos"), hm.SHORT_TO_SHORT_NXOS),
(dict(platform="hp_comware"), hm.SHORT_TO_SHORT_H3C),
(dict(platform="hp_procurve"), hm.SHORT_TO_SHORT_HPC),
]:
actual = intf_map.short_to_short(**kwargs)
diff = list(dictdiffer.diff(actual, expected))
Expand All @@ -52,6 +54,7 @@ def test_valid__long_to_short(self):
(dict(platform="cisco_ios"), hm.LONG_TO_SHORT_IOS),
(dict(platform="cisco_nxos"), hm.LONG_TO_SHORT_NXOS),
(dict(platform="hp_comware"), hm.LONG_TO_SHORT_H3C),
(dict(platform="hp_procurve"), hm.LONG_TO_SHORT_HPC),
]:
actual = intf_map.long_to_short(**kwargs)
diff = list(dictdiffer.diff(actual, expected))
Expand All @@ -67,6 +70,7 @@ def test_valid__long_to_long(self):
(dict(platform="cisco_ios"), hm.LONG_TO_LONG_IOS),
(dict(platform="cisco_nxos"), hm.LONG_TO_LONG_NXOS),
(dict(platform="hp_comware"), hm.LONG_TO_LONG_H3C),
(dict(platform="hp_procurve"), hm.LONG_TO_LONG_HPC),
]:
actual = intf_map.long_to_long(**kwargs)
diff = list(dictdiffer.diff(actual, expected))
Expand Down

0 comments on commit da3c450

Please sign in to comment.