netbox-pyswagger

Swagger client for Netbox


Keywords
netbox, rest, json, api, network, automation
License
MIT
Install
pip install netbox-pyswagger==0.1.2

Documentation

Python Swagger Client for Netbox

If you love Netbox, you want to automate it via the REST API, and you want a client that supports an interactive enviornment like ipython and jupyter notesbooks, then this client is for you!

The gist of this client is that it consumes the Netbox Swagger 2.0 spec and uses that information to dynamically create a client with all API capabilities, model parameters as objects, and perform data validataton on all request parameters and responses. You never have to worry about the client being "out of sync" with the Netbox API. This client is specifically designed so that you can introspect, that is show in a "help" like manner, everything about each API, parameter, and data-type so that you do not need to have any API docs. You can use this client in an interactive Python shell, such as ipython and jupyter notebooks, in order to create a CLI-like user experience and not require hard-core programming to automate the Netbox system. For these purpose, this client was built with the halutz package - see these tutorials for usage.


NOTE:    If you are already using the pynetbox client you can use both together. See this example tutorial.


Installation

pip install netbox-pyswagger

Quickstart

This example shows you how to create a client, and create a VLAN.

from netbox_pyswagger.client import Client

server_url = "localhost:32768"
api_token = "0123456789abcdef0123456789abcdef01234567"

netbox = Client(server_url, api_token=api_token)

# Use the `request` attribute to access a specific API based on the Swagger tag value
# (ipam) and the Swagger operationId value (ipam_vlans_create)

new_vlan = netbox.request.ipam.ipam_vlans_create

# the command body parameter is called 'data' and here we set the required values
# if you set an invalid value, like setting `vid` to "foobaz", you will get a validation
# exception

new_vlan.data.vid = 10
new_vlan.data.name = 'Blue'

# finally execute the command, which provides us the response data and the indication
# if the command executed ok or not.  If the command had addition (non-body) parameters
# you would provide them as key-value pairs to the call.

resp, ok = new_vlan()

The variable ok is True when the command is successful, and here is the example output of the response data, resp:

{
  "status": 1, 
  "group": null, 
  "name": "Blue", 
  "vid": 10, 
  "site": null, 
  "role": null, 
  "id": 8, 
  "tenant": null, 
  "description": ""
}

Built With

Other Links

Acknowledgements

The Netbox probject is quite amazing, with a vibrant community of users and contributors! Many thanks to @jeremystretch and @digitalocean!

Questions / Contributes?

Please use the issues link to ask questions. Contributions are welcome and apprecaited.