nbforager 0.8.1__tar.gz → 0.8.3__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.3}/PKG-INFO +2 -2
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/base_c.py +53 -49
- {nbforager-0.8.1 → nbforager-0.8.3}/pyproject.toml +2 -2
- {nbforager-0.8.1 → nbforager-0.8.3}/LICENSE.txt +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/README.rst +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/__init__.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/__init__.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/base_ac.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/circuits.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/connector.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/core.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/dcim.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/extended_get.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/extras.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/ip_addresses.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/ipam.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/plugins_ca.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/status.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/tenancy.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/users.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/virtualization.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/api/wireless.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/constants.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/exceptions.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/__init__.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/base_fa.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/circuits.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/core.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/dcim.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/extras.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/forager.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/ipam.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/ipv4.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/joiner.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/tenancy.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/users.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/virtualization.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/foragers/wireless.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/helpers.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/log.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/messages.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/nb_api.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/nb_cache.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/nb_forager.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/nb_tree.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/parser/__init__.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/parser/nb_custom.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/parser/nb_parser.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/parser/nb_value.py +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/nbforager/py.typed +0 -0
- {nbforager-0.8.1 → nbforager-0.8.3}/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.3
|
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.3.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,75 +316,66 @@ class BaseC:
|
|
316
316
|
|
317
317
|
:return: Netbox objects. Update self _results.
|
318
318
|
"""
|
319
|
-
|
320
|
-
if offsets := params_d.get("offset"):
|
321
|
-
offset = int(offsets[0])
|
322
|
-
|
323
|
-
max_limit: int = self._set_limit(params_d)
|
319
|
+
params_d = self._add_params_limit_offset(params_d)
|
324
320
|
params_l: LParam = vparam.from_dict(params_d)
|
321
|
+
url = f"{self.url_base}{path}?{urllib.parse.urlencode(params_l)}"
|
325
322
|
|
326
323
|
results: LDAny = []
|
327
324
|
while True:
|
328
|
-
params_i = [*params_l, ("offset", offset)]
|
329
|
-
url = f"{self.url_base}{path}?{urlencode(params_i)}"
|
330
325
|
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_):
|
326
|
+
if not response.ok:
|
341
327
|
break
|
342
|
-
|
328
|
+
|
329
|
+
html: str = response.content.decode("utf-8")
|
330
|
+
data: DAny = json.loads(html)
|
331
|
+
results_: LDAny = list(data["results"])
|
332
|
+
results.extend(results_)
|
333
|
+
|
334
|
+
# retrieve next offset from Response
|
335
|
+
if url_next := str(data.get("next") or ""):
|
336
|
+
url = url_next
|
337
|
+
else:
|
343
338
|
break
|
344
339
|
|
345
|
-
# next iteration
|
340
|
+
# Sleep before the next iteration to reduce server load
|
346
341
|
if self.interval:
|
347
342
|
time.sleep(self.interval)
|
348
|
-
offset += self.limit
|
349
343
|
|
350
344
|
return results
|
351
345
|
|
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
346
|
def _query_data_thread(self, path: str, params_d: DAny) -> None:
|
371
|
-
"""Retrieve data from the Netbox.
|
347
|
+
"""Retrieve data from the Netbox and appends results to the internal results list.
|
372
348
|
|
373
|
-
If the
|
374
|
-
|
349
|
+
If the params_d does not have `offset` and the received Response contains "next" URL,
|
350
|
+
the method will recurse to fetch the next set of data.
|
375
351
|
|
376
352
|
:param path: Section of the URL that points to the model.
|
377
353
|
:param params_d: Parameters to request from the Netbox.
|
378
354
|
|
379
355
|
:return: Netbox objects. Update self _results.
|
380
356
|
"""
|
357
|
+
params_d = self._add_params_limit_offset(params_d)
|
381
358
|
params_l: LParam = vparam.from_dict(params_d)
|
382
|
-
url = f"{self.url_base}{path}?{urlencode(params_l)}"
|
359
|
+
url = f"{self.url_base}{path}?{urllib.parse.urlencode(params_l)}"
|
360
|
+
|
383
361
|
response: Response = self._retry_requests(url)
|
384
|
-
if response.ok:
|
385
|
-
|
386
|
-
|
387
|
-
|
362
|
+
if not response.ok:
|
363
|
+
return
|
364
|
+
|
365
|
+
html: str = response.content.decode("utf-8")
|
366
|
+
data: DAny = json.loads(html)
|
367
|
+
results_: LDAny = list(data["results"])
|
368
|
+
self._results.extend(results_)
|
369
|
+
|
370
|
+
# threading mode manage offset in top level method
|
371
|
+
if "offset" in params_d:
|
372
|
+
return
|
373
|
+
|
374
|
+
# retrieve next offset from Response
|
375
|
+
if url_next := str(data.get("next") or ""):
|
376
|
+
url_o: ParseResult = urllib.parse.urlparse(url_next)
|
377
|
+
params_d_: DAny = urllib.parse.parse_qs(url_o.query)
|
378
|
+
results_ = self._query_loop(path=path, params_d=params_d_)
|
388
379
|
self._results.extend(results_)
|
389
380
|
|
390
381
|
def _query_pages_count(self, params_ld: LDList) -> LDAny:
|
@@ -436,6 +427,19 @@ class BaseC:
|
|
436
427
|
|
437
428
|
# ============================== helper ==============================
|
438
429
|
|
430
|
+
def _add_params_limit_offset(self, params_d: DList) -> DList:
|
431
|
+
"""Add `limit` and `offset` default values to the params_d if they are not already present.
|
432
|
+
|
433
|
+
:param params_d: Parameters that need to update.
|
434
|
+
:return: Updated parameters.
|
435
|
+
"""
|
436
|
+
params_d = params_d.copy()
|
437
|
+
if "limit" not in params_d:
|
438
|
+
params_d["limit"] = [self.limit]
|
439
|
+
if "offset" not in params_d:
|
440
|
+
params_d["offset"] = [0]
|
441
|
+
return params_d
|
442
|
+
|
439
443
|
def _get_d(self) -> DAny:
|
440
444
|
"""Get dictionary from the Netbox.
|
441
445
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "nbforager"
|
3
|
-
version = "0.8.
|
3
|
+
version = "0.8.3"
|
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.3.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
|