mpenning / ciscoconfparse

Parse, Audit, Query, Build, and Modify Arista / Cisco / Juniper / Palo Alto / F5 configurations.
http://www.pennington.net/py/ciscoconfparse/
GNU General Public License v3.0
793 stars 220 forks source link

[Feature request]: Cisco ASA ipv6 static route with factory=True #240

Closed metrax closed 2 years ago

metrax commented 2 years ago

Contact Details

metrax@metrax.eu

What happened?

Could not parse 'ipv6 route testnetz_transfer aaaa:aaaa:aaaa:bbbb::/64 aaaa:aaaa:aaaa:aaaa::2'

It looks like that the regex in modesl_cisco.py line 63864 is not detecting this string. I've played around a little bit with the regex, but couldn't fix it (due to my bad regex skills ;-)).

It's a Cisco ASA5550

CiscoConfParse Version

1.6.40

What Operating System are you using?

Linux - Debian, Ubuntu, CentOS, RHEL or others

What Python version(s) have this problem?

Python 3.8

Show us how to reproduce the problem. Please tell us if the problem is specific to certain inputs or situations.

from ciscoconfparse import CiscoConfParse

parse = CiscoConfParse("configs/file.txt",factory=True)

Python tracebacks

2022-05-12 16:03:43.506 | ERROR    | __main__:<module>:4 - An error has been caught in function '<module>', process 'MainProcess' (1700), thread 'MainThread' (140377853413184):
Traceback (most recent call last):

> File "test.py", line 4, in <module>
    parse = CiscoConfParse("configs/fw-config.txt",factory=True)
            └ <function CiscoConfParse at 0x7fac429803a0>

  File "/home/xxx/.local/lib/python3.8/site-packages/ciscoconfparse/ciscoconfparse.py", line 275, in __init__
    self.ConfigObjs = self.config_list(data=config)
    │    │            │    │                └ ['! ', '! Cisco Adaptive Security Appliance Software Version 9.1(7)32 ', '! Device Manager Version 7.9(1)', '! ', '! Compiled...
    │    │            │    └ <unprintable partial object>
    │    │            └ <unprintable CiscoConfParse object>
    │    └ None
    └ <unprintable CiscoConfParse object>
  File "/home/xxx/.local/lib/python3.8/site-packages/ciscoconfparse/ciscoconfparse.py", line 3426, in __init__
    self._list = self._bootstrap_obj_init_ios(data)
    │    │       │    │                       └ ['! ', '! Cisco Adaptive Security Appliance Software Version 9.1(7)32 ', '! Device Manager Version 7.9(1)', '! ', '! Compiled...
    │    │       │    └ <function ConfigList._bootstrap_obj_init_ios at 0x7fac429840d0>
    │    │       └ <ConfigList, syntax='ios', comment='!', conf=[]>
    │    └ []
    └ <ConfigList, syntax='ios', comment='!', conf=[]>
  File "/home/xxx/.local/lib/python3.8/site-packages/ciscoconfparse/ciscoconfparse.py", line 4096, in _bootstrap_obj_init_ios
    obj = ConfigLineFactory(
          └ <function ConfigLineFactory at 0x7fac42983280>
  File "/home/xxx/.local/lib/python3.8/site-packages/ciscoconfparse/ciscoconfparse.py", line 5839, in ConfigLineFactory
    inst = cls(
           └ <class 'ciscoconfparse.models_cisco.IOSRouteLine'>
  File "/home/xxx/.local/lib/python3.8/site-packages/ciscoconfparse/models_cisco.py", line 1998, in __init__
    raise ValueError("Could not parse '{0}'".format(self.text))
                                                    │    └ <property object at 0x7fac42a400e0>
                                                    └ <unprintable IOSRouteLine object>

ValueError: Could not parse 'ipv6 route testnetz_transfer aaaa:aaaa:aaaa:bbbb::/64 aaaa:aaaa:aaaa:aaaa::2'

Relevant log output

No response

Code of Conduct

mpenning commented 2 years ago

Hello @Metrax,

I removed the bug label because this is not a bug. The way you're using the factory parser is not correct.

from ciscoconfparse import CiscoConfParse

parse = CiscoConfParse("configs/file.txt",factory=True)
#                                         ^^^^^^^^^^^^

What are you hoping to do once the configuration is parsed?

This will work with no problems...

from ciscoconfparse import CiscoConfParse

asa_config = ['ipv6 route testnetz_transfer aaaa:aaaa:aaaa:bbbb::/64 aaaa:aaaa:aaaa:aaaa::2']
parse = CiscoConfParse(asa_config)

Please note that factory is False by default; the factory functionality is somewhere between alpha and beta quality (depending on what you're trying to do). If you try to use factory=True, the configuration syntax is checked against expected IOS static route configuration syntax (because syntax defaults to ios). However IOS doesn't use interface zone names...

Unfortunately, parsing with the ASA config factory classifier is not in a useful state for ASA static routes as of version 1.6.40. I can consider this as a request to change ASA factory parsing to understand ASA static routes... but as soon as you get that, there are 20 other ASA syntax factory features that won't work.

metrax commented 2 years ago

Hi @mpenning,

i'm using ciscoconfparse to automatically import the interfaces, the vlans and ip addresses from our cisco routers, switches and the ASAs config to netbox (https://github.com/netbox-community/netbox/).

I've started without factory mode, but had some problems, i dont' remember them. I just remember that it was realy complicated for me, to use it. I also tried the ASA module, but got a lot of errors. After activating factory mode, i could use the module easily for importing the interfaces and their configurations. It was working fine, until the colleagues from the firewall administration added the ipv6 route rules (unfortunatly on my request ... hehe :-( ).

I've fixed my issue now, with removing the ipv6 route lines before parsing the configuration with ciscoconfparse. Its fine, because i don't need these options for my script.

But it would be nice, if you can add this later.

Thank you very much (also for this awesome libary).

Bests,

Metrax

github-actions[bot] commented 2 years ago

This issue has automatically been marked stale due to inactivity. The issue will close unless further activity occurs. Please understand that the CiscoConfParse team is not obligated to comment on every issue. For more detailed information, please refer to our CONTRIBUTING guidance -> https://github.com/mpenning/ciscoconfparse/blob/main/.github/CONTRIBUTING.md

github-actions[bot] commented 2 years ago

Due to inactivity, CiscoConfParse's maintainers are closing this issue. Please refrain from further comments. In the future, CiscoConfParse's maintainers may reopen it solely at their own discretion. For more detailed information, please refer to our CONTRIBUTING guidance -> https://github.com/mpenning/ciscoconfparse/blob/main/.github/CONTRIBUTING.md