Skip to content

Commit

Permalink
rm ;
Browse files Browse the repository at this point in the history
  • Loading branch information
jtdub committed Jan 16, 2024
1 parent 9f1cb7e commit d524c8f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 53 deletions.
38 changes: 4 additions & 34 deletions hier_config/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,40 +439,6 @@ def _duplicate_child_allowed_check(self) -> bool:
"""Determine if duplicate(identical text) children are allowed under the parent"""
return False

def _preprocess_config(self, config_str: str) -> str:
"""
Preprocess the config string before parsing it into HConfig.
This is used to convert the config string into a format that is
in a Juniper style syntax.
Args:
config_str (str): The config string to preprocess
Returns:
preprocessed_config_str (str): The preprocessed config string
"""
if self.options["syntax_style"] == "juniper":
indent_level = 0
preproccessed_lines = []

for line in config_str.splitlines():
line = line.strip()
if line.endswith("{"):
preproccessed_lines.append(
" " * indent_level + line[:-1].strip()
)
indent_level += 1
elif line == "}":
indent_level -= 1
else:
preproccessed_lines.append(" " * indent_level + line)

preproccessed_config_str = "\n".join(preproccessed_lines)
else:
preproccessed_config_str = config_str

return preproccessed_config_str

def _convert_to_set_commands(self, config_str: str) -> str:
"""
Convert a Junupier style config string into a list of set commands.
Expand All @@ -494,6 +460,10 @@ def _convert_to_set_commands(self, config_str: str) -> str:
if not stripped_line:
continue

# Strip ; from the end of the line
if stripped_line.endswith(";"):
stripped_line = stripped_line.replace(";", "")

# Count the number of spaces at the beginning to determine the level
level = line.find(stripped_line) // 4

Expand Down
38 changes: 19 additions & 19 deletions tests/fixtures/remediation_config_flat_junos.conf
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
delete vlans switch_mgmt_10.0.4.0/24 vlan-id 3;
delete vlans switch_mgmt_10.0.4.0/24 l3-interface irb.3;
delete interfaces irb unit 2 family inet description "switch_10.0.2.0/24";
delete interfaces irb unit 2 family inet disable;
delete interfaces irb unit 3 family inet address 10.0.4.1/16;
delete interfaces irb unit 3 family inet description "switch_mgmt_10.0.4.0/24";
set vlans switch_mgmt_10.0.3.0/24 vlan-id 3;
set vlans switch_mgmt_10.0.3.0/24 l3-interface irb.3;
set vlans switch_mgmt_10.0.4.0/24 vlan-id 4;
set vlans switch_mgmt_10.0.4.0/24 l3-interface irb.4;
set interfaces irb unit 2 family inet filter input TEST;
set interfaces irb unit 2 family inet mtu 9000;
set interfaces irb unit 2 family inet description "switch_mgmt_10.0.2.0/24";
set interfaces irb unit 3 family inet address 10.0.3.1/16;
set interfaces irb unit 3 family inet description "switch_mgmt_10.0.3.0/24";
set interfaces irb unit 4 family inet address 10.0.4.1/16;
set interfaces irb unit 4 family inet filter input TEST;
set interfaces irb unit 4 family inet mtu 9000;
set interfaces irb unit 4 family inet description "switch_mgmt_10.0.4.0/24";
delete vlans switch_mgmt_10.0.4.0/24 vlan-id 3
delete vlans switch_mgmt_10.0.4.0/24 l3-interface irb.3
delete interfaces irb unit 2 family inet description "switch_10.0.2.0/24"
delete interfaces irb unit 2 family inet disable
delete interfaces irb unit 3 family inet address 10.0.4.1/16
delete interfaces irb unit 3 family inet description "switch_mgmt_10.0.4.0/24"
set vlans switch_mgmt_10.0.3.0/24 vlan-id 3
set vlans switch_mgmt_10.0.3.0/24 l3-interface irb.3
set vlans switch_mgmt_10.0.4.0/24 vlan-id 4
set vlans switch_mgmt_10.0.4.0/24 l3-interface irb.4
set interfaces irb unit 2 family inet filter input TEST
set interfaces irb unit 2 family inet mtu 9000
set interfaces irb unit 2 family inet description "switch_mgmt_10.0.2.0/24"
set interfaces irb unit 3 family inet address 10.0.3.1/16
set interfaces irb unit 3 family inet description "switch_mgmt_10.0.3.0/24"
set interfaces irb unit 4 family inet address 10.0.4.1/16
set interfaces irb unit 4 family inet filter input TEST
set interfaces irb unit 4 family inet mtu 9000
set interfaces irb unit 4 family inet description "switch_mgmt_10.0.4.0/24"

0 comments on commit d524c8f

Please sign in to comment.