Automation

IMPORTANT MODERATION NOTICE

This community is currently under full moderation, meaning  all posts will be reviewed before appearing in the community. Please expect a brief delay—there is no need to post multiple times. If your post is rejected, you'll receive an email outlining the reason(s). We've implemented full moderation to control spam. Thank you for your patience and participation.



  • 1.  display diff in commit script

    Posted 08-05-2021 09:16
    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
    ------------------------------


  • 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.

    Elvin


  • 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?

    ------------------------------
    Dennis
    ------------------------------