nbforager 0.8.1__tar.gz → 0.8.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nbforager-0.8.1 → nbforager-0.8.2}/PKG-INFO +2 -2
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/base_c.py +43 -48
- {nbforager-0.8.1 → nbforager-0.8.2}/pyproject.toml +2 -2
- {nbforager-0.8.1 → nbforager-0.8.2}/LICENSE.txt +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/README.rst +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/__init__.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/__init__.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/base_ac.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/circuits.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/connector.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/core.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/dcim.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/extended_get.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/extras.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/ip_addresses.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/ipam.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/plugins_ca.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/status.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/tenancy.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/users.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/virtualization.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/api/wireless.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/constants.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/exceptions.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/__init__.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/base_fa.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/circuits.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/core.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/dcim.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/extras.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/forager.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/ipam.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/ipv4.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/joiner.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/tenancy.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/users.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/virtualization.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/foragers/wireless.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/helpers.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/log.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/messages.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/nb_api.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/nb_cache.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/nb_forager.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/nb_tree.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/parser/__init__.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/parser/nb_custom.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/parser/nb_parser.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/parser/nb_value.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/py.typed +0 -0
- {nbforager-0.8.1 → nbforager-0.8.2}/nbforager/types_.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: nbforager
|
3
|
-
Version: 0.8.
|
3
|
+
Version: 0.8.2
|
4
4
|
Summary: Python package designed to assist in working with the Netbox REST API. The filter parameters are identical to those in the Web UI filter form. It replaces brief data with full information, and Netbox objects are represented as a recursive multidimensional dictionary.
|
5
5
|
License: Apache-2.0
|
6
6
|
Keywords: netbox
|
@@ -23,7 +23,7 @@ Requires-Dist: requests (>=2,<3)
|
|
23
23
|
Requires-Dist: tabulate (>=0.9,<0.10)
|
24
24
|
Requires-Dist: vhelpers (>=0.3)
|
25
25
|
Project-URL: Bug Tracker, https://github.com/vladimirs-git/nbforager/issues
|
26
|
-
Project-URL: Download URL, https://github.com/vladimirs-git/nbforager/archive/refs/tags/0.8.
|
26
|
+
Project-URL: Download URL, https://github.com/vladimirs-git/nbforager/archive/refs/tags/0.8.2.tar.gz
|
27
27
|
Project-URL: homepage, https://github.com/vladimirs-git/nbforager
|
28
28
|
Project-URL: repository, https://github.com/vladimirs-git/nbforager
|
29
29
|
Description-Content-Type: text/x-rst
|
@@ -13,13 +13,13 @@ from operator import itemgetter
|
|
13
13
|
from queue import Queue
|
14
14
|
from threading import Thread
|
15
15
|
from typing import Callable
|
16
|
-
from urllib.parse import
|
16
|
+
from urllib.parse import ParseResult
|
17
17
|
|
18
18
|
import netports
|
19
19
|
import requests
|
20
20
|
from requests import Session, Response
|
21
21
|
from requests.exceptions import ReadTimeout, ConnectionError as RequestsConnectionError
|
22
|
-
from vhelpers import
|
22
|
+
from vhelpers import vlist, vparam
|
23
23
|
|
24
24
|
from nbforager import helpers as h
|
25
25
|
from nbforager.api import extended_get
|
@@ -293,7 +293,7 @@ class BaseC:
|
|
293
293
|
params_d_["brief"] = 1
|
294
294
|
params_d_["limit"] = 1
|
295
295
|
params_l: LParam = vparam.from_dict(params_d_)
|
296
|
-
url = f"{self.url_base}{path}?{urlencode(params_l)}"
|
296
|
+
url = f"{self.url_base}{path}?{urllib.parse.urlencode(params_l)}"
|
297
297
|
response: Response = self._retry_requests(url)
|
298
298
|
|
299
299
|
count = 0
|
@@ -316,62 +316,43 @@ class BaseC:
|
|
316
316
|
|
317
317
|
:return: Netbox objects. Update self _results.
|
318
318
|
"""
|
319
|
-
|
320
|
-
if
|
321
|
-
|
319
|
+
params_d = params_d.copy()
|
320
|
+
if "limit" not in params_d:
|
321
|
+
params_d["limit"] = [self.limit]
|
322
|
+
if "offset" not in params_d:
|
323
|
+
params_d["offset"] = [0]
|
322
324
|
|
323
|
-
max_limit: int = self._set_limit(params_d)
|
324
325
|
params_l: LParam = vparam.from_dict(params_d)
|
326
|
+
url = f"{self.url_base}{path}?{urllib.parse.urlencode(params_l)}"
|
325
327
|
|
326
328
|
results: LDAny = []
|
327
329
|
while True:
|
328
|
-
params_i = [*params_l, ("offset", offset)]
|
329
|
-
url = f"{self.url_base}{path}?{urlencode(params_i)}"
|
330
330
|
response: Response = self._retry_requests(url)
|
331
|
-
if response.ok:
|
332
|
-
html: str = response.content.decode("utf-8")
|
333
|
-
data: DAny = json.loads(html)
|
334
|
-
results_: LDAny = list(data["results"])
|
335
|
-
results.extend(results_)
|
336
|
-
else:
|
337
|
-
results_ = []
|
338
|
-
|
339
|
-
# stop requests if limit reached
|
340
|
-
if self.limit != len(results_):
|
331
|
+
if not response.ok:
|
341
332
|
break
|
342
|
-
|
333
|
+
|
334
|
+
html: str = response.content.decode("utf-8")
|
335
|
+
data: DAny = json.loads(html)
|
336
|
+
results_: LDAny = list(data["results"])
|
337
|
+
results.extend(results_)
|
338
|
+
|
339
|
+
# retrieve next offset from Response
|
340
|
+
if url_next := str(data.get("next") or ""):
|
341
|
+
url = url_next
|
342
|
+
else:
|
343
343
|
break
|
344
344
|
|
345
|
-
# next iteration
|
345
|
+
# Sleep before the next iteration to reduce server load
|
346
346
|
if self.interval:
|
347
347
|
time.sleep(self.interval)
|
348
|
-
offset += self.limit
|
349
348
|
|
350
349
|
return results
|
351
350
|
|
352
|
-
def _set_limit(self, params_d: DList) -> int:
|
353
|
-
"""Update limit valur in params_d based on limit and max_limit
|
354
|
-
|
355
|
-
:return: Max limit value, update params_d["limit"] value
|
356
|
-
"""
|
357
|
-
limit = 0
|
358
|
-
if limit_ := list(vdict.pop(data=params_d, key="limit") or []):
|
359
|
-
limit = int(limit_[0])
|
360
|
-
if not limit:
|
361
|
-
limit = self.limit
|
362
|
-
max_limit = 0
|
363
|
-
if max_limit_ := list(vdict.pop(data=params_d, key="max_limit") or []):
|
364
|
-
max_limit = int(max_limit_[0])
|
365
|
-
if max_limit and max_limit < limit:
|
366
|
-
limit = max_limit
|
367
|
-
params_d["limit"] = [limit]
|
368
|
-
return max_limit
|
369
|
-
|
370
351
|
def _query_data_thread(self, path: str, params_d: DAny) -> None:
|
371
|
-
"""Retrieve data from the Netbox.
|
352
|
+
"""Retrieve data from the Netbox and appends results to the internal results list.
|
372
353
|
|
373
|
-
If the
|
374
|
-
|
354
|
+
If the params_d does not have `offset` and the received Response contains "next" URL,
|
355
|
+
the method will recurse to fetch the next set of data.
|
375
356
|
|
376
357
|
:param path: Section of the URL that points to the model.
|
377
358
|
:param params_d: Parameters to request from the Netbox.
|
@@ -379,12 +360,26 @@ class BaseC:
|
|
379
360
|
:return: Netbox objects. Update self _results.
|
380
361
|
"""
|
381
362
|
params_l: LParam = vparam.from_dict(params_d)
|
382
|
-
url = f"{self.url_base}{path}?{urlencode(params_l)}"
|
363
|
+
url = f"{self.url_base}{path}?{urllib.parse.urlencode(params_l)}"
|
364
|
+
|
383
365
|
response: Response = self._retry_requests(url)
|
384
|
-
if response.ok:
|
385
|
-
|
386
|
-
|
387
|
-
|
366
|
+
if not response.ok:
|
367
|
+
return
|
368
|
+
|
369
|
+
html: str = response.content.decode("utf-8")
|
370
|
+
data: DAny = json.loads(html)
|
371
|
+
results_: LDAny = list(data["results"])
|
372
|
+
self._results.extend(results_)
|
373
|
+
|
374
|
+
# threading mode manage offset in top level method
|
375
|
+
if "offset" in params_d:
|
376
|
+
return
|
377
|
+
|
378
|
+
# retrieve next offset from Response
|
379
|
+
if url_next := str(data.get("next") or ""):
|
380
|
+
url_o: ParseResult = urllib.parse.urlparse(url_next)
|
381
|
+
params_d_: DAny = urllib.parse.parse_qs(url_o.query)
|
382
|
+
results_ = self._query_loop(path=path, params_d=params_d_)
|
388
383
|
self._results.extend(results_)
|
389
384
|
|
390
385
|
def _query_pages_count(self, params_ld: LDList) -> LDAny:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "nbforager"
|
3
|
-
version = "0.8.
|
3
|
+
version = "0.8.2"
|
4
4
|
description = "Python package designed to assist in working with the Netbox REST API. The filter parameters are identical to those in the Web UI filter form. It replaces brief data with full information, and Netbox objects are represented as a recursive multidimensional dictionary."
|
5
5
|
authors = ["Vladimirs Prusakovs <vladimir.prusakovs@gmail.com>"]
|
6
6
|
readme = "README.rst"
|
@@ -19,7 +19,7 @@ classifiers = [
|
|
19
19
|
homepage = "https://github.com/vladimirs-git/nbforager"
|
20
20
|
repository = "https://github.com/vladimirs-git/nbforager"
|
21
21
|
"Bug Tracker" = "https://github.com/vladimirs-git/nbforager/issues"
|
22
|
-
"Download URL" = "https://github.com/vladimirs-git/nbforager/archive/refs/tags/0.8.
|
22
|
+
"Download URL" = "https://github.com/vladimirs-git/nbforager/archive/refs/tags/0.8.2.tar.gz"
|
23
23
|
|
24
24
|
[tool.poetry.dependencies]
|
25
25
|
python = "^3.11"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|