Git Product home page Git Product logo

mpenning / ciscoconfparse2 Goto Github PK

View Code? Open in Web Editor NEW
18.0 18.0 6.0 3.23 MB

Parse, Audit, Query, Build, and Modify Cisco / Juniper / Palo Alto / F5 configurations.

Home Page: http://www.pennington.net/py/ciscoconfparse2/

License: GNU General Public License v3.0

Makefile 1.18% Python 98.62% Go 0.14% CSS 0.05%
automation cisco configuration-parser f5networks firewall juniper network network-management palo-alto-networks parse python router switch

ciscoconfparse2's Introduction

Hello ๐Ÿ‘‹, I'm Mike Pennington a Network Engineer from Austin, TX.

ciscoconfparse2's People

Contributors

mpenning avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ciscoconfparse2's Issues

[Bug]: save_as not working

Contact Details

No response

What happened?

When executing save_as i ran into an error instead of writing the config into the new file.

I was also able to fix this manually by changing ciscoconfparse2/ciscoconfparse2.py line 3548 to for line in self.objs.as_text though i am not sure that this is the intended way.

btw. this tool saved me a ton of python-programming and therefore time while rearranging configuration-files. Thanks a lot!

CiscoConfParse Version

0.7.43

What Operating System are you using?

MacOS

What Python version(s) have this problem?

Python 3.9

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

from ciscoconfparse2 import CiscoConfParse

parse = CiscoConfParse('example.conf', syntax='ios')
parse.save_as("example_parsed.conf")

Python tracebacks

Traceback (most recent call last):

> File "/Users/tabea.rieth/work/python_ztp/parser.py", line 51, in <module>
    origConfig.save_as("example_parsed.conf")
    โ”‚          โ”” <function CiscoConfParse.save_as at 0x1041325e0>
    โ”” <CiscoConfParse: 484 lines / syntax: ios / comment delimiters: ['!'] / auto_indent_width: 1 / factory: False / ignore_blank_l...

  File "/Users/tabea.rieth/Library/Python/3.9/lib/python/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3553, in save_as
    raise ee
  File "/Users/tabea.rieth/Library/Python/3.9/lib/python/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3548, in save_as
    for line in self.as_text:
                โ”” <CiscoConfParse: 484 lines / syntax: ios / comment delimiters: ['!'] / auto_indent_width: 1 / factory: False / ignore_blank_l...

AttributeError: 'CiscoConfParse' object has no attribute 'as_text'
  File "/Users/tabea.rieth/work/python_ztp/parser.py", line 51, in <module>
    origConfig.save_as("example_parsed.conf")
  File "/Users/tabea.rieth/Library/Python/3.9/lib/python/site-packages/loguru/_logger.py", line 1277, in catch_wrapper
    return function(*args, **kwargs)
  File "/Users/tabea.rieth/Library/Python/3.9/lib/python/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3553, in save_as
    raise ee
  File "/Users/tabea.rieth/Library/Python/3.9/lib/python/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3548, in save_as
    for line in self.as_text:
AttributeError: 'CiscoConfParse' object has no attribute 'as_text'

Relevant log output

No response

Code of Conduct

[Question]: install fails on apple silicon mac due to new dependency py-scrypt

Contact Details

No response

What happened?

Hello,

it looks like in the last day or so this library now has a dependency on py-scrypt directly beginning in version v0.6.2 (it looks like away from scrypt via hashlib), which at least for me causes installation failure via pip -- seems to be the same issue described here: holgern/py-scrypt#9

its unclear to me thus far if the fix described there solves the issue for Apple Silicon users, mostly I just wanted to report this as possible issue for other users in case others run into it or find solution. in the meantime I will revert to using v0.6.1 for my needs

CiscoConfParse Version

0.6.2

What Operating System are you using?

MacOS

What Python version(s) have this problem?

Python 3.11

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

pip3 install ciscoconfparse2

Python tracebacks

N/A - see log output with pip install failure messages

Relevant log output

