Skip to content

Commit

Permalink
Merge pull request #165 from shurick2/main
Browse files Browse the repository at this point in the history
feat: add h3c
  • Loading branch information
gescheit authored Nov 26, 2024
2 parents 3f32a3a + 1aaaa90 commit 605983c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 4 deletions.
5 changes: 4 additions & 1 deletion annet/adapters/netbox/common/manufacturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"aruba": "Aruba",
"routeros": "RouterOS",
"ribbon": "Ribbon",
"b4com": "B4com"
"b4com": "B4com",
"h3c": "H3C",
}


Expand All @@ -37,6 +38,8 @@ def get_breed(manufacturer: str, model: str):
return "vrp85"
elif manufacturer == "Huawei":
return "vrp55"
elif manufacturer == "H3C":
return "h3c"
elif manufacturer in ("Mellanox", "NVIDIA"):
return "cuml2"
elif manufacturer == "Juniper":
Expand Down
6 changes: 6 additions & 0 deletions annet/annlib/rbparser/platform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VENDOR_REVERSES = {
"huawei": "undo",
"h3c": "undo",
"optixtrans": "undo",
"cisco": "no",
"nexus": "no",
Expand Down Expand Up @@ -45,6 +46,7 @@

VENDOR_EXIT = {
"huawei": "quit",
"h3c": "quit",
"optixtrans": "quit",
"cisco": "exit",
"nexus": "exit",
Expand All @@ -57,3 +59,7 @@
"ribbon": "exit",
"b4com": "exit",
}

VENDOR_ALIASES = {
"h3c": "huawei",
}
4 changes: 4 additions & 0 deletions annet/annlib/rulebook/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ def apply(hw, do_commit, do_finalize, **_):
after.add_cmd(Command("commit"))
if do_finalize:
after.add_cmd(Command("write", timeout=40))
elif hw.H3C:
before.add_cmd(Command("system-view"))
if do_finalize:
after.add_cmd(Command("save force", timeout=20))
else:
raise Exception("unknown hw %s" % hw)

Expand Down
5 changes: 3 additions & 2 deletions annet/rulebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from annet.annlib.lib import mako_render
from annet.annlib.rbparser.ordering import compile_ordering_text
from annet.annlib.rbparser.platform import VENDOR_REVERSES
from annet.annlib.rbparser.platform import VENDOR_REVERSES, VENDOR_ALIASES

from annet.connectors import CachedConnector
from annet.rulebook.deploying import compile_deploying_text
Expand Down Expand Up @@ -64,7 +64,8 @@ def get_rulebook(self, hw):
return self._rulebook_cache[hw]

assert hw.vendor in VENDOR_REVERSES, "Unknown vendor: %s" % (hw.vendor)
patching = compile_patching_text(self._render_rul(hw.vendor + ".rul", hw), hw.vendor)
rul_vendor_name = VENDOR_ALIASES.get(hw.vendor, hw.vendor)
patching = compile_patching_text(self._render_rul(rul_vendor_name + ".rul", hw), rul_vendor_name)

try:
ordering_text = self._render_rul(hw.vendor + ".order", hw)
Expand Down
2 changes: 2 additions & 0 deletions annet/tabparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def make_formatter(hw, **kwargs):
cls = CommonFormatter
elif hw.Ribbon:
cls = RibbonFormatter
elif hw.H3C:
cls = HuaweiFormatter
else:
raise NotImplementedError("Unknown formatter for hw '%s'" % hw)

Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def make_hw_stub(vendor):
"ribbon": "Ribbon",
"optixtrans": "Huawei DC",
"b4com": "B4com",
"h3c": "H3C",
}[vendor], None)


Expand Down
2 changes: 1 addition & 1 deletion tests/annet/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
id="juniper-ribbon"
),
pytest.param(
{"huawei"},
{"huawei", "h3c"},
"""
port split mode mode1 slot 1
ip vpn-instance MEth0/0/0
Expand Down

0 comments on commit 605983c

Please sign in to comment.