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

req_cfgspec_all_diff method not working as intended #136

Closed rshxyz closed 5 years ago

rshxyz commented 5 years ago

req_cfgspec_all_diff is not working as intended. ignore_ws=False, seems to be ignoring white space. The output is not what it's suppose to be. It should include the " ip radius source-interface Vlan63"

from ciscoconfparse import CiscoConfParse
config = [
    'ip radius source-interface Vlan63',
    'logging 172.28.26.15',
    'aaa group server radius STUFF',
    ' server name radius',
    ' server name radius2',
    " ip radius source-interface Vlan33",
    ' deadtime 10',
    ] 
p = CiscoConfParse(config)
required_lines = [
    "logging 172.28.26.15",
    "logging 172.16.1.5",
    "ip radius source-interface Vlan63",
    " ip radius source-interface Vlan63",
    ]
diffs = p.req_cfgspec_all_diff(required_lines, ignore_ws=False)
print (diffs)
['logging 172.16.1.5']
mpenning commented 5 years ago

req_cfgspec_all_diff() only supports global configuration lines without child lines. It's functioning as expected.

mpenning commented 5 years ago

By the way, a better way of handling both parent and child lines is to use sync_diff(). An example, using your script follows:

from ciscoconfparse import CiscoConfParse
config = [
    'ip radius source-interface Vlan63',
    'logging 172.28.26.15',
    'aaa group server radius STUFF',
    ' server name radius',
    ' server name radius2',
    " ip radius source-interface Vlan33",
    ' deadtime 10',
    ]
p = CiscoConfParse(config)
required_lines = [
    "logging 172.28.26.15",
    "logging 172.16.1.5",
    'aaa group server radius STUFF',
    " ip radius source-interface Vlan63",
    ]

print p.sync_diff(required_lines, linespec="", remove_lines=False)