Skip to content

Commit 4c18c61

Browse files
author
Thomas
committed
Initial python-netbox commit
1 parent f94dafe commit 4c18c61

16 files changed

+1242
-0
lines changed

MANIFEST.in

Whitespace-only changes.

README.rst

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
============================
2+
Python Netbox
3+
============================
4+
5+
6+
7+
-----------------
8+
Installation
9+
-----------------
10+
11+
To get the latest version from Github:
12+
13+
$ pip install -e git+git://github.com/jagter/python-netbox.git#egg=python-netbox
14+
15+
-----------------
16+
Usage
17+
-----------------
18+
To start with the module:
19+
20+
>>> from netbox import NetBox
21+
>>> netbox = NetBox(host='127.0.0.1', port=32768, use_ssl=False, auth_token='token')
22+
23+
24+
-----------------
25+
Examples
26+
-----------------
27+
Get all devices:
28+
29+
>>> netbox.dcim.get_devices()
30+
31+
Get devices per rack:
32+
33+
>>> netbox.dcim.get_devices_per_rack('rack_name')
34+
35+
Get device by name
36+
37+
>>> netbox.dcim.get_device_by_name('device_name')
38+
39+
Get per device the primary ip and mac address:
40+
41+
>>> output = []
42+
>>> for item in a.dcim.get_devices():
43+
>>> device_name = item['name']
44+
>>>
45+
>>> if item['primary_ip'] is not None:
46+
>>> primary_ip_id = item['primary_ip']['id']
47+
>>> get_ips = a.ipam.get_ip_by_id(primary_ip_id)
48+
>>>
49+
>>> output.append({'name': device_name, 'ip': get_ips['address'], 'mac': get_ips['interface']['mac_address']})
50+
>>> else:
51+
>>> print('{} has no primary_ip'.format(item['name']))
52+
>>>
53+
>>> print(output)
54+
55+
Create a site:
56+
57+
>>> netbox.dcim.create_site('site1', 'site1')
58+
59+
Delete a site:
60+
61+
>>> netbox.dcim.delete_site('site1')
62+
63+
-----------------
64+
Support
65+
-----------------
66+
If you have questions or comments please send an email to [email protected]

docs/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = python -msphinx
7+
SPHINXPROJ = python-netbox
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/conf.py

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# python-netbox documentation build configuration file, created by
5+
# sphinx-quickstart on Thu Jun 29 14:00:10 2017.
6+
#
7+
# This file is execfile()d with the current directory set to its
8+
# containing dir.
9+
#
10+
# Note that not all possible configuration values are present in this
11+
# autogenerated file.
12+
#
13+
# All configuration values have a default; values that are commented out
14+
# serve to show the default.
15+
16+
# If extensions (or modules to document with autodoc) are in another directory,
17+
# add these directories to sys.path here. If the directory is relative to the
18+
# documentation root, use os.path.abspath to make it absolute, like shown here.
19+
#
20+
import os
21+
import sys
22+
sys.path.insert(0, os.path.abspath('../'))
23+
24+
25+
# -- General configuration ------------------------------------------------
26+
27+
# If your documentation needs a minimal Sphinx version, state it here.
28+
#
29+
# needs_sphinx = '1.0'
30+
31+
# Add any Sphinx extension module names here, as strings. They can be
32+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
33+
# ones.
34+
extensions = ['sphinx.ext.autodoc']
35+
36+
# Add any paths that contain templates here, relative to this directory.
37+
templates_path = ['_templates']
38+
39+
# The suffix(es) of source filenames.
40+
# You can specify multiple suffix as a list of string:
41+
#
42+
# source_suffix = ['.rst', '.md']
43+
source_suffix = '.rst'
44+
45+
# The master toctree document.
46+
master_doc = 'index'
47+
48+
# General information about the project.
49+
project = 'python-netbox'
50+
copyright = '2017, Thomas van der Jagt'
51+
author = 'Thomas van der Jagt'
52+
53+
# The version info for the project you're documenting, acts as replacement for
54+
# |version| and |release|, also used in various other places throughout the
55+
# built documents.
56+
#
57+
# The short X.Y version.
58+
version = '0.0.1'
59+
# The full version, including alpha/beta/rc tags.
60+
release = '0.0.1'
61+
62+
# The language for content autogenerated by Sphinx. Refer to documentation
63+
# for a list of supported languages.
64+
#
65+
# This is also used if you do content translation via gettext catalogs.
66+
# Usually you set "language" from the command line for these cases.
67+
language = None
68+
69+
# List of patterns, relative to source directory, that match files and
70+
# directories to ignore when looking for source files.
71+
# This patterns also effect to html_static_path and html_extra_path
72+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
73+
74+
# The name of the Pygments (syntax highlighting) style to use.
75+
pygments_style = 'sphinx'
76+
77+
# If true, `todo` and `todoList` produce output, else they produce nothing.
78+
todo_include_todos = False
79+
80+
81+
# -- Options for HTML output ----------------------------------------------
82+
83+
# The theme to use for HTML and HTML Help pages. See the documentation for
84+
# a list of builtin themes.
85+
#
86+
html_theme = 'sphinx_rtd_theme'
87+
88+
# Theme options are theme-specific and customize the look and feel of a theme
89+
# further. For a list of options available for each theme, see the
90+
# documentation.
91+
#
92+
# html_theme_options = {}
93+
94+
# Add any paths that contain custom static files (such as style sheets) here,
95+
# relative to this directory. They are copied after the builtin static files,
96+
# so a file named "default.css" will overwrite the builtin "default.css".
97+
html_static_path = ['_static']
98+
99+
100+
# -- Options for HTMLHelp output ------------------------------------------
101+
102+
# Output file base name for HTML help builder.
103+
htmlhelp_basename = 'python-netboxdoc'
104+
105+
106+
# -- Options for LaTeX output ---------------------------------------------
107+
108+
latex_elements = {
109+
# The paper size ('letterpaper' or 'a4paper').
110+
#
111+
# 'papersize': 'letterpaper',
112+
113+
# The font size ('10pt', '11pt' or '12pt').
114+
#
115+
# 'pointsize': '10pt',
116+
117+
# Additional stuff for the LaTeX preamble.
118+
#
119+
# 'preamble': '',
120+
121+
# Latex figure (float) alignment
122+
#
123+
# 'figure_align': 'htbp',
124+
}
125+
126+
# Grouping the document tree into LaTeX files. List of tuples
127+
# (source start file, target name, title,
128+
# author, documentclass [howto, manual, or own class]).
129+
latex_documents = [
130+
(master_doc, 'python-netbox.tex', 'python-netbox Documentation',
131+
'Thomas van der Jagt', 'manual'),
132+
]
133+
134+
135+
# -- Options for manual page output ---------------------------------------
136+
137+
# One entry per manual page. List of tuples
138+
# (source start file, name, description, authors, manual section).
139+
man_pages = [
140+
(master_doc, 'python-netbox', 'python-netbox Documentation',
141+
[author], 1)
142+
]
143+
144+
145+
# -- Options for Texinfo output -------------------------------------------
146+
147+
# Grouping the document tree into Texinfo files. List of tuples
148+
# (source start file, target name, title, author,
149+
# dir menu entry, description, category)
150+
texinfo_documents = [
151+
(master_doc, 'python-netbox', 'python-netbox Documentation',
152+
author, 'python-netbox', 'One line description of project.',
153+
'Miscellaneous'),
154+
]
155+
156+
157+

