Skip to content

Commit

Permalink
Fix inventory.py to work with nautobot 1.3.1 (#135)
Browse files Browse the repository at this point in the history
* Update inventory.py

* Update inventory.py

* Fix linting issue

* Fix virtual machines URL. Updated CI for better Nautobot version test matrix.

Co-authored-by: Mikhail Yohman <mikhail.yohman@gmail.com>
  • Loading branch information
gneville-ot and FragmentedPacket authored Apr 21, 2022
1 parent d39a029 commit 6602e1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ jobs:
# ansible-release: ["base", "core"]
include:
- python-version: "3.7"
nautobot-version: "1.0.3"
nautobot-version: "1.1.6"
ansible-release: "base" # Ansible 2.10
- python-version: "3.8"
nautobot-version: "1.1.1"
nautobot-version: "1.2"
ansible-release: "2.11"
- python-version: "3.8"
nautobot-version: "1.1.1"
nautobot-version: "1.2"
ansible-release: "2.9"
- python-version: "3.8"
nautobot-version: "1.1.3"
nautobot-version: "1.3"
ansible-release: "2.10"
- python-version: "3.8"
nautobot-version: "1.1.3"
nautobot-version: "1.3"
ansible-release: "2.12"
env:
INVOKE_NAUTOBOT_ANSIBLE_PYTHON_VER: "${{ matrix.python-version }}"
Expand Down
10 changes: 8 additions & 2 deletions plugins/inventory/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,14 @@ def fetch_api_docs(self):
openapi = self._fetch_information(self.api_endpoint + "/api/docs/?format=openapi")

self.api_version = openapi["info"]["version"]
self.allowed_device_query_parameters = [p["name"] for p in openapi["paths"]["/dcim/devices/"]["get"]["parameters"]]
self.allowed_vm_query_parameters = [p["name"] for p in openapi["paths"]["/virtualization/virtual-machines/"]["get"]["parameters"]]

device_path = "/api/dcim/devices/" if "/api/dcim/devices/" in openapi["paths"] else "/dcim/devices/"
vm_path = (
"/api/virtualization/virtual-machines/" if "/api/virtualization/virtual-machines/" in openapi["paths"] else "/virtualization/virtual-machines/"
)

self.allowed_device_query_parameters = [p["name"] for p in openapi["paths"][device_path]["get"]["parameters"]]
self.allowed_vm_query_parameters = [p["name"] for p in openapi["paths"][vm_path]["get"]["parameters"]]

def validate_query_parameter(self, parameter, allowed_query_parameters):
if not (isinstance(parameter, dict) and len(parameter) == 1):
Expand Down

0 comments on commit 6602e1b

Please sign in to comment.