pip3 install ciscoconfparse2
Collecting ciscoconfparse2
  Using cached ciscoconfparse2-0.6.7-py3-none-any.whl.metadata (19 kB)
Requirement already satisfied: attrs==23.2.0 in ./venv/lib/python3.11/site-packages (from ciscoconfparse2) (23.2.0)
Collecting dnspython<3.0.0,>=2.4.2 (from ciscoconfparse2)
  Using cached dnspython-2.6.1-py3-none-any.whl.metadata (5.8 kB)
Collecting hier_config>=2.2.3 (from ciscoconfparse2)
  Using cached hier_config-2.2.3-py3-none-any.whl.metadata (1.1 kB)
Collecting loguru==0.7.2 (from ciscoconfparse2)
  Using cached loguru-0.7.2-py3-none-any.whl.metadata (23 kB)
Collecting macaddress<3.0.0,>=2.0.2 (from ciscoconfparse2)
  Using cached macaddress-2.0.2-py3-none-any.whl.metadata (8.9 kB)
Collecting passlib<2.0.0,>=1.7.4 (from ciscoconfparse2)
  Using cached passlib-1.7.4-py2.py3-none-any.whl (525 kB)
Collecting pyparsing>=3.1.1 (from ciscoconfparse2)
  Using cached pyparsing-3.1.1-py3-none-any.whl.metadata (5.1 kB)