docs/examples.rst

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
##############################################
2+
Examples
3+
##############################################
4+
5+
To start with python-netbox client:
6+
7+
>>> from netbox import NetBox
8+
>>> netbox = NetBox(host='127.0.0.1', port=32768, use_ssl=False, auth_token='token')
9+
10+
Get all devices:
11+
12+
>>> netbox.dcim.get_devices()
13+
14+
Get devices per rack:
15+
16+
>>> netbox.dcim.get_devices_per_rack('rack_name')
17+
18+
Get device by name
19+
20+
>>> netbox.dcim.get_device_by_name('device_name')
21+
22+
Get per device the primary ip and mac address:
23+
24+
>>> output = []
25+
>>> for item in a.dcim.get_devices():
26+
>>> device_name = item['name']
27+
>>>
28+
>>> if item['primary_ip'] is not None:
29+
>>> primary_ip_id = item['primary_ip']['id']
30+
>>> get_ips = a.ipam.get_ip_by_id(primary_ip_id)
31+
>>>
32+
>>> output.append({'name': device_name, 'ip': get_ips['address'], 'mac': get_ips['interface']['mac_address']})
33+
>>> else:
34+
>>> print('{} has no primary_ip'.format(item['name']))
35+
>>>
36+
>>> print(output)
37+
38+
Create a site:
39+
40+
>>> netbox.dcim.create_site('site1', 'site1')
41+
42+
Delete a site:
43+
44+
>>> netbox.dcim.delete_site('site1')

docs/index.rst

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.. python-netbox documentation master file, created by
2+
sphinx-quickstart on Thu Jun 29 14:00:10 2017.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Python Netbox Client
7+
=========================================
8+
9+
python-netbox is a client for Netbox (https://github.com/digitalocean/netbox).
10+
It's based on the APIv2 which is released since version 2.0.0. For now only the get/create/delete methods
11+
are implemented. The possibility to modify items will be implementend soon.
12+
13+
Installation
14+
============
15+
16+
To get the latest version from Github::
17+
18+
pip install -e git+https://github.com/jagter/python-netbox.git#egg=python-netbox
19+
20+
Contents
21+
========
22+
23+
.. toctree::
24+
:maxdepth: 2
25+
26+
examples
27+
28+
29+
30+
Indices and tables
31+
==================
32+
33+
* :ref:`genindex`
34+
* :ref:`modindex`
35+
* :ref:`search`
36+

docs/source/modules.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
netbox
2+
======
3+
4+
.. toctree::
5+
:maxdepth: 4
6+
7+
netbox

docs/source/netbox.rst

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
netbox package
2+
==============
3+
4+
Submodules
5+
----------
6+
7+
netbox\.connection module
8+
-------------------------
9+
10+
.. automodule:: netbox.connection
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
netbox\.dcim module
16+
-------------------
17+
18+
.. automodule:: netbox.dcim
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
23+
netbox\.exceptions module
24+
-------------------------
25+
26+
.. automodule:: netbox.exceptions
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:
30+
31+
netbox\.ipam module
32+
-------------------
33+
34+
.. automodule:: netbox.ipam
35+
:members:
36+
:undoc-members:
37+
:show-inheritance:
38+
39+
netbox\.netbox module
40+
---------------------
41+
42+
.. automodule:: netbox.netbox
43+
:members:
44+
:undoc-members:
45+
:show-inheritance:
46+
47+
48+
Module contents
49+
---------------
50+
51+
.. automodule:: netbox
52+
:members:
53+
:undoc-members:
54+
:show-inheritance:

netbox/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .netbox import NetBox

0 commit comments

Comments
 (0)