diff --git a/changelogs/fragments/fix_issue_1300.yml b/changelogs/fragments/fix_issue_1300.yml new file mode 100644 index 00000000..79ceded9 --- /dev/null +++ b/changelogs/fragments/fix_issue_1300.yml @@ -0,0 +1,2 @@ +minor_changes: + - Allows templating of api_endpoint in nb_inventory plugin diff --git a/plugins/inventory/nb_inventory.py b/plugins/inventory/nb_inventory.py index 03444b6b..5d990628 100644 --- a/plugins/inventory/nb_inventory.py +++ b/plugins/inventory/nb_inventory.py @@ -1594,7 +1594,9 @@ def fetch_api_docs(self): except Exception: cached_api_version = None cache = None - + self.api_endpoint = self.templar.template( + self.get_option("api_endpoint"), fail_on_undefined=False + ) status = self._fetch_information(self.api_endpoint + "/api/status") netbox_api_version = ".".join(status["netbox-version"].split(".")[:2]) diff --git a/tests/unit/inventory/test_nb_inventory.py b/tests/unit/inventory/test_nb_inventory.py index 93a59217..5114cf30 100644 --- a/tests/unit/inventory/test_nb_inventory.py +++ b/tests/unit/inventory/test_nb_inventory.py @@ -222,7 +222,7 @@ def test_get_resource_list_chunked( "/fake/path/asdasd3456", ) @pytest.mark.parametrize("netbox_ver", ["2.0.2", "3.0.0"]) -def test_fetch_api_docs(inventory_fixture, netbox_ver): +def test_fetch_api_docs(inventory_fixture, netbox_ver, templar_fixture): mock_fetch_information = Mock() mock_fetch_information.side_effect = [ {"netbox-version": netbox_ver},