Brocade Automation Community

Expand all | Collapse all

about py scripts

  • 1.  about py scripts

    Posted 12-05-2019 11:04 AM
        I wrote a Python script to create an alias on the switch, the script works fine and got the return values,  below is the script output: -i -L admin -P password --name=cwserver1 --members="20:22:00:02:ac:00:69:bf" -f 128 -s self
    executing __aliascreate
    "http-resp-code": 201,
    "success-code": 201,
    "success-message": "Created",
    "success-type": "Success"
    __aliascreate succeeded.

    My questions are :
    1. Is that a Jason format?
    2. How can I get the return values in my python script? I tried to use Jason.loads() in my script, but it doesn't work.

            Any suggestions would be appreciated. thanks  

    Wu Chen

  • 2.  RE: about py scripts

    Posted 12-05-2019 04:03 PM
    JSON doesn't have any format. That looks more like pprint output. json.dumps() is the correct way to convert the response to a python data structure. My first guess would be that you don't have the correct content headers. Before getting to that, you must have FOS 8.2.1 for JSON support from the API and I strongly recommend 8.2.1c or higher.

    I have a github site intended for programmers not using PyFOS to program to the API. There is a driver, look in folder brcdapi, that addresses this plus a few other typical driver layer things you need to address. There are examples on how to use the driver in the folder api_direct and some documentation specifically aimed at programmers such as yourself in folder "Documentation_and_tools".

    Rather than re-invent the wheel, I suggest just taking the driver but if you must, take the driver and read through it. There isn't much code and I tried to be a little more verbose than usual with comments

    Included in the driver:

    • Single interface to the API is standard Python data structures converted to/from JSON with all interactions with the API
    • Efficient throttling
    • Handles retries
    • Converts errors indicating a zero length array to a zero length array

    Field Applications Engineer