View Only
last person joined: 4 days ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  display diff in commit script

    Posted 08-05-2021 09:16

    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()
        cu = Config(dev)
        diff = cu.diff(1)
        if diff:
          jcs.emit_warning("Do something")
          print(f"Here's the diff\n{diff}")
          print("nothing to sync")
    if __name__ == '__main__':
    And that seems to work just fine:
    srx-1# run op
    warning: Do something
    Here's the diff
    [edit system scripts op]
    +     file;

    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__':

    Can I use this root object to show the diff before or after committing the candidate?



    Dennis Wallberg

  • 2.  RE: display diff in commit script

    Posted 08-25-2021 11:01
    You could try to upload the config to the device itself, but instead of doing commit do a commit confirm with Netconf and based on the result of the rpc call, indicate success or not.


  • 3.  RE: display diff in commit script

    Posted 09-02-2021 11:12
    So the idea was just to have the diff showed to the operator that are commiting local changes, but I guess its not possible to do this with a commit script?