Books and laptop


Copy/Paste

While my first contact with Extreme Management Center’s Northbound Interface was driven by a concrete business need, I have stuck to that topic out of curiosity and laziness. Why bother with a sometimes sluggish web interface when a lightning fast API is available?

Working with Extreme Management Center’s API

Based on this need and interest, three different open source applications emerged:

  • DeviceLister: That one simply fetches a list of all devices managed with XMC and prints it to stdout in a defined format.
  • GenericNbiClient: As the name suggests this is the one to use when you need to send custom queries to XMC.
  • VlanLister: Lists all VLANs configured on all devices managed by XMC along with port associations; returned in CSV format, ready for Excel.

Looking at the code of these different applications, one thing was very obvious: Large parts of code were copied over from one client to another, especially the code that handled API communication with XMC. Knowing that Go supports modules to make code reusable I finally decided to transfer that redundant code to a module.


Introducing xmcnbiclient

The result of my efforts is a Go module called xmcnbiclient, which encapsulates all that is necessary to use XMC’s Northbound Interface API.

GitLab: Go module xmcnbiclient

Its features include:

  • Connection: HTTPS or HTTP. With certificate validation or not. Using any valid port.
  • Authentication: HTTP Basic Auth or OAuth. With automatic token refresh for OAuth.
  • Interaction: Send a query to XMC and receive the result as an easily parseable byte slice.

In the backend, efforts have been made to catch and handle any error condition that might arise. Module tests have also been written.


Using xmcnbiclient

xmcnbiclient has been designed to be easily usable. You create a new client with the New() function, set other parameters with provided functions and use QueryAPI() to send queries to XMC and receive the results. The most simple Go program that utilizes xmcnbiclient looks as follows:

package main

import (
    "fmt"
    "os"

    xmcnbiclient "gitlab.com/rbrt-weiler/go-module-xmcnbiclient"
)

func main() {
    client := xmcnbiclient.New("localhost")
    client.UseBasicAuth("user", "pass")
    res, err := client.QueryAPI("query { network { devices { up ip sysName nickName } } }")
    if err != nil {
        fmt.Printf("Oops: %s", err)
        os.Exit(255)
    }
    fmt.Println(string(res))
    os.Exit(0)
}

Note that this will not work with a fresh XMC installation, as xmcnbiclient enables certificate checking by default and refuses to connect to a host that provides an invalid certificate. UseInsecureHTTPS() will solve that problem.

But what to do when your XMC installation is, for example, hidden behind a Web Application Firewall, using HTTP instead of HTTPS, a custom port and OAuth instead of Basic Auth? Just adjust your parameters:

package main

import (
    "fmt"
    "os"

    xmcnbiclient "gitlab.com/rbrt-weiler/go-module-xmcnbiclient"
)

func main() {
    client := xmcnbiclient.New("xmc.waf.example.com")
    client.UseHTTP()
    portErr := client.SetPort(10443)
    if portErr != nil {
        fmt.Printf("Oops: %s", portErr)
        os.Exit(255)
    }
    client.UseOAuth("id", "secret")
    res, resErr := client.QueryAPI("query { network { devices { up ip sysName nickName } } }")
    if resErr != nil {
        fmt.Printf("Oops: %s", resErr)
        os.Exit(255)
    }
    fmt.Println(string(res))
    os.Exit(0)
}

As you can see, all relevant parameters are set on the client object alone, thus making it very easy to react to different situations. The complete API documentation for xmcnbiclient is contained in the module and available on godoc.org in a nice, human-readable format.


Status and Outlook

While the module has not yet reached v1.0.0, I sense that it is feature-complete by now. Only extended test routines are missing.

From a user perspective the module is definitively production-ready: All applications mentioned in the intro  -  DeviceLister, GenericNbiClient and VlanLister  -  have already been converted to use the module.

Everyone can code

With the GraphQL-based API of Extreme Networks’ Management Center still being in development, there may be changes to the module in the future. I expect them to be minor though, as the endpoints and principles used to interact with XMC’s NBI are  -  to my knowledge   - not about to change any time soon.


Feedback

The main repository for the module is located on GitLab. In case something is missing or erroneous, file an issue or fork the repository and send a merge request.

For other feedback, feel free to reach out to me via LinkedIn or Xing. I am especially interested in people (or companies) using xmcnbiclient and their use cases  -  and, of course, use cases for which xmcnbiclient is not sufficient.

This article was originally published on Medium.