Skip to content

Commit

Permalink
Develop (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthanson authored Aug 8, 2024
1 parent ef2271d commit c84ca29
Show file tree
Hide file tree
Showing 31 changed files with 89 additions and 100 deletions.
7 changes: 3 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,24 @@ body:
attributes:
label: pynetbox version
description: What version of pynetbox are you currently running?
placeholder: v7.1.0
placeholder: v7.4.0
validations:
required: true
- type: input
attributes:
label: NetBox version
description: What version of NetBox are you currently running?
placeholder: v3.6.0
placeholder: v4.0.8
validations:
required: true
- type: dropdown
attributes:
label: Python version
description: What version of Python are you currently running?
options:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
validations:
required: true
- type: textarea
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/py3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.8", "3.9", "3.10", "3.11"]
netbox: ["3.4", "3.5", "3.6", "3.7"]
python: ["3.10", "3.11", "3.12"]
netbox: ["3.6", "3.7", "4.0"]

steps:
- uses: actions/checkout@v4
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ Python API client library for [NetBox](https://github.com/netbox-community/netbo

> **Note:** Version 6.7 and later of the library only supports NetBox 3.3 and above.
## Compatibility

Each pyNetBox Version listed below has been tested with its corresponding NetBox Version.

| NetBox Version | Plugin Version |
|:--------------:|:--------------:|
| 4.0.6 | 7.4.0 |
| 4.0.0 | 7.3.4 |
| 3.7 | 7.3.0 |
| 3.6 | 7.2.0 |
| 3.5 | 7.1.0 |
| 3.3 | 7.0.0 |

## Installation

To install run `pip install pynetbox`.
Expand Down
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'pynetbox'
copyright = '2023, NetBox'
author = 'Abhimanyu Saharan'
release = 'Apache2'
project = "pynetbox"
copyright = "2023, NetBox"
author = "Abhimanyu Saharan"
release = "Apache2"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
6 changes: 2 additions & 4 deletions pynetbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from importlib.metadata import version

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

__version__ = version(__name__)
__version__ = "7.4.0"
2 changes: 1 addition & 1 deletion pynetbox/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import requests

from pynetbox.core.query import Request
from pynetbox.core.app import App, PluginsApp
from pynetbox.core.query import Request
from pynetbox.core.response import Record


Expand Down
6 changes: 3 additions & 3 deletions pynetbox/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
from pynetbox.core.endpoint import Endpoint
from pynetbox.core.query import Request
from pynetbox.models import (
dcim,
ipam,
virtualization,
circuits,
dcim,
extras,
ipam,
users,
virtualization,
wireless,
)

Expand Down
3 changes: 2 additions & 1 deletion pynetbox/core/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ def filter(self, *args, **kwargs):
offset = kwargs.pop("offset") if "offset" in kwargs else None
if limit == 0 and offset is not None:
raise ValueError("offset requires a positive limit value")
filters = {x: y if y is not None else "null" for x, y in kwargs.items()}
req = Request(
filters=kwargs,
filters=filters,
base=self.url,
token=self.token,
http_session=self.api.http_session,
Expand Down
1 change: 1 addition & 0 deletions pynetbox/core/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import concurrent.futures as cf
import json

from packaging import version


Expand Down
5 changes: 2 additions & 3 deletions pynetbox/core/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

import copy
from collections import OrderedDict
from urllib.parse import urlsplit

import pynetbox.core.app
from urllib.parse import urlsplit
from pynetbox.core.query import Request
from pynetbox.core.util import Hashabledict


# List of fields that are lists but should be treated as sets.
LIST_AS_SET = ("tags", "tagged_vlans")

Expand Down Expand Up @@ -68,7 +67,7 @@ def flatten_custom(custom_dict):
current_val = val.get("id", val)

if isinstance(val, list):
current_val = [v.get("id") if isinstance(v, dict) else v for v in val]
current_val = [v.get("id", v) if isinstance(v, dict) else v for v in val]

ret[k] = current_val
return ret
Expand Down
11 changes: 3 additions & 8 deletions pynetbox/models/dcim.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

from urllib.parse import urlsplit

from pynetbox.core.endpoint import DetailEndpoint, RODetailEndpoint
from pynetbox.core.query import Request
from pynetbox.core.response import Record, JsonField
from pynetbox.core.endpoint import RODetailEndpoint, DetailEndpoint
from pynetbox.models.ipam import IpAddresses
from pynetbox.core.response import JsonField, Record
from pynetbox.models.circuits import Circuits
from pynetbox.models.ipam import IpAddresses


class TraceableRecord(Record):
Expand Down Expand Up @@ -150,13 +150,8 @@ def __str__(self):
return self.interface.name


class ConnectedEndpoint(Record):
device = Devices


class Interfaces(TraceableRecord):
interface_connection = InterfaceConnection
connected_endpoint = ConnectedEndpoint


class PowerOutlets(TraceableRecord):
Expand Down
2 changes: 1 addition & 1 deletion pynetbox/models/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
"""

from pynetbox.core.response import Record, JsonField
from pynetbox.core.response import JsonField, Record


class ConfigContexts(Record):
Expand Down
2 changes: 1 addition & 1 deletion pynetbox/models/ipam.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
limitations under the License.
"""

from pynetbox.core.response import Record
from pynetbox.core.endpoint import DetailEndpoint
from pynetbox.core.response import Record


class IpAddresses(Record):
Expand Down
23 changes: 8 additions & 15 deletions pynetbox/models/mapper.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
from .circuits import Circuits, CircuitTerminations
from .dcim import (
DeviceTypes,
Cables,
ConsolePorts,
ConsoleServerPorts,
Devices,
DeviceTypes,
FrontPorts,
Interfaces,
PowerOutlets,
PowerPorts,
ConsolePorts,
ConsoleServerPorts,
RackReservations,
VirtualChassis,
FrontPorts,
RearPorts,
Racks,
RearPorts,
Termination,
Cables,
)
from .ipam import (
IpAddresses,
Prefixes,
Aggregates,
Vlans,
VlanGroups,
VirtualChassis,
)
from .ipam import Aggregates, IpAddresses, Prefixes, VlanGroups, Vlans
from .virtualization import VirtualMachines
from .wireless import WirelessLans


CONTENT_TYPE_MAPPER = {
"circuits.circuit": Circuits,
"circuits.circuittermination": CircuitTerminations,
Expand Down
2 changes: 1 addition & 1 deletion pynetbox/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
"""

from pynetbox.core.response import Record, JsonField
from pynetbox.core.response import JsonField, Record


class Users(Record):
Expand Down
2 changes: 1 addition & 1 deletion pynetbox/models/virtualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
"""

from pynetbox.core.response import Record, JsonField
from pynetbox.core.response import JsonField, Record
from pynetbox.models.ipam import IpAddresses


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
requests>=2.20.0,<3.0
packaging
packaging
18 changes: 7 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
from setuptools import setup, find_packages
from setuptools import find_packages, setup

setup(
name="pynetbox",
description="NetBox API client library",
url="https://github.com/netbox-community/pynetbox",
author="Zach Moody",
author_email="[email protected]",
author="Zach Moody, Arthur Hanson",
author_email="[email protected]",
license="Apache2",
include_package_data=True,
use_scm_version=True,
setup_requires=["setuptools_scm"],
packages=find_packages(exclude=["tests", "tests.*"]),
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
install_requires=[
"requests>=2.20.0,<3.0",
"packaging"
],
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
install_requires=["requests>=2.20.0,<3.0", "packaging"],
zip_safe=False,
keywords=["netbox"],
classifiers=[
"Intended Audience :: Developers",
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
)
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import pytest
from packaging import version


DEFAULT_NETBOX_VERSIONS = "3.7"
DEFAULT_NETBOX_VERSIONS = "4.0"


def pytest_addoption(parser):
Expand Down
22 changes: 8 additions & 14 deletions tests/fixtures/dcim/interface.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,16 @@
"mgmt_only": false,
"description": "",
"is_connected": true,
"connected_endpoint": {
"id": 1,
"url": "http://localhost:8000/api/dcim/interfaces/1/",
"device": {
"connected_endpoints": [
{
"id": 1,
"url": "http://localhost:8000/api/dcim/devices/1/",
"name": "tst-endpoint",
"display_name": "tst-endpoint"
},
"name": "eth0",
"cable": 1
},
"connection_status": {
"value": true,
"label": "Connected"
},
"display": "tst-endpoint",
"name": "tst-endpoint"
}
],
"connected_endpoints_type": "dcim.device",
"connected_endpoints_reachable": true,
"cable": {
"id": 1,
"url": "http://localhost:8000/api/dcim/cables/1/",
Expand Down
19 changes: 7 additions & 12 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import atexit
import os

import subprocess as subp
import time
import yaml
from http.client import RemoteDisconnected

import atexit
import pynetbox
import pytest
import requests
import yaml

import pynetbox

DOCKER_PROJECT_PREFIX = "pytest_pynetbox"

Expand All @@ -27,16 +26,12 @@ def get_netbox_docker_version_tag(netbox_version):
"""
major, minor = netbox_version.major, netbox_version.minor

if (major, minor) == (3, 3):
tag = "2.3.0"
elif (major, minor) == (3, 4):
tag = "2.5.3"
elif (major, minor) == (3, 5):
tag = "2.6.1"
elif (major, minor) == (3, 6):
if (major, minor) == (3, 6):
tag = "2.7.0"
elif (major, minor) == (3, 7):
tag = "2.8.0"
elif (major, minor) == (4, 0):
tag = "2.9.1"
else:
raise NotImplementedError(
"Version %s is not currently supported" % netbox_version
Expand Down Expand Up @@ -235,7 +230,7 @@ def docker_compose_file(pytestconfig, netbox_docker_repo_dirpaths):
)
compose_data["networks"] = {docker_network_name: {}}
# https://docs.docker.com/compose/compose-file/compose-file-v3/#network-configuration-reference
if compose_data["version"] >= "3.5":
if "version" not in compose_data or compose_data["version"] >= "3.5":
compose_data["networks"][docker_network_name][
"name"
] = docker_network_name
Expand Down
Loading

0 comments on commit c84ca29

Please sign in to comment.