-
Notifications
You must be signed in to change notification settings - Fork 32
add huawei_vrp platform #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+174
−10
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
390b08b
add huawei_vpv8 platform
yanpla 2366b6e
Update hier_config/platforms/huawei_vrpv8/driver.py
yanpla d1ac906
restore walrus
yanpla 59a74a4
rename to huawei_vrp
yanpla 7ea9d79
remove override
yanpla 9f92355
Update CHANGELOG.md
yanpla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import re | ||
|
|
||
| from hier_config.child import HConfigChild | ||
| from hier_config.models import PerLineSubRule | ||
| from hier_config.platforms.driver_base import HConfigDriverBase, HConfigDriverRules | ||
|
|
||
|
|
||
| class HConfigDriverHuaweiVrp(HConfigDriverBase): | ||
| """Driver for Huawei VRP operating system. | ||
| Platform enum: ``Platform.HUAWEI_VRP``. | ||
| """ | ||
|
|
||
| @property | ||
| def negation_prefix(self) -> str: | ||
| return "undo " | ||
|
|
||
| def swap_negation(self, child: HConfigChild) -> HConfigChild: | ||
| if child.text.startswith(self.negation_prefix): | ||
| child.text = child.text.removeprefix(self.negation_prefix) | ||
| return child | ||
|
|
||
| text = child.text | ||
| if text.startswith("description "): | ||
| text = "description" | ||
| elif text.startswith("alias "): | ||
| text = "alias" | ||
| elif " remark " in text or text.startswith("remark "): | ||
| text = re.sub(r"^(.*?remark) .*", r"\1", text) | ||
| elif text.startswith("snmp-agent community "): | ||
| text = re.sub( | ||
| r"^(snmp-agent community (?:read |write )?(?:cipher )?\S+).*", | ||
| r"\1", | ||
| text, | ||
| ) | ||
|
|
||
| child.text = f"{self.negation_prefix}{text}" | ||
| return child | ||
|
|
||
| def sectional_exit(self, config: HConfigChild) -> str | None: | ||
| result = super().sectional_exit(config) | ||
| if result == "exit": | ||
| return "quit" | ||
| return result | ||
|
|
||
| @staticmethod | ||
| def _instantiate_rules() -> HConfigDriverRules: | ||
| return HConfigDriverRules( | ||
| per_line_sub=[ | ||
| PerLineSubRule(search="^\\s*[#!].*", replace=""), | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| from hier_config import get_hconfig_fast_load | ||
| from hier_config.constructors import get_hconfig | ||
| from hier_config.models import Platform | ||
|
|
||
|
|
||
| def test_merge_with_undo() -> None: | ||
| platform = Platform.HUAWEI_VRP | ||
| running_config = get_hconfig_fast_load( | ||
| platform, ("test_for_undo", "undo test_for_redo") | ||
| ) | ||
| generated_config = get_hconfig_fast_load( | ||
| platform, ("undo test_for_undo", "test_for_redo") | ||
| ) | ||
| remediation_config = running_config.config_to_get_to(generated_config) | ||
| assert remediation_config.dump_simple() == ("undo test_for_undo", "test_for_redo") | ||
|
|
||
|
|
||
| def test_negate_description() -> None: | ||
| platform = Platform.HUAWEI_VRP | ||
| running_config = get_hconfig_fast_load( | ||
| platform, ("interface GigabitEthernet0/0/0", " description some old blabla") | ||
| ) | ||
| generated_config = get_hconfig_fast_load( | ||
| platform, ("interface GigabitEthernet0/0/0",) | ||
| ) | ||
| remediation_config = running_config.config_to_get_to(generated_config) | ||
| assert remediation_config.dump_simple() == ( | ||
| "interface GigabitEthernet0/0/0", | ||
| " undo description", | ||
| ) | ||
|
|
||
|
|
||
| def test_negate_remark() -> None: | ||
| platform = Platform.HUAWEI_VRP | ||
| running_config = get_hconfig_fast_load( | ||
| platform, ("acl number 2000", " rule 5 remark some old remark") | ||
| ) | ||
| generated_config = get_hconfig_fast_load(platform, ("acl number 2000",)) | ||
| remediation_config = running_config.config_to_get_to(generated_config) | ||
| assert remediation_config.dump_simple() == ( | ||
| "acl number 2000", | ||
| " undo rule 5 remark", | ||
| ) | ||
|
|
||
|
|
||
| def test_negate_alias() -> None: | ||
| platform = Platform.HUAWEI_VRP | ||
| running_config = get_hconfig_fast_load( | ||
| platform, ("interface GigabitEthernet0/0/0", " alias some old alias") | ||
| ) | ||
| generated_config = get_hconfig_fast_load( | ||
| platform, ("interface GigabitEthernet0/0/0",) | ||
| ) | ||
| remediation_config = running_config.config_to_get_to(generated_config) | ||
| assert remediation_config.dump_simple() == ( | ||
| "interface GigabitEthernet0/0/0", | ||
| " undo alias", | ||
| ) | ||
|
|
||
|
|
||
| def test_negate_snmp_agent_community() -> None: | ||
| platform = Platform.HUAWEI_VRP | ||
| running_config = get_hconfig_fast_load( | ||
| platform, ("snmp-agent community read cipher %^%#blabla%^%# acl 2000",) | ||
| ) | ||
| generated_config = get_hconfig(platform) | ||
| remediation_config = running_config.config_to_get_to(generated_config) | ||
| assert remediation_config.dump_simple() == ( | ||
| "undo snmp-agent community read cipher %^%#blabla%^%#", | ||
| ) | ||
|
|
||
|
|
||
| def test_comments_stripped() -> None: | ||
| platform = Platform.HUAWEI_VRP | ||
| config = get_hconfig_fast_load( | ||
| platform, | ||
| ( | ||
| "#", | ||
| "! this is a comment", | ||
| "interface GigabitEthernet0/0/0", | ||
| " # another comment", | ||
| " description test", | ||
| "! yet another comment", | ||
| ), | ||
| ) | ||
| assert config.dump_simple() == ( | ||
| "interface GigabitEthernet0/0/0", | ||
| " description test", | ||
| ) | ||
|
|
||
|
|
||
| def test_sectional_exit_is_quit() -> None: | ||
| platform = Platform.HUAWEI_VRP | ||
| config = get_hconfig_fast_load( | ||
| platform, | ||
| ( | ||
| "interface GigabitEthernet0/0/0", | ||
| " description test", | ||
| ), | ||
| ) | ||
| assert config.dump_simple(sectional_exiting=True) == ( | ||
| "interface GigabitEthernet0/0/0", | ||
| " description test", | ||
| " quit", | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.