Requirement already satisfied: pyyaml==6.0.1 in ./venv/lib/python3.11/site-packages (from ciscoconfparse2) (6.0.1)
Collecting scrypt==0.8.20 (from ciscoconfparse2)
  Using cached scrypt-0.8.20.tar.gz (55 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Collecting tomlkit>=0.12.3 (from ciscoconfparse2)
  Using cached tomlkit-0.12.3-py3-none-any.whl.metadata (2.7 kB)
Collecting typeguard>=4.1.5 (from ciscoconfparse2)
  Using cached typeguard-4.1.5-py3-none-any.whl.metadata (3.7 kB)
Requirement already satisfied: typing-extensions>=4.7.0 in ./venv/lib/python3.11/site-packages (from typeguard>=4.1.5->ciscoconfparse2) (4.9.0)
Using cached ciscoconfparse2-0.6.7-py3-none-any.whl (229 kB)
Using cached loguru-0.7.2-py3-none-any.whl (62 kB)
Using cached dnspython-2.6.1-py3-none-any.whl (307 kB)
Using cached hier_config-2.2.3-py3-none-any.whl (21 kB)
Using cached macaddress-2.0.2-py3-none-any.whl (8.0 kB)
Using cached pyparsing-3.1.1-py3-none-any.whl (103 kB)
Using cached tomlkit-0.12.3-py3-none-any.whl (37 kB)
Using cached typeguard-4.1.5-py3-none-any.whl (34 kB)
Building wheels for collected packages: scrypt
  Building wheel for scrypt (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  ร— Building wheel for scrypt (pyproject.toml) did not run successfully.
  โ”‚ exit code: 1
  โ•ฐโ”€> [42 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-universal2-cpython-311
      creating build/lib.macosx-10.9-universal2-cpython-311/scrypt
      copying scrypt/__init__.py -> build/lib.macosx-10.9-universal2-cpython-311/scrypt
      copying scrypt/scrypt.py -> build/lib.macosx-10.9-universal2-cpython-311/scrypt
      creating build/lib.macosx-10.9-universal2-cpython-311/scrypt/tests
      copying scrypt/tests/__init__.py -> build/lib.macosx-10.9-universal2-cpython-311/scrypt/tests
      copying scrypt/tests/test_scrypt_py2x.py -> build/lib.macosx-10.9-universal2-cpython-311/scrypt/tests
      copying scrypt/tests/test_scrypt_py3x.py -> build/lib.macosx-10.9-universal2-cpython-311/scrypt/tests
      copying scrypt/tests/test_scrypt_c_module.py -> build/lib.macosx-10.9-universal2-cpython-311/scrypt/tests
      copying scrypt/tests/test_scrypt.py -> build/lib.macosx-10.9-universal2-cpython-311/scrypt/tests
      copying scrypt/tests/ciphertexts.csv -> build/lib.macosx-10.9-universal2-cpython-311/scrypt/tests
      copying scrypt/tests/hashvectors.csv -> build/lib.macosx-10.9-universal2-cpython-311/scrypt/tests
      running build_ext
      building '_scrypt' extension
      creating build/temp.macosx-10.9-universal2-cpython-311
      creating build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1
      creating build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/lib
      creating build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/lib/crypto
      creating build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/lib/scryptenc
      creating build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/lib/util
      creating build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/libcperciva
      creating build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/libcperciva/alg
      creating build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/libcperciva/crypto
      creating build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/libcperciva/util
      creating build/temp.macosx-10.9-universal2-cpython-311/src
      clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DHAVE_CONFIG_H -DHAVE_POSIX_MEMALIGN=1 -DHAVE_SYSCTL_HW_USERMEM=1 -Iscrypt-1.2.1 -Iscrypt-1.2.1/lib -Iscrypt-1.2.1/lib/scryptenc -Iscrypt-1.2.1/lib/crypto -Iscrypt-1.2.1/lib/util -Iscrypt-1.2.1/libcperciva/cpusupport -Iscrypt-1.2.1/libcperciva/alg -Iscrypt-1.2.1/libcperciva/util -Iscrypt-1.2.1/libcperciva/crypto -I/Users/wmclendon/coding/net-auditor/venv/include -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c scrypt-1.2.1/lib/crypto/crypto_scrypt.c -o build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/lib/crypto/crypto_scrypt.o
      clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DHAVE_CONFIG_H -DHAVE_POSIX_MEMALIGN=1 -DHAVE_SYSCTL_HW_USERMEM=1 -Iscrypt-1.2.1 -Iscrypt-1.2.1/lib -Iscrypt-1.2.1/lib/scryptenc -Iscrypt-1.2.1/lib/crypto -Iscrypt-1.2.1/lib/util -Iscrypt-1.2.1/libcperciva/cpusupport -Iscrypt-1.2.1/libcperciva/alg -Iscrypt-1.2.1/libcperciva/util -Iscrypt-1.2.1/libcperciva/crypto -I/Users/wmclendon/coding/net-auditor/venv/include -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c scrypt-1.2.1/lib/crypto/crypto_scrypt_smix.c -o build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/lib/crypto/crypto_scrypt_smix.o
      clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DHAVE_CONFIG_H -DHAVE_POSIX_MEMALIGN=1 -DHAVE_SYSCTL_HW_USERMEM=1 -Iscrypt-1.2.1 -Iscrypt-1.2.1/lib -Iscrypt-1.2.1/lib/scryptenc -Iscrypt-1.2.1/lib/crypto -Iscrypt-1.2.1/lib/util -Iscrypt-1.2.1/libcperciva/cpusupport -Iscrypt-1.2.1/libcperciva/alg -Iscrypt-1.2.1/libcperciva/util -Iscrypt-1.2.1/libcperciva/crypto -I/Users/wmclendon/coding/net-auditor/venv/include -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c scrypt-1.2.1/lib/crypto/crypto_scrypt_smix_sse2.c -o build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/lib/crypto/crypto_scrypt_smix_sse2.o
      clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DHAVE_CONFIG_H -DHAVE_POSIX_MEMALIGN=1 -DHAVE_SYSCTL_HW_USERMEM=1 -Iscrypt-1.2.1 -Iscrypt-1.2.1/lib -Iscrypt-1.2.1/lib/scryptenc -Iscrypt-1.2.1/lib/crypto -Iscrypt-1.2.1/lib/util -Iscrypt-1.2.1/libcperciva/cpusupport -Iscrypt-1.2.1/libcperciva/alg -Iscrypt-1.2.1/libcperciva/util -Iscrypt-1.2.1/libcperciva/crypto -I/Users/wmclendon/coding/net-auditor/venv/include -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c scrypt-1.2.1/lib/scryptenc/scryptenc.c -o build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/lib/scryptenc/scryptenc.o
      clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DHAVE_CONFIG_H -DHAVE_POSIX_MEMALIGN=1 -DHAVE_SYSCTL_HW_USERMEM=1 -Iscrypt-1.2.1 -Iscrypt-1.2.1/lib -Iscrypt-1.2.1/lib/scryptenc -Iscrypt-1.2.1/lib/crypto -Iscrypt-1.2.1/lib/util -Iscrypt-1.2.1/libcperciva/cpusupport -Iscrypt-1.2.1/libcperciva/alg -Iscrypt-1.2.1/libcperciva/util -Iscrypt-1.2.1/libcperciva/crypto -I/Users/wmclendon/coding/net-auditor/venv/include -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c scrypt-1.2.1/lib/scryptenc/scryptenc_cpuperf.c -o build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/lib/scryptenc/scryptenc_cpuperf.o
      clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DHAVE_CONFIG_H -DHAVE_POSIX_MEMALIGN=1 -DHAVE_SYSCTL_HW_USERMEM=1 -Iscrypt-1.2.1 -Iscrypt-1.2.1/lib -Iscrypt-1.2.1/lib/scryptenc -Iscrypt-1.2.1/lib/crypto -Iscrypt-1.2.1/lib/util -Iscrypt-1.2.1/libcperciva/cpusupport -Iscrypt-1.2.1/libcperciva/alg -Iscrypt-1.2.1/libcperciva/util -Iscrypt-1.2.1/libcperciva/crypto -I/Users/wmclendon/coding/net-auditor/venv/include -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c scrypt-1.2.1/lib/util/memlimit.c -o build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/lib/util/memlimit.o
      clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DHAVE_CONFIG_H -DHAVE_POSIX_MEMALIGN=1 -DHAVE_SYSCTL_HW_USERMEM=1 -Iscrypt-1.2.1 -Iscrypt-1.2.1/lib -Iscrypt-1.2.1/lib/scryptenc -Iscrypt-1.2.1/lib/crypto -Iscrypt-1.2.1/lib/util -Iscrypt-1.2.1/libcperciva/cpusupport -Iscrypt-1.2.1/libcperciva/alg -Iscrypt-1.2.1/libcperciva/util -Iscrypt-1.2.1/libcperciva/crypto -I/Users/wmclendon/coding/net-auditor/venv/include -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c scrypt-1.2.1/libcperciva/alg/sha256.c -o build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/libcperciva/alg/sha256.o
      clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DHAVE_CONFIG_H -DHAVE_POSIX_MEMALIGN=1 -DHAVE_SYSCTL_HW_USERMEM=1 -Iscrypt-1.2.1 -Iscrypt-1.2.1/lib -Iscrypt-1.2.1/lib/scryptenc -Iscrypt-1.2.1/lib/crypto -Iscrypt-1.2.1/lib/util -Iscrypt-1.2.1/libcperciva/cpusupport -Iscrypt-1.2.1/libcperciva/alg -Iscrypt-1.2.1/libcperciva/util -Iscrypt-1.2.1/libcperciva/crypto -I/Users/wmclendon/coding/net-auditor/venv/include -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c scrypt-1.2.1/libcperciva/crypto/crypto_aes.c -o build/temp.macosx-10.9-universal2-cpython-311/scrypt-1.2.1/libcperciva/crypto/crypto_aes.o
      scrypt-1.2.1/libcperciva/crypto/crypto_aes.c:6:10: fatal error: 'openssl/aes.h' file not found
      #include <openssl/aes.h>
               ^~~~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for scrypt
Failed to build scrypt
ERROR: Could not build wheels for scrypt, which is required to install pyproject.toml-based projects

Code of Conduct

[Bug]: Diff class error

Contact Details

[email protected]

What happened?

I tried to test the Diff Script that i found on the official documentation: http://www.pennington.net/py/ciscoconfparse2/tutorial_build_diffs.html#diff-script

for "old_config" i created the file "fullconfig.conf" with the following content:

interface Ethernet1/0/0
 description Connected to crouter1 Gi1 - 172.17.10.1/30
 undo shutdown
 ip address 172.17.10.2 255.255.255.0
 undo dcn
 undo dcn mode vlan
#
interface Ethernet1/0/1
 description Connected to crouter2 Gi2 - 172.17.50.1/30
 undo shutdown
 ip address 172.17.50.2 255.255.255.0
 undo dcn
 undo dcn mode vlan
#
interface Ethernet1/0/2
 description Connected to hrouter2 GE1/0/2 - 172.17.60.2/30
 undo shutdown
 ip address 172.17.60.1 255.255.255.0
 undo dcn mode vlan
#
interface Ethernet1/0/3
 description Management 192.168.56.103/24
 undo shutdown
 ip address 192.168.56.103 255.255.255.0
 undo dcn mode vlan
#
interface Ethernet1/0/4
 undo shutdown
 undo dcn mode vlan
#
interface Ethernet1/0/5
 undo shutdown
 undo dcn mode vlan
#
interface Ethernet1/0/6
 undo shutdown
 undo dcn mode vlan
#
interface Ethernet1/0/7
 undo shutdown
 undo dcn mode vlan
#
interface Ethernet1/0/8
 undo shutdown
 undo dcn mode vlan
#
interface Ethernet1/0/9
 undo shutdown
 undo dcn mode vlan
#
interface GigabitEthernet0/0/0
 undo shutdown

For "new_config" i created the file "newconfig.conf" with the following content

interface Ethernet1/0/2
shutdown

When I got to this line.:

diff = Diff(old_config=old_config, new_config=new_config)

I had an error, that i think could be a bug. See the part of the traceback that catched my attention:

in _load_from_string_lines
    for line in config_text.splitlines():
                โ”” ['interface Ethernet1/0/2', 'shutdown']

AttributeError: 'list' object has no attribute 'splitlines'

The code is expecting object "config_text" to be a String and convert it to a list. But it seems that it was already converted to a List in a step before.

CiscoConfParse Version

0.7.33

What Operating System are you using?

Linux - Debian, Ubuntu, CentOS, RHEL or others

What Python version(s) have this problem?

Python 3.10

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

from ciscoconfparse2.ciscoconfparse2 import Diff

# Parse the original configuration
old_config = 'fullconfig.conf'
new_config = 'newconfig.conf'

diff = Diff(old_config=old_config, new_config=new_config)

Python tracebacks

2024-04-06 13:13:54.391 | ERROR    | __main__:<module>:1 - An error has been caught in function '<module>', process 'MainProcess' (44632), thread 'MainThread' (140103149501312):
Traceback (most recent call last):

> File "<stdin>", line 1, in <module>
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3716, in __init__
    self.host.load_generated_config(new_config)
    โ”‚    โ”‚                          โ”” ['interface Ethernet1/0/2', 'shutdown']
    โ”‚    โ”” <member 'host' of 'Diff' objects>
    โ”” <ciscoconfparse2.ciscoconfparse2.Diff object at 0x7f6c4aecc100>
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/host.py", line 127, in load_generated_config
    self._generated_config = self._load_config(config_text)
    โ”‚    โ”‚                   โ”‚    โ”‚            โ”” ['interface Ethernet1/0/2', 'shutdown']
    โ”‚    โ”‚                   โ”‚    โ”” <function Host._load_config at 0x7f6c4c069fc0>
    โ”‚    โ”‚                   โ”” Host(hostname=example_hostname)
    โ”‚    โ”” None
    โ”” Host(hostname=example_hostname)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/host.py", line 164, in _load_config
    hier.load_from_string(config_text)
    โ”‚    โ”‚                โ”” ['interface Ethernet1/0/2', 'shutdown']
    โ”‚    โ”” <function HConfig.load_from_string at 0x7f6c4bfee680>
    โ”” HConfig(host=Host(hostname=example_hostname))
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/root.py", line 140, in load_from_string
    self._load_from_string_lines(config_text)
    โ”‚    โ”‚                       โ”” ['interface Ethernet1/0/2', 'shutdown']
    โ”‚    โ”” <function HConfig._load_from_string_lines at 0x7f6c4bfeee60>
    โ”” HConfig(host=Host(hostname=example_hostname))
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/root.py", line 337, in _load_from_string_lines
    for line in config_text.splitlines():
                โ”” ['interface Ethernet1/0/2', 'shutdown']

AttributeError: 'list' object has no attribute 'splitlines'
2024-04-06 13:13:54.391 | ERROR    | __main__:<module>:1 - An error has been caught in function '<module>', process 'MainProcess' (44632), thread 'MainThread' (140103149501312):
Traceback (most recent call last):

> File "<stdin>", line 1, in <module>
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3716, in __init__
    self.host.load_generated_config(new_config)
    โ”‚    โ”‚                          โ”” ['interface Ethernet1/0/2', 'shutdown']
    โ”‚    โ”” <member 'host' of 'Diff' objects>
    โ”” <ciscoconfparse2.ciscoconfparse2.Diff object at 0x7f6c4aecc100>
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/host.py", line 127, in load_generated_config
    self._generated_config = self._load_config(config_text)
    โ”‚    โ”‚                   โ”‚    โ”‚            โ”” ['interface Ethernet1/0/2', 'shutdown']
    โ”‚    โ”‚                   โ”‚    โ”” <function Host._load_config at 0x7f6c4c069fc0>
    โ”‚    โ”‚                   โ”” Host(hostname=example_hostname)
    โ”‚    โ”” None
    โ”” Host(hostname=example_hostname)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/host.py", line 164, in _load_config
    hier.load_from_string(config_text)
    โ”‚    โ”‚                โ”” ['interface Ethernet1/0/2', 'shutdown']
    โ”‚    โ”” <function HConfig.load_from_string at 0x7f6c4bfee680>
    โ”” HConfig(host=Host(hostname=example_hostname))
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/root.py", line 140, in load_from_string
    self._load_from_string_lines(config_text)
    โ”‚    โ”‚                       โ”” ['interface Ethernet1/0/2', 'shutdown']
    โ”‚    โ”” <function HConfig._load_from_string_lines at 0x7f6c4bfeee60>
    โ”” HConfig(host=Host(hostname=example_hostname))
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/root.py", line 337, in _load_from_string_lines
    for line in config_text.splitlines():
                โ”” ['interface Ethernet1/0/2', 'shutdown']

AttributeError: 'list' object has no attribute 'splitlines'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/loguru/_logger.py", line 1277, in catch_wrapper
    return function(*args, **kwargs)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3716, in __init__
    self.host.load_generated_config(new_config)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/host.py", line 127, in load_generated_config
    self._generated_config = self._load_config(config_text)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/host.py", line 164, in _load_config
    hier.load_from_string(config_text)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/root.py", line 140, in load_from_string
    self._load_from_string_lines(config_text)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/root.py", line 337, in _load_from_string_lines
    for line in config_text.splitlines():
AttributeError: 'list' object has no attribute 'splitlines'

Relevant log output

No Logs

Code of Conduct

Full IOS-XR support

Dear Mike,

Thanks for building this awesome tool. I've been using it for some time now and it has helped tremendously with my projects. I've previously opened a bug report on the previous version of ciscoconfparse relating to route-policies in IOS-XR and the fact that regex wasn't properly escaped. However, now I'd like to open a feature request, because I'm noticing other issues with IOS-XR as well.

In short, I would like better support for XR specific syntax in this tool. There are several components that do not behave the same way as IOS-XE or the other components in XR. These components are:

  • route-policy
  • community-set
  • prefix-set
    potentially more..

Below are some config examples and I'm sure you will immediately recognise why I have some problems, especially with the diffs.

route-policy:

route-policy RP-PASS
  pass
end-policy
!
route-policy RP-MOD($COMM1, $COMM2)
  if community matches-any $COMM1 then
    drop
  elseif community matches-any $COMM2 then
    pass
  endif
end-policy

community-set

community-set SHUTDOWN-COMM
  65535:0
end-set

prefix-set:

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

Problems that currently occur:

  • end-set or end-policy are not a child of the preceeding config. In the diff, this does not show up because the diff doesn't handle it properly. If I want to add more configuration to another set (or extract), then I need to "hack" those statements in there as it won't be part of any object that ciscoconfparse finds.
  • For example in the prefix-set, if i do a diff to get the commands to change something, and two prefixes have a different order, then I will see the following for example:
prefix-set PEERINGS
  172.16.0.0/12,
  10.0.1.0/24,

There are three problems with that:

  1. It'll overwrite the existing prefix-set
  2. shows a comma, but the last entry will never have one
  3. it's missing the end-set statement

There are likely more issues, but these are the ones i'm currently running into.

I wouldn't mind helping out, but I would first have to get comfortable with the codebase here. Also, the question is if IOS-XR would require it's own code, be a derivative of XE or only modify the default IOS codeset to support both.

Kr.

ciscoconfparse2 is slower than ciscoconfparse

Question

When parsing a large configuration such as tests/fixtures/configs/sample_06.ios and auto_commit=True, ciscoconfparse2 version 0.2.5 takes about 1.55 seconds on my system; however, parsing the same configuration with ciscoconfparse version
1.9.41 takes about 1.40 seconds.

sample_06.ios has over 4700 physical and virtual interfaces.

Why is ciscoconfparse2 about 10% slower?

try:
    # fail if we can't import ciscoconfparse2
    from ciscoconfparse2 import CiscoConfParse
except BaseException:
    from ciscoconfparse import CiscoConfParse

# auto_commit defaults True in ciscoconfparse2
parse = CiscoConfParse('tests/fixtures/configs/sample_06.ios', syntax='ios')

Answer:

This is due to the safety features that ciscoconfparse2 has; specifically it's due to the additional configuration safety built with in the ConfigList().get_checkpoint() method. get_checkpoint() is called with each commit() operation.

As of version 0.2.5, there are two big rocks that could chew up a lot of time:

  • assign_parent_to_closing_braces() which is a function from legacy ciscoconfparse
  • ConfigList().get_checkpoint(), which is a new method in ciscoconfparse2

Making ciscoconfparse2 significantly faster is a long-term improvement, if possible.

[Bug]: F5-style open / close curly-braces on the same line are broken

Contact Details

[email protected]

What happened?

Using ciscoconfparse2 version 0.5.0, this script does not see children on bar1 and bar2 correctly... bar1 and bar2 should have children, but they do not.

CiscoConfParse Version

0.5.0

What Operating System are you using?

Other (please specify)

What Python version(s) have this problem?

Other (please specify)

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

from ciscoconfparse2.ciscoconfparse2 import BraceParse

config = """
foo1
foo2 {
    bar1 { this }
    bar2 { that }
}
"""

braces = BraceParse(config)
for obj in braces.get_junoscfgline_list():
    print(obj)

The output below is missing this and that children...

<JunosCfgLine # 0 'foo1'>
<JunosCfgLine # 1 'foo2'>
<JunosCfgLine # 2 '    bar1'>
<JunosCfgLine # 3 '        bar2'>
<JunosCfgLine # 4 ''>


### Python tracebacks

N/A


### Relevant log output

_No response_

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/mpenning/ciscoconfparse2/blob/main/CONTRIBUTING.md)

[Bug]: loguru infinite recursion with JunOS configurations

Contact Details

No response

What happened?

from loguru import logger

from ciscoconfparse2 import CiscoConParse

if False:
    logger.opt(capture=False).info("try to stop infinite recursion")
    logger.opt(exception=False).info("try to stop infinite recursion")
    logger.opt(depth=0).info("try to stop infinite recursion")

parse = CiscoConfParse("tests/fixtures/configs/sample_01.junos", syntax="junos", factory=False)
print(parse)
for obj in parse.objs:
    print(obj)

CiscoConfParse Version

git main hash 1a7b88d

What Operating System are you using?

Linux - Debian, Ubuntu, CentOS, RHEL or others

What Python version(s) have this problem?

Python 3.10, Python 3.9, Python 3.8, Python 3.7

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

from loguru import logger

from ciscoconfparse2 import CiscoConParse

if False:
    logger.opt(capture=False).info("try to stop infinite recursion")
    logger.opt(exception=False).info("try to stop infinite recursion")
    logger.opt(depth=0).info("try to stop infinite recursion")

parse = CiscoConfParse("tests/fixtures/configs/sample_01.junos", syntax="junos", factory=False)
print(parse)
for obj in parse.objs:
    print(obj)

Python tracebacks

File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 528, in format_exception
    yield from self._format_exception(value, tb, is_first=True, from_decorator=from_decorator)
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 415, in _format_exception
    yield from self._format_exception(
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 415, in _format_exception
    yield from self._format_exception(
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 415, in _format_exception
    yield from self._format_exception(
  [Previous line repeated 27 more times]
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 447, in _format_exception
    frames, final_source = self._extract_frames(
                           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 249, in _extract_frames
    values = self._format_relevant_values(list(relevant_values), colorize)
                                          ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 281, in _get_relevant_values
    pending = (col, self._format_value(value))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 333, in _format_value
    v = repr(v)
        ^^^^^^^
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_logger.py", line 1276, in catch_wrapper
    with catcher:
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_logger.py", line 1243, in __exit__
    logger._log(level, from_decorator, catch_options, message, (), {})
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_logger.py", line 2032, in _log
    handler.emit(log_record, level_id, from_decorator, raw, colored_message)
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_handler.py", line 147, in emit
    formatter_record["exception"] = "".join(lines)
                                    ^^^^^^^^^^^^^^
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 528, in format_exception
    yield from self._format_exception(value, tb, is_first=True, from_decorator=from_decorator)
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 415, in _format_exception
    yield from self._format_exception(
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 415, in _format_exception
    yield from self._format_exception(
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 415, in _format_exception
    yield from self._format_exception(
  [Previous line repeated 28 more times]
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 447, in _format_exception
    frames, final_source = self._extract_frames(
                           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/python/virtualenv/py311_test/lib/python3.11/site-packages/loguru/_better_exceptions.py", line 249, in _extract_frames
    values = self._format_relevant_values(list(relevant_values), colorize)

Relevant log output

Infinite loop of the traceback above

Code of Conduct

[Bug]: order does not matter for policy-map

Contact Details

No response

What happened?

The diff does not show differences in ordering on policy-map directives

(python 3.11)

CiscoConfParse Version

0.3.3

What Operating System are you using?

Linux - Debian, Ubuntu, CentOS, RHEL or others

What Python version(s) have this problem?

Python 3.10

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

from ciscoconfparse2 import Diff

running = """
policy-map type inspect pm-self-to-accesspoints
  class type inspect cm-self-to-accesspoints
    inspect
  class type inspect self-to-any-dhcp
    pass
  class class-default
    drop
"""
generated = """
policy-map type inspect pm-self-to-accesspoints
  class type inspect self-to-any-dhcp
    pass
  class type inspect cm-self-to-accesspoints
    inspect
  class class-default
    drop
"""
diff = Diff(old_config=running, new_config=generated)
for line in diff.get_diff():
    print(line)

Python tracebacks

none

Relevant log output

no output / diff. however, the configs differ semantically.

see
https://community.cisco.com/t5/switching/evaluation-order-of-class-maps-under-policy-map/td-p/2834242
https://community.cisco.com/t5/routing/qos-policy-map-classes-order/td-p/1863137

Code of Conduct

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.