From 5cbc5c0494c8b00ba174add3d928e950d02e26c8 Mon Sep 17 00:00:00 2001 From: Ralph Schmieder Date: Tue, 23 Apr 2024 11:55:10 +0200 Subject: [PATCH] Fix node mapping and package meta data (#2) * Fix node mapping and package meta data - fix longest prefix node type mapping - update package meta data - added a note regarding configurations when changing node Types * dependency update --- CHANGELOG.md | 4 ++++ README.md | 3 +++ pdm.lock | 36 ++++++++++++++++++------------------ pyproject.toml | 35 +++++++++++++++++++++++++++++++++++ src/eve2cml/_version.py | 2 +- src/eve2cml/mapper.py | 21 +++++++++++---------- tests/requirements.txt | 4 ++-- 7 files changed, 74 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59e9adf..2b340f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +- v0.1.0b3 + - fix longest prefix node type mapping + - update package meta data + - added a note regarding configurations when changing node types - v0.1.0b2 - fix slot calculation for nodes with interface gaps - increase IOL / IOL-2 maximum interfaces from 16 to 32 diff --git a/README.md b/README.md index 710f021..d8e3d3f 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,9 @@ After modification / adding more or different node type mappings to the exported Disclaimer: There's certainly things out there which do not properly translate. If you encounter anything then raise an issue in the issue tracker and I'll look into it. +> [!NOTE] +> It is possible to change node types when importing. For example, you might want to change IOSv-L2 instances to IOLL2-XE instances by providing a custom import map. Note, however, that this does **NOT** change the device configuration of the imported nodes. So, if the configuration uses `GigabitEthernet0/4` in the original IOSv-L2 configuration then it is your responsibility to change this to `Ethernet1/0` for the configuration of the imported IOLL2-XE device. This can be easily done via a sed script or using a text editor and global search and replace. However, this might be more involved depending on the original/target device type. + ### Usage ``` diff --git a/pdm.lock b/pdm.lock index 07d05d5..4900f22 100644 --- a/pdm.lock +++ b/pdm.lock @@ -341,28 +341,28 @@ files = [ [[package]] name = "ruff" -version = "0.3.5" +version = "0.4.1" requires_python = ">=3.7" summary = "An extremely fast Python linter and code formatter, written in Rust." groups = ["dev"] files = [ - {file = "ruff-0.3.5-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:aef5bd3b89e657007e1be6b16553c8813b221ff6d92c7526b7e0227450981eac"}, - {file = "ruff-0.3.5-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:89b1e92b3bd9fca249153a97d23f29bed3992cff414b222fcd361d763fc53f12"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5e55771559c89272c3ebab23326dc23e7f813e492052391fe7950c1a5a139d89"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:dabc62195bf54b8a7876add6e789caae0268f34582333cda340497c886111c39"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3a05f3793ba25f194f395578579c546ca5d83e0195f992edc32e5907d142bfa3"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:dfd3504e881082959b4160ab02f7a205f0fadc0a9619cc481982b6837b2fd4c0"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:87258e0d4b04046cf1d6cc1c56fadbf7a880cc3de1f7294938e923234cf9e498"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:712e71283fc7d9f95047ed5f793bc019b0b0a29849b14664a60fd66c23b96da1"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a532a90b4a18d3f722c124c513ffb5e5eaff0cc4f6d3aa4bda38e691b8600c9f"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:122de171a147c76ada00f76df533b54676f6e321e61bd8656ae54be326c10296"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:d80a6b18a6c3b6ed25b71b05eba183f37d9bc8b16ace9e3d700997f00b74660b"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_i686.whl", hash = "sha256:a7b6e63194c68bca8e71f81de30cfa6f58ff70393cf45aab4c20f158227d5936"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:a759d33a20c72f2dfa54dae6e85e1225b8e302e8ac655773aff22e542a300985"}, - {file = "ruff-0.3.5-py3-none-win32.whl", hash = "sha256:9d8605aa990045517c911726d21293ef4baa64f87265896e491a05461cae078d"}, - {file = "ruff-0.3.5-py3-none-win_amd64.whl", hash = "sha256:dc56bb16a63c1303bd47563c60482a1512721053d93231cf7e9e1c6954395a0e"}, - {file = "ruff-0.3.5-py3-none-win_arm64.whl", hash = "sha256:faeeae9905446b975dcf6d4499dc93439b131f1443ee264055c5716dd947af55"}, - {file = "ruff-0.3.5.tar.gz", hash = "sha256:a067daaeb1dc2baf9b82a32dae67d154d95212080c80435eb052d95da647763d"}, + {file = "ruff-0.4.1-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:2d9ef6231e3fbdc0b8c72404a1a0c46fd0dcea84efca83beb4681c318ea6a953"}, + {file = "ruff-0.4.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:9485f54a7189e6f7433e0058cf8581bee45c31a25cd69009d2a040d1bd4bfaef"}, + {file = "ruff-0.4.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d2921ac03ce1383e360e8a95442ffb0d757a6a7ddd9a5be68561a671e0e5807e"}, + {file = "ruff-0.4.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:eec8d185fe193ad053eda3a6be23069e0c8ba8c5d20bc5ace6e3b9e37d246d3f"}, + {file = "ruff-0.4.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:baa27d9d72a94574d250f42b7640b3bd2edc4c58ac8ac2778a8c82374bb27984"}, + {file = "ruff-0.4.1-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:f1ee41580bff1a651339eb3337c20c12f4037f6110a36ae4a2d864c52e5ef954"}, + {file = "ruff-0.4.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:0926cefb57fc5fced629603fbd1a23d458b25418681d96823992ba975f050c2b"}, + {file = "ruff-0.4.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2c6e37f2e3cd74496a74af9a4fa67b547ab3ca137688c484749189bf3a686ceb"}, + {file = "ruff-0.4.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:efd703a5975ac1998c2cc5e9494e13b28f31e66c616b0a76e206de2562e0843c"}, + {file = "ruff-0.4.1-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:b92f03b4aa9fa23e1799b40f15f8b95cdc418782a567d6c43def65e1bbb7f1cf"}, + {file = "ruff-0.4.1-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:1c859f294f8633889e7d77de228b203eb0e9a03071b72b5989d89a0cf98ee262"}, + {file = "ruff-0.4.1-py3-none-musllinux_1_2_i686.whl", hash = "sha256:b34510141e393519a47f2d7b8216fec747ea1f2c81e85f076e9f2910588d4b64"}, + {file = "ruff-0.4.1-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:6e68d248ed688b9d69fd4d18737edcbb79c98b251bba5a2b031ce2470224bdf9"}, + {file = "ruff-0.4.1-py3-none-win32.whl", hash = "sha256:b90506f3d6d1f41f43f9b7b5ff845aeefabed6d2494307bc7b178360a8805252"}, + {file = "ruff-0.4.1-py3-none-win_amd64.whl", hash = "sha256:c7d391e5936af5c9e252743d767c564670dc3889aff460d35c518ee76e4b26d7"}, + {file = "ruff-0.4.1-py3-none-win_arm64.whl", hash = "sha256:a1eaf03d87e6a7cd5e661d36d8c6e874693cb9bc3049d110bc9a97b350680c43"}, + {file = "ruff-0.4.1.tar.gz", hash = "sha256:d592116cdbb65f8b1b7e2a2b48297eb865f6bdc20641879aa9d7b9c11d86db79"}, ] [[package]] diff --git a/pyproject.toml b/pyproject.toml index ae73ce0..4db20a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,41 @@ dependencies = [ requires-python = ">=3.8" readme = "README.md" license = {text = "MIT"} +keywords = ["automation", "tools", "simulation", "virtualization", "network-programming"] + +classifiers = [ + # How mature is this project? Common values are + # 3 - Alpha + # 4 - Beta + # 5 - Production/Stable + "Development Status :: 4 - Beta", + + "Environment :: Console", + + # Indicate who your project is intended for + "Intended Audience :: Telecommunications Industry", + # "Topic :: Software Development :: Build Tools", + "Topic :: Internet", + + # Pick your license as you wish (see also "license" above) + "License :: OSI Approved :: MIT License", + + # Operating system + "Operating System :: OS Independent", + + # Specify the Python versions you support here. + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", +] + +[project.urls] +Homepage = "https://developer.cisco.com/modeling-labs" +# Documentation = "https://readthedocs.org" +Repository = "https://github.com/ciscodevnet/eve2cml" +Issues = "https://github.com/ciscodevnet/eve2cml/issues" +Changelog = "https://github.com/ciscodevnet/eve2cml/blob/master/CHANGELOG.md" [project.scripts] eve2cml = "eve2cml.main:main" diff --git a/src/eve2cml/_version.py b/src/eve2cml/_version.py index 79518e6..81871ff 100644 --- a/src/eve2cml/_version.py +++ b/src/eve2cml/_version.py @@ -1 +1 @@ -__version__ = "0.1.0b2" +__version__ = "0.1.0b3" diff --git a/src/eve2cml/mapper.py b/src/eve2cml/mapper.py index abce0b4..6259810 100644 --- a/src/eve2cml/mapper.py +++ b/src/eve2cml/mapper.py @@ -77,16 +77,17 @@ def node_def(self, obj_type: str, template: str, image: str) -> CMLdef: found = self.map.get(lookup) if not found: # special case for non-template images like IOL or Docker - if image and template == obj_type: - for key, cmldef in self.map.items(): - if lookup.startswith(key): - return cmldef - found = self.map.get(f"{obj_type}:{template}") - if not found: - _LOGGER.warning( - "Unmapped node type %s %s %s", obj_type, template, image - ) - return CMLdef(self.unknown_type, None, True) + longest_prefix = "" + longest_cmldef = None + for key, cmldef in self.map.items(): + if lookup.startswith(key) and len(key) > len(longest_prefix): + longest_prefix = key + longest_cmldef = cmldef + if longest_cmldef: + _LOGGER.info("mapped node type %s", longest_cmldef) + return longest_cmldef + _LOGGER.warning("Unmapped node type %s %s %s", obj_type, template, image) + return CMLdef(self.unknown_type, None, True) return found def cml_iface_label(self, slot: int, node_def: str, label: str) -> str: diff --git a/tests/requirements.txt b/tests/requirements.txt index e817380..087de46 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -11,9 +11,9 @@ mypy-extensions==1.0.0 packaging==23.2 pluggy==1.4.0 pytest==8.1.1 -pytest-cov==4.1.0 +pytest-cov==5.0.0 pyyaml==6.0.1 -ruff==0.3.2 +ruff==0.4.1 soupsieve==2.5 tomli==2.0.1; python_version < "3.11" types-beautifulsoup4==4.12.0.20240229