Skip to content
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

IOS XR end-set should not be indented #130

Open
mpenning opened this issue May 5, 2024 · 1 comment
Open

IOS XR end-set should not be indented #130

mpenning opened this issue May 5, 2024 · 1 comment

Comments

@mpenning
Copy link

mpenning commented May 5, 2024

As one can see here, hier_config IOS XR diff end-set should not be indented... explicitly, this seems to be (slightly) wrong in hier_config version 2.2.3...

Contents of before.txt...

prefix-set ALL
  0.0.0.0/0 eq 32
end-set
!
prefix-set PEERINGS
  1.1.1.1/32,
  2.2.2.2/32,
  10.0.1.0/24,
  172.16.0.0/12,
  192.168.3.0/26
end-set

Contents of after.txt...

prefix-set ALL
  0.0.0.0/0 eq 32
end-set
!
prefix-set PEERINGS
  1.1.1.1/32,
  172.16.0.0/12,
  192.168.3.0/26
end-set

ciscoconfparse2 uses hier_config for all diffs... The diff end-set is indented when it shouldn't be, but I think that will be cosmetic... sadly I don't have an IOS XR system to test against...

(py311_test) mpenning@mudslide:~/$ python
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ciscoconfparse2 import Diff
>>> diff = Diff('before.txt', 'after.txt', syntax='iosxr')
>>> diff.get_diff()
['prefix-set PEERINGS', '  1.1.1.1/32,', '  172.16.0.0/12,', '  192.168.3.0/26', '  end-set']
>>>
@jtdub
Copy link
Contributor

jtdub commented Dec 18, 2024

By default, hier_config adds the exit_text at the same level that it's currently at:

https://github.com/netdevops/hier_config/blob/master/hier_config/child.py#L116-L117

        if sectional_exiting and (exit_text := self.sectional_exit):
            yield " " * self.driver.rules.indentation * self.depth() + exit_text

I think we should add a depth option fo the SectionalExitiingRule model:

https://github.com/netdevops/hier_config/blob/master/hier_config/models.py#L35-L37

class SectionalExitingRule(BaseModel):
    match_rules: tuple[MatchRule, ...]
    exit_text: str

The default could be 0 and we could set the value to -1 where the exit text should be unindented.

https://github.com/netdevops/hier_config/blob/master/hier_config/platforms/cisco_xr/driver.py#L40-L66

            sectional_exiting=[
                SectionalExitingRule(
                    match_rules=(MatchRule(startswith="route-policy"),),
                    exit_text="end-policy",
                ),
                SectionalExitingRule(
                    match_rules=(MatchRule(startswith="prefix-set"),),
                    exit_text="end-set",
                ),
                SectionalExitingRule(
                    match_rules=(MatchRule(startswith="policy-map"),),
                    exit_text="end-policy-map",
                ),
                SectionalExitingRule(
                    match_rules=(MatchRule(startswith="class-map"),),
                    exit_text="end-class-map",
                ),
                SectionalExitingRule(
                    match_rules=(MatchRule(startswith="community-set"),),
                    exit_text="end-set",
                ),
                SectionalExitingRule(
                    match_rules=(MatchRule(startswith="extcommunity-set"),),
                    exit_text="end-set",
                ),
                SectionalExitingRule(
                    match_rules=(MatchRule(startswith="template"),),
                    exit_text="end-template",
                ),
            ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants