Hi,
I am trying to create a commit script to show me the diff of candidate config before (or after commit if possible?) is this possible to do with a commit script?
I tried something like this with a simple OP script
#!/usr/bin/env python
from jnpr.junos import Device
from jnpr.junos.utils.config import Config
import jcs
def main():
dev = Device()
dev.open()
cu = Config(dev)
diff = cu.diff(1)
if diff:
jcs.emit_warning("Do something")
print(f"Here's the diff\n{diff}")
else:
print("nothing to sync")
dev.close()
if __name__ == '__main__':
main()
And that seems to work just fine:
srx-1# run op tt.py
warning: Do something
Here's the diff
[edit system scripts op]
+ file tt.py;
So the question is can I do this with a commit script? The candidate config seems to be available to a commit script just by importing Junos_Configuration
from junos import Junos_Configuration
import jcs
def main():
# Get the configuration root object
root = Junos_Configuration
if __name__ == '__main__':
main()
Can I use this root object to show the diff before or after committing the candidate?
Thanks!
/Dennis
------------------------------
Dennis Wallberg
------------------------------