PyNSoT - The Network Source of Truth Client¶
PyNSoT is the official client library and command-line utility for the Network Source of Truth (NSoT) network source-of-truth and IPAM database. For more information on the core project, please follow the link above.
Table of Contents:
Installation¶
Assuming you’ve got Python 2.7 and pip
, all you have to do is:
$ pip install pynsot
We realize that this might not work for you. More detailed install instructions are Coming Soon™.
Quick Start¶
How do you use it? Here are some basic examples to get you started.
Important
These examples assume you’ve already installed and configured pynsot
.
For a detailed walkthrough, please visit Configuration and then head over
to the Command-Line docs.
Create a Site¶
Sites are namespaces for all other objects. Before you can do anything you’ll need a Site:
$ nsot sites add --name 'My Site'
These examples also assume the use of a default_site
so that you don’t have
to provide the -s/--site-id
argument on every query. If this is your only
site, just add default_site = 1
to your pynsotrc
file.
If you’re throughoughly lost already, check out the Example Configuration.
CLI Example¶
Here’s an example of a few basic CLI lookups after adding several networks:
# Add a handful of networks
$ nsot networks add -c 192.168.0.0/16 -a owner=jathan
$ nsot networks add -c 192.168.0.0/24
$ nsot networks add -c 192.168.0.0/25
$ nsot networks add -c 192.168.0.1/32
$ nsot networks add -c 172.16.0.0/12
$ nsot networks add -c 10.0.0.0/24
$ nsot networks add -c 10.1.0.0/24
# And start looking them up!
$ nsot networks list
+-------------------------------------------------------------------------+
| ID Network Prefix Is IP? IP Ver. Parent ID Attributes |
+-------------------------------------------------------------------------+
| 1 192.168.0.0 16 False 4 None owner=jathan |
| 2 10.0.0.0 16 False 4 None owner=jathan |
| 3 172.16.0.0 12 False 4 None |
| 4 10.0.0.0 24 False 4 2 |
| 5 10.1.0.0 24 False 4 2 |
+-------------------------------------------------------------------------+
$ nsot networks list --include-ips
+-------------------------------------------------------------------------+
| ID Network Prefix Is IP? IP Ver. Parent ID Attributes |
+-------------------------------------------------------------------------+
| 1 192.168.0.0 16 False 4 None owner=jathan |
| 2 10.0.0.0 16 False 4 None owner=jathan |
| 3 172.16.0.0 12 False 4 None |
| 4 10.0.0.0 24 False 4 2 |
| 5 10.1.0.0 24 False 4 2 |
| 6 192.168.0.1 32 True 4 1 |
+-------------------------------------------------------------------------+
$ nsot networks list --include-ips --no-include-networks
+-----------------------------------------------------------------------+
| ID Network Prefix Is IP? IP Ver. Parent ID Attributes |
+-----------------------------------------------------------------------+
| 6 192.168.0.1 32 True 4 1 |
+-----------------------------------------------------------------------+
$ nsot networks list --cidr 192.168.0.0/16 subnets
+-----------------------------------------------------------------------+
| ID Network Prefix Is IP? IP Ver. Parent ID Attributes |
+-----------------------------------------------------------------------+
| 6 192.168.0.0 24 False 4 1 |
| 7 192.168.0.0 25 False 4 6 |
+-----------------------------------------------------------------------+
$ nsot networks list -c 192.168.0.0/24 supernets
+-------------------------------------------------------------------------+
| ID Network Prefix Is IP? IP Ver. Parent ID Attributes |
+-------------------------------------------------------------------------+
| 1 192.168.0.0 16 False 4 None owner=jathan |
| cluster= |
| foo=baz |
+-------------------------------------------------------------------------+
API Example¶
And for the Python API? Run some Python!
If you want a more detailed walkthrough, check out the Python API guide.
from pynsot.client import get_api_client
# get_api_client() is a magical function that returns the proper client
# according to your ``pynsotrc`` configuration
c = get_api_client()
nets = c.sites(1).networks.get()
subnets = c.sites(1).networks('192.168.0.0/16').subnets.get()
supernets = c.sites(1).networks('192.168.0.0/24').supernets.get()
API Reference¶
If you are looking for information on a specific function, class, or method, go forward.