Brocade Logo

Brocade BNA API

Brocade Network Advisor (BNA) has a REST API for accessing Fibre Channel-related data. The documentation includes a sample Python script showing how to connect to the API to retrieve Fabric info. The script given only works with Python 3.x. It’s also a pain to copy out of the documentation as you end up with a few extra characters in there. Here’s a version that will work with Python 2.7. I’ve also made a few other modifications – in this one, you can set the BNA IP, Username & Password at the top of the script.  I’ve also made it PEP8-compliant.

Save that, edit the server IP & username/password, then run it. You should get output that looks something like this:

Hope this helps someone trying to get started with the API.

,

12 Responses to Brocade BNA API

  1. Andrew March 18, 2016 at 1:25 am #

    Hi
    Do you have a POST action as well of a ZoneObjectCreation?
    Thanks,

    • Lindsay Hill March 18, 2016 at 1:11 pm #

      Do you need an example of the payload for a CreateZoningObjectRequest?

      • Andrew March 18, 2016 at 8:52 pm #

        I’m trying to build some powershell functions.
        It’s no problem To GET information from the Brocade SAN Network Advisor. (version 12.3.4 running on Windows 2008R2)

        But I’m not able to create a new ZoneAlias or Zone within the Fabric.

        A JSON body which I used:

        $ZoneObjectBody = ‘{
        “zoneAliases”: [
        {
        “name”: “HOST_1”,
        “memberNames”: [“50:01:43:80:36:84:B2:C0”]
        }
        ]

        }’

        URI which I used to POST: “/resourcegroups/All/fcfabrics/$FabricKey/createzoningobject”

        Stil receiving error:

        Invoke-WebRequest : JBWEB000065: HTTP Status 400 – org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token at [Source:
        [email protected]; line: 4, column: 46] (through reference chain:
        com.brocade.dcm.webservices.common.v1.zoneservice.request.CreateZoningObjectRequest[“zoneAliases”]->com.brocade.dcm.webservices.common.v1.model.zone.ZoneAlias[“memberNames”])
        JBWEB000309: type JBWEB000067: Status report
        JBWEB000068: message org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token at [Source: [email protected]; line: 4, column: 46]
        (through reference chain: com.brocade.dcm.webservices.common.v1.zoneservice.request.CreateZoningObjectRequest[“zoneAliases”]->com.brocade.dcm.webservices.common.v1.model.zone.ZoneAlias[“memberNames”])
        JBWEB000069: description JBWEB000120: The request sent by the client was syntactically incorrect.
        JBoss Web/7.2.0.Final
        At line:156 char:17
        + … $data = Invoke-WebRequest -Uri “$url” -Body $json -Headers $heade …
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

        ZONE create JSON body which I used:
        $ZoneObjectBody = ‘
        {
        “zones”: [
        {
        “name”:”HOSTZONE_1″,
        “type”:”STANDARD”,
        “aliasNames”:[“HOST_1”],
        “memberNames”:[]
        }
        ]
        }’

        Used documentation: http://www1.brocade.com/downloads/documents/html_product_manuals/NA_1230_RESTAPI/wwhelp/wwhimpl/js/html/wwhelp.htm

        • Lindsay Hill March 18, 2016 at 8:58 pm #

          I’ll have a look through some sample scripts I’ve got, and post something here. I’ve got some Python stuff, but should be easy to translate to Powershell

          • Lindsay Hill March 22, 2016 at 12:38 pm #

            Looking through a script I’ve got kicking around, the request body for ../createzoningobject looks like this:
            data={
            "zones": [
            {
            "name": "host1_hba0_array_sp0",
            "aliasNames": [
            "host_hba0",
            "array_sp0"
            ],
            "type": "STANDARD"
            }
            ],
            "zoneAliases": [
            {
            "name": "host_hba0",
            "memberNames": [
            "11:22:33:44:55:66:77:88"
            ]
            },
            {
            "name": "array_sp0",
            "memberNames": [
            "88:77:66:55:44:33:22:11"
            ]
            }
            ]
            }

            (Hopefully that doesn’t get too mangled)

          • Andrew March 22, 2016 at 9:45 pm #

            To bad. Still same error. I can not find anything different in the JSON body.

          • Lindsay Hill March 23, 2016 at 9:17 am #

            I’ll send you an email with a more complete Python script I’ve got.

          • Andrew March 23, 2016 at 11:09 am #

            Great! That would be nice. Maybe it will give me some answers.

  2. Andrew March 24, 2016 at 3:52 am #

    I’ve got it working.

    The original JSON body was okay. But the function to invoke the body needed a PSobject, so I had to convert the PSobject to JSON. The JSON body didn’t look the same as created after convert.

    I had to define the depth value when converting a PSObject to JSON. When running CONVERTTO-JSON -depth 3 the JSON body shows correct.

    Example:
    after incorrect convert. (missing brackets):
    {
    “zoneAliases”: [
    {
    “memberNames”: “11:22:33:44:55:66:77:88”,
    “name”: “HOST_A”
    }
    ]
    }

    Correct convert with correct powershell depth value:
    {
    “zoneAliases”: [
    {
    “memberNames”: [
    “11:22:33:44:55:66:77:88”
    ],
    “name”: “HOST_A”
    }
    ]
    }

    Thanks!

    • Lindsay Hill March 24, 2016 at 10:04 am #

      Great! Thanks for posting feedback here, I’m sure it will help someone else trying to do the same thing

      • sandeep July 29, 2016 at 12:51 am #

        would you please send me script which uses POST for zoning and zoneAlias creation. thanks in advance.

  3. Obi May 21, 2016 at 3:00 am #

    Hi,

    I get the following while create a zone via REST.

    JBoss Web/7.2.0.Final – JBWEB000064: Error report JBWEB000065: HTTP Status 415 – Cannot consume content typeJBWEB000309: type JBWEB000067: Status reportJBWEB000068: message Cannot consume content typeJBWEB000069: description JBWEB000135: The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.JBoss Web/7.2.0.Final

    Headers used:

    ‘Accept’: ‘application/vnd.brocade.networkadvisor+json;version=v1’}

Leave a Reply