Junos Automation (Scripting)
Junos Automation (Scripting)

python commit script question

‎08-11-2019 02:46 AM

Hi,

I am trying to to write an on-box commit script via python which should stop the commit in case certain part of the configuration is changed - for example if somebody changed interface lo0 in any way, the commit should fail. I know there is the Python object Junos_Configuration which contains the candidate configuration, but there I can't check what exactly will be changed after the commit. Is there some other object which contains something like the result of show | compare which I could check? Or is there some other way to achieve this with Python commit script?

2 REPLIES 2
Junos Automation (Scripting)

Re: python commit script question

‎08-11-2019 05:27 AM

Hello Marvin,

 

Have you tried pdiff() method to compare the previously and the candidate configuration? I´m not sure, but I probably would try use it before loading new configuration and compare if there is something new in the candidate configuration before starting changes.

 

Best regards,

 

 

Junos Automation (Scripting)

Re: python commit script question

‎08-11-2019 05:33 AM

Hi, you can check for [@junos:changed='changed'] in configuration.

 

For example this will find all interfaces where filter was changed

root = Junos_Configuration
namespaces = {'junos': 'http://xml.juniper.net/junos/*/junos'}
for iflt in root.findall("./interfaces/interface/unit/family/*/filter[@junos:changed='changed']", namespaces) :