Automation

 View Only
last person joined: 5 days ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  Using PyEZ in on-box commit scripts

    This message was posted by a user wishing to remain anonymous
    Posted 29 days ago
    This message was posted by a user wishing to remain anonymous

    Does anyone know whether it's possible to commit configuration using a Python based commit script, using PyEZ with set commands?

    LLMs are hallucinating telling me it's possible, but I'm struggling to find resources pointing to PyEZ's usage on box, despite it being outlined as a supported library https://www.juniper.net/documentation/us/en/software/junos/automation-scripting/topics/concept/junos-python-modules-on-device.html and with most examples I can find point to jcs.emit_change() where only XML based changes are possible.

    In essence, I wish to do the below, where change is any valid set command, but I seem to hit an issue that I assume is essentially related to the commit script itself locking the database, and then an attempt made within the commit script to lock the database.

    Should I be trying to use an ephemeral database instead, or taking another approach? Does anyone have a working, on-box, pyez example?

    Thanks in advance.

        with Device() as dev:
            with Config(dev, mode='private') as cfg:
              cfg.load(change,format="set", merge=True)
              cfg.commit(comment="pyez load attempt")


  • 2.  RE: Using PyEZ in on-box commit scripts

    Posted 29 days ago
    Edited by RYOTA KOSAKA 29 days ago

    Hi

    From my understanding, you can't do that.
    PyEZ uses netconf, which in turn uses the Junos XML API to manipulate devices.
    If you want to use "set commands", you will need to use a ssh-based or telnet-based library to operate the device for accessing CLI.
    (I don't recommend it from an error handling perspective.)



    ------------------------------
    RYOTA KOSAKA
    ------------------------------



  • 3.  RE: Using PyEZ in on-box commit scripts

    Posted 28 days ago

    Sorry, I was wrong. Please ignore my previous post.
    I have only ever used jsc.emit_change(content,'change',format) in commit script.  "format" is only support XML.

    I don't know of any cases where functions other than jsc.XXX() have been used in a commit script.



    ------------------------------
    RYOTA KOSAKA
    ------------------------------



  • 4.  RE: Using PyEZ in on-box commit scripts

     
    Posted 28 days ago

    So, with a "commit script", the scenario is that the script is going to process whatever the user is attempting to commit.  Either to issue a warning, block the commit, or make some additional adjustments to the commit that has triggered the commit script. Hence you will only be using emit_change within the commit script, and as you understand, it supports XML only.

    Numerous examples of commit scripts (and other script types) can be found here:  https://github.com/Juniper/junosautomation/tree/master/on-box-python

    Else, if you are just looking to push some additional configuration to a device via an op or event-script then you can approach it with the lock/load/commit/unlock approach etc., with support for text/xml/json.

    Regards,