-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from digitalocean/5.0
5.0.0 Release
- Loading branch information
Showing
31 changed files
with
1,000 additions
and
1,000 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.