Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.0.0 Release #256

Merged
merged 35 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a525424
Test for `vlan` in `interface.tagged_vlan`
Jun 12, 2020
9e65a07
Pycodestyle Fix
jsenecal Jun 17, 2020
944fc03
Recreate `self.endpoint` from url when present
jsenecal Jun 17, 2020
96f930b
Support URL parameters
jsenecal Jun 17, 2020
da90ed7
Move Apps to its own file
Jun 23, 2020
9ec1f25
add endpoint_from_url method
Jun 23, 2020
db5ebea
Merge branch 'fix-endpoint-hash' into hash_fix
Jun 23, 2020
9524c33
Merge pull request #243 from jsenecal/hash_fix
Jun 23, 2020
b76ffac
Make linter happy
Jun 23, 2020
5d6f2f2
Make Response endpoint kwarg optional
Jun 23, 2020
4136959
Use self.endpoint in all cases
Jun 23, 2020
2b94cd8
clean endpoint_from_url test
Jun 23, 2020
cb61f9e
Make _endpoint_from_url take url as arg.
Jun 24, 2020
5268619
Re-re-implement self.endpoint
Jun 24, 2020
33dccaa
Merge pull request #248 from digitalocean/fix-endpoint-hash
Jun 24, 2020
423cd48
Add way to get openapi spec
Jun 24, 2020
4a06c07
Remove unused kwarg
Jun 24, 2020
ff84493
linter
Jun 24, 2020
ed9b153
linter
Jun 24, 2020
c35aaf4
Merge pull request #249 from digitalocean/add-openapi-query
Jun 24, 2020
699021d
Move population of api.session_key to App
Jun 24, 2020
3887d97
Merge pull request #250 from digitalocean/move-get-session-key
Jun 24, 2020
8c45a89
Fixes #224 - Catch RequestError in .get()
Jun 24, 2020
0fc7373
Merge pull request #251 from digitalocean/get-raise-error
Jun 24, 2020
190f87a
Remove ssl_verify init kwarg
Jun 24, 2020
ce74ebb
Merge pull request #252 from digitalocean/remove-ssl-verify
Jun 24, 2020
af565d5
Return objects from DetailEndpoint.create()
Jun 25, 2020
ebafdc7
Use response_loader in Endpoint and DetailEndpoint
Jun 25, 2020
cc4d6d7
linter
Jun 25, 2020
1d53796
Merge pull request #253 from digitalocean/record-return-custom
Jun 25, 2020
dcd988d
Use Black and Pytest in GH Actions
Jun 25, 2020
21b40ff
Merge pull request #254 from digitalocean/black
Jun 25, 2020
2839e6d
Move api into core
Jun 25, 2020
5f8c0f2
Update docs
Jun 25, 2020
522a3b8
Merge pull request #255 from digitalocean/docs
Jun 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/py2pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: PR Test

