diff --git a/hier_config/root.py b/hier_config/root.py index a915639..694c793 100644 --- a/hier_config/root.py +++ b/hier_config/root.py @@ -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. @@ -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 diff --git a/tests/fixtures/remediation_config_flat_junos.conf b/tests/fixtures/remediation_config_flat_junos.conf index a5cf0ac..33e0179 100644 --- a/tests/fixtures/remediation_config_flat_junos.conf +++ b/tests/fixtures/remediation_config_flat_junos.conf @@ -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"; \ No newline at end of file +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" \ No newline at end of file