DellEMC

Getting started with the Brocade FOS REST API

In the next article we will explore how to use Ansible to manage Brocade switches. But today we will talk briefly about the REST API. This is important because under the covers the Brocade Ansible modules use the REST API. This helps you (as it helped me) to understand what’s happening when things don’t work with the Ansible as you expected. It will also prove handy if for example you are trying to get information from the switches in order to perform other functions.

The first thing to know about the REST API is that you the minimum version of code you need is Fabric OS 8.2.x. This of course going to restrict what Brocade switches you can manage this way. When I first started testing the REST API and Ansible I only had access to a DS300 which of course cannot run 8.x. In page 7 of this Brocade REST API Reference Guide you can see that you need Gen5 and Gen 6 fixed-port switches and directors. So please do yourself a favor and check that list first of all to make sure you don’t waste your precious time

The FOS REST API has a log in mechanism. We won’t get very far unless we log in. The overall process is as follows:

1 – POST /rest/login

  • This call uses basic authentication
  • The call returns an “Authorization” key in the response header. So programmatically you will need to extract and store that header because subsequent calls need to include the “Authorization” header as part of the request. This includes the “logout” call at the end

2 – Now you can perform calls to retrieve information or to configure the switch

  • The call “GET /rest/brocade-module-version” lists all the resources that the FOS REST API exposes which is very handy … great idea Brocade!!
  • After logging in all calls need to include the “Authorization” header as part of the request. See the screenshot below
  • All subsequent calls also need the following two headers:
    • Accept: application/yang-data+json
    • Content-Type: application/yang-data+json

3 – POST /rest/logout

  • yes, indeed, there is a logout call, and you better use it because by default the default limit for FOS REST API sessions is 3 sessions, although you can increase that limit to a maximum number of 10 API connections
  • Notice how this call is also a POST
  • This call also requires the “application/yang-data+json” headers

I have created a Postman collection with 13 sample calls (including login/logout) and uploaded it to the Project Vision Github repo

Please note it requires you to create an environment in Postman with three variables: “ip”, “pwd” and “authkey”

The “authkey” variable is automatically populated by the little code in the “Tests” tab of the “Login” call

If you are new to Postman you can go back to this article that teaches you the easy way everything you need to know to get started

And to conclude this article I will leave you with a link to a handy introductory document that discusses the various ways of automating Brocade switches: SAN Automation for Dummies

3 replies »

    • Hi James, sorry I don’t have an example with PATCH and what is worst I no longer have access to a switch to test things on. FC switches are a scarce resource in a lab environment 😦

      Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.