on: [pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python: [2.7]

steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

- name: Install pynetbox and testing packages.
run: pip install . mock

- name: Run Tests
run: python -m unittest discover

10 changes: 4 additions & 6 deletions .github/workflows/pr.yml → .github/workflows/py3pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [2.7, 3.6]
python: [3.6, 3.8]

steps:
- uses: actions/checkout@v2
Expand All @@ -19,13 +19,11 @@ jobs:
python-version: ${{ matrix.python }}

- name: Install pynetbox and testing packages.
run: pip install . pycodestyle mock
run: pip install . black pytest

- name: Run Linter
run: |
pycodestyle pynetbox
pycodestyle --ignore=E501 tests
run: black --check .

- name: Run Tests
run: python -m unittest discover
run: pytest

75 changes: 75 additions & 0 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Custom Sessions
===============

Custom sessions can be used to modify the default HTTP behavior. Below are a few examples, most of them from `here <https://hodovi.ch/blog/advanced-usage-python-requests-timeouts-retries-hooks/>`_.

Headers
*******

To set a custom header on all requests. These headers are automatically merged with headers pynetbox sets itself.

:Example:

>>> import pynetbox
>>> import requests
>>> session = requests.Session()
>>> session.headers = {"mycustomheader": "test"}
>>> nb = pynetbox.api(
... 'http://localhost:8000',
... private_key_file='/path/to/private-key.pem',
... token='d6f4e314a5b5fefd164995169f28ae32d987704f'
... )
>>> nb.http_session = session


SSL Verification
****************

To disable SSL verification. See `the docs <https://requests.readthedocs.io/en/stable/user/advanced/#ssl-cert-verification>`_.

:Example:

>>> import pynetbox
>>> import requests
>>> session = requests.Session()
>>> session.verify = False
>>> nb = pynetbox.api(
... 'http://localhost:8000',
... private_key_file='/path/to/private-key.pem',
... token='d6f4e314a5b5fefd164995169f28ae32d987704f'
... )
>>> nb.http_session = session


Timeouts
********

Setting timeouts requires the use of Adapters.

:Example:

.. code-block:: python

from requests.adapters import HTTPAdapter

class TimeoutHTTPAdapter(HTTPAdapter):
def __init__(self, *args, **kwargs):
self.timeout = kwargs.get("timeout", 5)
super().__init__(*args, **kwargs)

def send(self, request, **kwargs):
kwargs['timeout'] = self.timeout
return super().send(request, **kwargs)

adapter = TimeoutHTTPAdapter()
session = requests.Session()
session.mount("http://", adapter)
session.mount("https://", adapter)

nb = pynetbox.api(
'http://localhost:8000',
private_key_file='/path/to/private-key.pem',
token='d6f4e314a5b5fefd164995169f28ae32d987704f'
)
nb.http_session = session

58 changes: 27 additions & 31 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import os
import sys
from pkg_resources import get_distribution
sys.path.insert(0, os.path.abspath('../'))

sys.path.insert(0, os.path.abspath("../"))


# -- General configuration ------------------------------------------------
Expand All @@ -31,33 +32,33 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc']
extensions = ["sphinx.ext.autodoc"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = u'pynetbox'
copyright = u'2017, DigitalOcean'
author = u'Zach Moody'
project = u"pynetbox"
copyright = u"2017, DigitalOcean"
author = u"Zach Moody"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
# The full version, including alpha/beta/rc tags.
release = get_distribution('pynetbox').version
release = get_distribution("pynetbox").version
#
# The short X.Y version.
version = '.'.join(release.split('.')[:2])
version = ".".join(release.split(".")[:2])

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -69,10 +70,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -96,18 +97,14 @@
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']

html_sidebars = {'**': [
'globaltoc.html',
'relations.html',
'sourcelink.html',
'searchbox.html'
]
html_sidebars = {
"**": ["globaltoc.html", "relations.html", "sourcelink.html", "searchbox.html"]
}

# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'pynetboxdoc'
htmlhelp_basename = "pynetboxdoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -116,15 +113,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -134,19 +128,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'pynetbox.tex', u'pynetbox Documentation',
u'Zach Moody', 'manual'),
(master_doc, "pynetbox.tex", u"pynetbox Documentation", u"Zach Moody", "manual"),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'pynetbox', u'pynetbox Documentation',
[author], 1)
]
man_pages = [(master_doc, "pynetbox", u"pynetbox Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -155,7 +145,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'pynetbox', u'pynetbox Documentation',
author, 'pynetbox', 'A python library for NetBox.',
'Miscellaneous'),
(
master_doc,
"pynetbox",
u"pynetbox Documentation",
author,
"pynetbox",
"A python library for NetBox.",
"Miscellaneous",
),
]
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Instantiate the :py:class:`.Api`. Use the methods available on :py:class:`.Endpo
API
===

.. autoclass:: pynetbox.api.Api
.. autoclass:: pynetbox.core.api.Api
:members:

App
===

.. autoclass:: pynetbox.api.App
.. autoclass:: pynetbox.core.app.App
:members:

Indices and tables
Expand Down
2 changes: 1 addition & 1 deletion pynetbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pkg_resources import get_distribution, DistributionNotFound

from pynetbox.core.query import RequestError, AllocationError, ContentError
from pynetbox.api import Api as api
from pynetbox.core.api import Api as api

try:
__version__ = get_distribution(__name__).version
Expand Down
Loading