nbforager 0.4.1__tar.gz → 0.6.0__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.4.1 → nbforager-0.6.0}/PKG-INFO +6 -6
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/__init__.py +0 -13
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/base_c.py +2 -2
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/circuits.py +1 -1
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/connector.py +1 -1
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/extended_get.py +1 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/ipam.py +1 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/base_fa.py +1 -3
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/circuits.py +3 -3
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/core.py +3 -3
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/dcim.py +3 -3
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/extras.py +3 -3
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/forager.py +1 -14
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/ipam.py +3 -3
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/ipv4.py +1 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/joiner.py +1 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/tenancy.py +3 -3
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/users.py +3 -3
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/virtualization.py +3 -3
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/wireless.py +3 -3
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/helpers.py +6 -3
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/log.py +1 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/messages.py +1 -1
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/nb_api.py +81 -27
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/nb_forager.py +10 -34
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/nb_tree.py +1 -9
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/parser/nb_custom.py +1 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/parser/nb_parser.py +1 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/parser/nb_value.py +1 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/types_.py +3 -3
- {nbforager-0.4.1 → nbforager-0.6.0}/pyproject.toml +28 -23
- nbforager-0.4.1/nbforager/py_tree.py +0 -265
- {nbforager-0.4.1 → nbforager-0.6.0}/LICENSE.txt +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/README.rst +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/__init__.py +0 -0
- /nbforager-0.4.1/nbforager/api/base_ca.py → /nbforager-0.6.0/nbforager/api/base_ac.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/core.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/dcim.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/extras.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/ip_addresses.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/plugins_ca.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/status.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/tenancy.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/users.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/virtualization.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/api/wireless.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/exceptions.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/foragers/__init__.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/nb_cache.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/parser/__init__.py +0 -0
- {nbforager-0.4.1 → nbforager-0.6.0}/nbforager/py.typed +0 -0
@@ -1,8 +1,7 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: nbforager
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.6.0
|
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
|
-
Home-page: https://github.com/vladimirs-git/nbforager
|
6
5
|
License: Apache-2.0
|
7
6
|
Keywords: netbox
|
8
7
|
Author: Vladimirs Prusakovs
|
@@ -18,18 +17,19 @@ Classifier: Programming Language :: Python :: 3.9
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.10
|
19
18
|
Classifier: Programming Language :: Python :: 3.11
|
20
19
|
Classifier: Programming Language :: Python :: 3.12
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
21
21
|
Provides-Extra: test
|
22
22
|
Requires-Dist: ciscoconfparse (>=1.9,<2.0)
|
23
23
|
Requires-Dist: netports (>=0.14,<1.0.0)
|
24
24
|
Requires-Dist: pydantic (>=2,<3)
|
25
|
-
Requires-Dist: pynetbox (>=7.3.3,<8.0.0)
|
26
25
|
Requires-Dist: requests (>=2,<3)
|
27
26
|
Requires-Dist: tabulate (>=0.9.0,<0.10.0)
|
28
27
|
Requires-Dist: tomli (==2.0.1)
|
29
28
|
Requires-Dist: vhelpers (>=0.3,<1.0.0)
|
30
29
|
Project-URL: Bug Tracker, https://github.com/vladimirs-git/nbforager/issues
|
31
|
-
Project-URL: Download URL, https://github.com/vladimirs-git/nbforager/archive/refs/tags/0.
|
32
|
-
Project-URL:
|
30
|
+
Project-URL: Download URL, https://github.com/vladimirs-git/nbforager/archive/refs/tags/0.6.0.tar.gz
|
31
|
+
Project-URL: homepage, https://github.com/vladimirs-git/nbforager
|
32
|
+
Project-URL: repository, https://github.com/vladimirs-git/nbforager
|
33
33
|
Description-Content-Type: text/x-rst
|
34
34
|
|
35
35
|
|
@@ -355,12 +355,12 @@ class BaseC:
|
|
355
355
|
:return: Max limit value, update params_d["limit"] value
|
356
356
|
"""
|
357
357
|
limit = 0
|
358
|
-
if limit_ := vdict.pop(params_d, key="limit") or []:
|
358
|
+
if limit_ := list(vdict.pop(data=params_d, key="limit") or []):
|
359
359
|
limit = int(limit_[0])
|
360
360
|
if not limit:
|
361
361
|
limit = self.limit
|
362
362
|
max_limit = 0
|
363
|
-
if max_limit_ := vdict.pop(params_d, key="max_limit") or []:
|
363
|
+
if max_limit_ := list(vdict.pop(data=params_d, key="max_limit") or []):
|
364
364
|
max_limit = int(max_limit_[0])
|
365
365
|
if max_limit and max_limit < limit:
|
366
366
|
limit = max_limit
|
@@ -4,14 +4,13 @@ from nbforager import helpers as h
|
|
4
4
|
from nbforager.api import ConnectorA
|
5
5
|
from nbforager.nb_api import NbApi
|
6
6
|
from nbforager.nb_tree import NbTree
|
7
|
-
from nbforager.py_tree import PyTree
|
8
7
|
from nbforager.types_ import LStr
|
9
8
|
|
10
9
|
|
11
10
|
class BaseAF:
|
12
11
|
"""Base for Application Foragers."""
|
13
12
|
|
14
|
-
def __init__(self, api: NbApi, root: NbTree, tree: NbTree
|
13
|
+
def __init__(self, api: NbApi, root: NbTree, tree: NbTree):
|
15
14
|
"""Init BaseAF.
|
16
15
|
|
17
16
|
:param root: Dictionary where data from Netbox needs to be saved.
|
@@ -19,7 +18,6 @@ class BaseAF:
|
|
19
18
|
self.api = api
|
20
19
|
self.root: NbTree = root
|
21
20
|
self.tree: NbTree = tree
|
22
|
-
self.pynb: PyTree = pynb
|
23
21
|
self.app: str = h.attr_name(self)
|
24
22
|
self.connector: ConnectorA = getattr(api, self.app) # connector to application
|
25
23
|
|
@@ -1,24 +1,24 @@
|
|
1
1
|
# pylint: disable=R0902,R0903
|
2
2
|
|
3
3
|
"""Circuits Forager."""
|
4
|
+
|
4
5
|
from nbforager.foragers.base_fa import BaseAF
|
5
6
|
from nbforager.foragers.forager import Forager
|
6
7
|
from nbforager.nb_api import NbApi
|
7
8
|
from nbforager.nb_tree import NbTree
|
8
|
-
from nbforager.py_tree import PyTree
|
9
9
|
|
10
10
|
|
11
11
|
class CircuitsAF(BaseAF):
|
12
12
|
"""Circuits Forager."""
|
13
13
|
|
14
|
-
def __init__(self, api: NbApi, root: NbTree, tree: NbTree
|
14
|
+
def __init__(self, api: NbApi, root: NbTree, tree: NbTree):
|
15
15
|
"""Init CircuitsAF.
|
16
16
|
|
17
17
|
:param api: NbApi object, connector to Netbox API.
|
18
18
|
:param root: NbTree object where raw data from Netbox needs to be saved.
|
19
19
|
:param tree: NbTree object where transformed data from Netbox needs to be saved.
|
20
20
|
"""
|
21
|
-
super().__init__(api, root, tree
|
21
|
+
super().__init__(api, root, tree)
|
22
22
|
self.circuit_terminations = self.CircuitTerminationsF(self)
|
23
23
|
self.circuit_types = self.CircuitTypesF(self)
|
24
24
|
self.circuits = self.CircuitsF(self)
|
@@ -1,24 +1,24 @@
|
|
1
1
|
# pylint: disable=R0902,R0903
|
2
2
|
|
3
3
|
"""Core Forager."""
|
4
|
+
|
4
5
|
from nbforager.foragers.base_fa import BaseAF
|
5
6
|
from nbforager.foragers.forager import Forager
|
6
7
|
from nbforager.nb_api import NbApi
|
7
8
|
from nbforager.nb_tree import NbTree
|
8
|
-
from nbforager.py_tree import PyTree
|
9
9
|
|
10
10
|
|
11
11
|
class CoreAF(BaseAF):
|
12
12
|
"""Core Forager."""
|
13
13
|
|
14
|
-
def __init__(self, api: NbApi, root: NbTree, tree: NbTree
|
14
|
+
def __init__(self, api: NbApi, root: NbTree, tree: NbTree):
|
15
15
|
"""Init CoreAF.
|
16
16
|
|
17
17
|
:param api: NbApi object, connector to Netbox API.
|
18
18
|
:param root: NbTree object where raw data from Netbox needs to be saved.
|
19
19
|
:param tree: NbTree object where transformed data from Netbox needs to be saved.
|
20
20
|
"""
|
21
|
-
super().__init__(api, root, tree
|
21
|
+
super().__init__(api, root, tree)
|
22
22
|
self.data_files = self.DataFilesF(self)
|
23
23
|
self.data_sources = self.DataSourcesF(self)
|
24
24
|
self.jobs = self.JobsF(self)
|
@@ -1,24 +1,24 @@
|
|
1
1
|
# pylint: disable=R0902,R0903
|
2
2
|
|
3
3
|
"""DCIM Forager."""
|
4
|
+
|
4
5
|
from nbforager.foragers.base_fa import BaseAF
|
5
6
|
from nbforager.foragers.forager import Forager
|
6
7
|
from nbforager.nb_api import NbApi
|
7
8
|
from nbforager.nb_tree import NbTree
|
8
|
-
from nbforager.py_tree import PyTree
|
9
9
|
|
10
10
|
|
11
11
|
class DcimAF(BaseAF):
|
12
12
|
"""DCIM Forager."""
|
13
13
|
|
14
|
-
def __init__(self, api: NbApi, root: NbTree, tree: NbTree
|
14
|
+
def __init__(self, api: NbApi, root: NbTree, tree: NbTree):
|
15
15
|
"""Init DcimAF.
|
16
16
|
|
17
17
|
:param api: NbApi object, connector to Netbox API.
|
18
18
|
:param root: NbTree object where raw data from Netbox needs to be saved.
|
19
19
|
:param tree: NbTree object where transformed data from Netbox needs to be saved.
|
20
20
|
"""
|
21
|
-
super().__init__(api, root, tree
|
21
|
+
super().__init__(api, root, tree)
|
22
22
|
self.cable_terminations = self.CableTerminationsF(self)
|
23
23
|
self.cables = self.CablesF(self)
|
24
24
|
# connected_device, is not model
|
@@ -1,24 +1,24 @@
|
|
1
1
|
# pylint: disable=R0902,R0903
|
2
2
|
|
3
3
|
"""Extras Forager."""
|
4
|
+
|
4
5
|
from nbforager.foragers.base_fa import BaseAF
|
5
6
|
from nbforager.foragers.forager import Forager
|
6
7
|
from nbforager.nb_api import NbApi
|
7
8
|
from nbforager.nb_tree import NbTree
|
8
|
-
from nbforager.py_tree import PyTree
|
9
9
|
|
10
10
|
|
11
11
|
class ExtrasAF(BaseAF):
|
12
12
|
"""Extras Forager."""
|
13
13
|
|
14
|
-
def __init__(self, api: NbApi, root: NbTree, tree: NbTree
|
14
|
+
def __init__(self, api: NbApi, root: NbTree, tree: NbTree):
|
15
15
|
"""Init ExtrasAF.
|
16
16
|
|
17
17
|
:param api: NbApi object, connector to Netbox API.
|
18
18
|
:param root: NbTree object where raw data from Netbox needs to be saved.
|
19
19
|
:param tree: NbTree object where transformed data from Netbox needs to be saved.
|
20
20
|
"""
|
21
|
-
super().__init__(api, root, tree
|
21
|
+
super().__init__(api, root, tree)
|
22
22
|
self.bookmarks = self.BookmarksF(self)
|
23
23
|
self.config_contexts = self.ConfigContextsF(self)
|
24
24
|
self.config_templates = self.ConfigTemplatesF(self)
|
@@ -16,8 +16,7 @@ from nbforager import nb_tree
|
|
16
16
|
from nbforager.nb_api import NbApi
|
17
17
|
from nbforager.nb_tree import NbTree
|
18
18
|
from nbforager.parser import nb_parser
|
19
|
-
from nbforager.
|
20
|
-
from nbforager.types_ import LDAny, DiDAny, LStr, LT2StrDAny, DList, LDList, DiAny, SInt, DAny
|
19
|
+
from nbforager.types_ import LDAny, DiDAny, LStr, LT2StrDAny, DList, LDList, SInt, DAny
|
21
20
|
|
22
21
|
|
23
22
|
class Forager:
|
@@ -40,7 +39,6 @@ class Forager:
|
|
40
39
|
self.root_d: DiDAny = getattr(getattr(self.root, app), model)
|
41
40
|
self.tree: NbTree = forager_a.tree
|
42
41
|
self.tree_d: DiDAny = getattr(getattr(self.tree, app), model)
|
43
|
-
self.pynb: PyTree = forager_a.pynb
|
44
42
|
|
45
43
|
def __repr__(self) -> str:
|
46
44
|
"""__repr__."""
|
@@ -340,17 +338,6 @@ class Forager:
|
|
340
338
|
data["_nested"] = False
|
341
339
|
model_d[idx] = data
|
342
340
|
|
343
|
-
def _get_pynb_data(self, path: str) -> DiAny:
|
344
|
-
"""Get data in self pynb by app/model path.
|
345
|
-
|
346
|
-
:param path: The app/model path.
|
347
|
-
|
348
|
-
:return: The model data.
|
349
|
-
"""
|
350
|
-
app, model = h.path_to_attrs(path)
|
351
|
-
data = getattr(getattr(self.pynb, app), model)
|
352
|
-
return data
|
353
|
-
|
354
341
|
def _get_root_data(self, path: str) -> DiDAny:
|
355
342
|
"""Get data in self root by app/model path.
|
356
343
|
|
@@ -1,24 +1,24 @@
|
|
1
1
|
# pylint: disable=R0902,R0903
|
2
2
|
|
3
3
|
"""IPAM Forager."""
|
4
|
+
|
4
5
|
from nbforager.foragers.base_fa import BaseAF
|
5
6
|
from nbforager.foragers.forager import Forager
|
6
7
|
from nbforager.nb_api import NbApi
|
7
8
|
from nbforager.nb_tree import NbTree
|
8
|
-
from nbforager.py_tree import PyTree
|
9
9
|
|
10
10
|
|
11
11
|
class IpamAF(BaseAF):
|
12
12
|
"""IPAM Forager."""
|
13
13
|
|
14
|
-
def __init__(self, api: NbApi, root: NbTree, tree: NbTree
|
14
|
+
def __init__(self, api: NbApi, root: NbTree, tree: NbTree):
|
15
15
|
"""Init IpamAF.
|
16
16
|
|
17
17
|
:param api: NbApi object, connector to Netbox API.
|
18
18
|
:param root: NbTree object where raw data from Netbox needs to be saved.
|
19
19
|
:param tree: NbTree object where transformed data from Netbox needs to be saved.
|
20
20
|
"""
|
21
|
-
super().__init__(api, root, tree
|
21
|
+
super().__init__(api, root, tree)
|
22
22
|
self.aggregates = self.AggregatesF(self)
|
23
23
|
self.asn_ranges = self.AsnRangesF(self)
|
24
24
|
self.asns = self.AsnsF(self)
|
@@ -1,24 +1,24 @@
|
|
1
1
|
# pylint: disable=R0902,R0903
|
2
2
|
|
3
3
|
"""Tenancy Forager."""
|
4
|
+
|
4
5
|
from nbforager.foragers.base_fa import BaseAF
|
5
6
|
from nbforager.foragers.forager import Forager
|
6
7
|
from nbforager.nb_api import NbApi
|
7
8
|
from nbforager.nb_tree import NbTree
|
8
|
-
from nbforager.py_tree import PyTree
|
9
9
|
|
10
10
|
|
11
11
|
class TenancyAF(BaseAF):
|
12
12
|
"""Tenancy Forager."""
|
13
13
|
|
14
|
-
def __init__(self, api: NbApi, root: NbTree, tree: NbTree
|
14
|
+
def __init__(self, api: NbApi, root: NbTree, tree: NbTree):
|
15
15
|
"""Init TenancyAF.
|
16
16
|
|
17
17
|
:param api: NbApi object, connector to Netbox API.
|
18
18
|
:param root: NbTree object where raw data from Netbox needs to be saved.
|
19
19
|
:param tree: NbTree object where transformed data from Netbox needs to be saved.
|
20
20
|
"""
|
21
|
-
super().__init__(api, root, tree
|
21
|
+
super().__init__(api, root, tree)
|
22
22
|
self.contact_assignments = self.ContactAssignmentsF(self)
|
23
23
|
self.contact_groups = self.ContactGroupsF(self)
|
24
24
|
self.contact_roles = self.ContactRolesF(self)
|
@@ -1,24 +1,24 @@
|
|
1
1
|
# pylint: disable=R0902,R0903
|
2
2
|
|
3
3
|
"""Users Forager."""
|
4
|
+
|
4
5
|
from nbforager.foragers.base_fa import BaseAF
|
5
6
|
from nbforager.foragers.forager import Forager
|
6
7
|
from nbforager.nb_api import NbApi
|
7
8
|
from nbforager.nb_tree import NbTree
|
8
|
-
from nbforager.py_tree import PyTree
|
9
9
|
|
10
10
|
|
11
11
|
class UsersAF(BaseAF):
|
12
12
|
"""Users Forager."""
|
13
13
|
|
14
|
-
def __init__(self, api: NbApi, root: NbTree, tree: NbTree
|
14
|
+
def __init__(self, api: NbApi, root: NbTree, tree: NbTree):
|
15
15
|
"""Init UsersAF.
|
16
16
|
|
17
17
|
:param api: NbApi object, connector to Netbox API.
|
18
18
|
:param root: NbTree object where raw data from Netbox needs to be saved.
|
19
19
|
:param tree: NbTree object where transformed data from Netbox needs to be saved.
|
20
20
|
"""
|
21
|
-
super().__init__(api, root, tree
|
21
|
+
super().__init__(api, root, tree)
|
22
22
|
# config: is not DiDAny
|
23
23
|
self.groups = self.GroupsF(self)
|
24
24
|
self.permissions = self.PermissionsF(self)
|
@@ -1,24 +1,24 @@
|
|
1
1
|
# pylint: disable=R0902,R0903
|
2
2
|
|
3
3
|
"""Tenancy Virtualization."""
|
4
|
+
|
4
5
|
from nbforager.foragers.base_fa import BaseAF
|
5
6
|
from nbforager.foragers.forager import Forager
|
6
7
|
from nbforager.nb_api import NbApi
|
7
8
|
from nbforager.nb_tree import NbTree
|
8
|
-
from nbforager.py_tree import PyTree
|
9
9
|
|
10
10
|
|
11
11
|
class VirtualizationAF(BaseAF):
|
12
12
|
"""Virtualization Virtualization."""
|
13
13
|
|
14
|
-
def __init__(self, api: NbApi, root: NbTree, tree: NbTree
|
14
|
+
def __init__(self, api: NbApi, root: NbTree, tree: NbTree):
|
15
15
|
"""Init VirtualizationAF.
|
16
16
|
|
17
17
|
:param api: NbApi object, connector to Netbox API.
|
18
18
|
:param root: NbTree object where raw data from Netbox needs to be saved.
|
19
19
|
:param tree: NbTree object where transformed data from Netbox needs to be saved.
|
20
20
|
"""
|
21
|
-
super().__init__(api, root, tree
|
21
|
+
super().__init__(api, root, tree)
|
22
22
|
self.cluster_groups = self.ClusterGroupsF(self)
|
23
23
|
self.cluster_types = self.ClusterTypesF(self)
|
24
24
|
self.clusters = self.ClustersF(self)
|
@@ -1,24 +1,24 @@
|
|
1
1
|
# pylint: disable=R0902,R0903
|
2
2
|
|
3
3
|
"""Wireless Forager."""
|
4
|
+
|
4
5
|
from nbforager.foragers.base_fa import BaseAF
|
5
6
|
from nbforager.foragers.forager import Forager
|
6
7
|
from nbforager.nb_api import NbApi
|
7
8
|
from nbforager.nb_tree import NbTree
|
8
|
-
from nbforager.py_tree import PyTree
|
9
9
|
|
10
10
|
|
11
11
|
class WirelessAF(BaseAF):
|
12
12
|
"""Wireless Forager."""
|
13
13
|
|
14
|
-
def __init__(self, api: NbApi, root: NbTree, tree: NbTree
|
14
|
+
def __init__(self, api: NbApi, root: NbTree, tree: NbTree):
|
15
15
|
"""Init WirelessAF.
|
16
16
|
|
17
17
|
:param api: NbApi object, connector to Netbox API.
|
18
18
|
:param root: NbTree object where raw data from Netbox needs to be saved.
|
19
19
|
:param tree: NbTree object where transformed data from Netbox needs to be saved.
|
20
20
|
"""
|
21
|
-
super().__init__(api, root, tree
|
21
|
+
super().__init__(api, root, tree)
|
22
22
|
self.wireless_lan_groups = self.WirelessLanGroupsF(self)
|
23
23
|
self.wireless_lans = self.WirelessLansF(self)
|
24
24
|
self.wireless_links = self.WirelessLinksF(self)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""Helper functions."""
|
2
|
+
|
2
3
|
import itertools
|
3
|
-
import re
|
4
4
|
import urllib
|
5
5
|
from typing import Any
|
6
6
|
from urllib.parse import ParseResult, urlencode, urlparse, parse_qs
|
@@ -14,6 +14,7 @@ from nbforager.types_ import LTInt2, DAny, SeqStr, SStr, TValues, TLists, T2Str,
|
|
14
14
|
|
15
15
|
# =========================== app model id ===========================
|
16
16
|
|
17
|
+
|
17
18
|
def am_to_object_type(app: str, model: str) -> str:
|
18
19
|
"""Convert application and model to object_type.
|
19
20
|
|
@@ -30,6 +31,7 @@ def am_to_object_type(app: str, model: str) -> str:
|
|
30
31
|
model_singular = f"vm{model_singular}"
|
31
32
|
return f"{app}.{model_singular}"
|
32
33
|
|
34
|
+
|
33
35
|
def attr_name(obj: Any) -> str:
|
34
36
|
"""Transform the class name to the attribute name, lowercase without postfix.
|
35
37
|
|
@@ -170,6 +172,7 @@ def path_to_attrs(path: str) -> T2Str:
|
|
170
172
|
model = model_to_attr(model)
|
171
173
|
return app, model
|
172
174
|
|
175
|
+
|
173
176
|
def plural_to_singular(plural: str) -> str:
|
174
177
|
"""Convert a plural model name to a singular model name.
|
175
178
|
|
@@ -189,6 +192,7 @@ def plural_to_singular(plural: str) -> str:
|
|
189
192
|
singular = singular[:-1] # types -> type
|
190
193
|
return singular
|
191
194
|
|
195
|
+
|
192
196
|
def replace_upper(word: str) -> str:
|
193
197
|
"""Replace upper character with underscore and lower.
|
194
198
|
|
@@ -339,7 +343,7 @@ def url_to_object_type(url: str) -> str:
|
|
339
343
|
:example:
|
340
344
|
url_to_object_type("/api/ipam/ip-addresses/1/") -> "ipam.ipaddress"
|
341
345
|
"""
|
342
|
-
app, model,
|
346
|
+
app, model, _ = url_to_ami(url)
|
343
347
|
object_type = am_to_object_type(app, model)
|
344
348
|
return object_type
|
345
349
|
|
@@ -361,7 +365,6 @@ def url_to_ui_url(url: str) -> str:
|
|
361
365
|
return ui_url
|
362
366
|
|
363
367
|
|
364
|
-
|
365
368
|
# ============================== params ==============================
|
366
369
|
|
367
370
|
|
@@ -20,9 +20,21 @@ from nbforager.api.tenancy import TenancyAC
|
|
20
20
|
from nbforager.api.users import UsersAC
|
21
21
|
from nbforager.api.virtualization import VirtualizationAC
|
22
22
|
from nbforager.api.wireless import WirelessAC
|
23
|
-
from nbforager.nb_tree import NbTree
|
24
23
|
from nbforager.parser.nb_parser import NbParser
|
25
|
-
from nbforager.types_ import ODLStr, ODDAny, DAny, LDAny
|
24
|
+
from nbforager.types_ import ODLStr, ODDAny, DAny, LDAny, LStr, LT2Str
|
25
|
+
|
26
|
+
APPS = (
|
27
|
+
"circuits",
|
28
|
+
"core",
|
29
|
+
"dcim",
|
30
|
+
"extras",
|
31
|
+
"ipam",
|
32
|
+
"plugins",
|
33
|
+
"tenancy",
|
34
|
+
"users",
|
35
|
+
"virtualization",
|
36
|
+
"wireless",
|
37
|
+
)
|
26
38
|
|
27
39
|
|
28
40
|
class NbApi:
|
@@ -48,27 +60,27 @@ class NbApi:
|
|
48
60
|
"""
|
49
61
|
|
50
62
|
def __init__(
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
63
|
+
self,
|
64
|
+
host: str,
|
65
|
+
token: str = "",
|
66
|
+
scheme: str = "https",
|
67
|
+
port: int = 0,
|
68
|
+
verify: bool = True,
|
69
|
+
limit: int = 1000,
|
70
|
+
url_length: int = 2047,
|
71
|
+
# Multithreading
|
72
|
+
threads: int = 1,
|
73
|
+
interval: float = 0.0,
|
74
|
+
# Errors processing
|
75
|
+
timeout: int = 60,
|
76
|
+
max_retries: int = 0,
|
77
|
+
sleep: int = 10,
|
78
|
+
strict: bool = False,
|
79
|
+
# Settings
|
80
|
+
extended_get: bool = True,
|
81
|
+
default_get: ODDAny = None,
|
82
|
+
loners: ODLStr = None,
|
83
|
+
**kwargs,
|
72
84
|
):
|
73
85
|
"""Init NbApi.
|
74
86
|
|
@@ -199,6 +211,8 @@ class NbApi:
|
|
199
211
|
loners=connector.loners,
|
200
212
|
)
|
201
213
|
|
214
|
+
# ============================= property =============================
|
215
|
+
|
202
216
|
@property
|
203
217
|
def host(self) -> str:
|
204
218
|
"""Netbox host name."""
|
@@ -222,12 +236,52 @@ class NbApi:
|
|
222
236
|
|
223
237
|
:return: None. Update threads in all connectors.
|
224
238
|
"""
|
225
|
-
|
226
|
-
|
227
|
-
for model in
|
239
|
+
for app in self.apps():
|
240
|
+
models: LStr = [s for s in dir(getattr(self, app)) if s[0].islower()]
|
241
|
+
for model in models:
|
228
242
|
connector = getattr(getattr(self, app), model)
|
229
243
|
setattr(connector, "threads", threads)
|
230
244
|
|
245
|
+
# ============================= methods ==============================
|
246
|
+
|
247
|
+
@staticmethod
|
248
|
+
def apps() -> LStr:
|
249
|
+
"""Get list of application names.
|
250
|
+
|
251
|
+
:return: Applications.
|
252
|
+
:rtype: List[str]
|
253
|
+
"""
|
254
|
+
return list(APPS)
|
255
|
+
|
256
|
+
def app_models(self) -> LT2Str:
|
257
|
+
"""Get list of application model names.
|
258
|
+
|
259
|
+
:return: Application model names.
|
260
|
+
:rtype: List[Tuple[str, str]]
|
261
|
+
"""
|
262
|
+
app_models: LT2Str = []
|
263
|
+
for app in self.apps():
|
264
|
+
models: LStr = [s for s in dir(getattr(self, app)) if s[0].islower()]
|
265
|
+
for model in models:
|
266
|
+
app_models.append((app, model))
|
267
|
+
return app_models
|
268
|
+
|
269
|
+
def app_paths(self) -> LStr:
|
270
|
+
"""Get list of application/model paths.
|
271
|
+
|
272
|
+
:return: Application/model paths.
|
273
|
+
:rtype: List[str]
|
274
|
+
"""
|
275
|
+
app_paths: LStr = []
|
276
|
+
for app in self.apps():
|
277
|
+
models: LStr = [s for s in dir(getattr(self, app)) if s[0].islower()]
|
278
|
+
for model in models:
|
279
|
+
connector = getattr(getattr(self, app), model)
|
280
|
+
path = getattr(connector, "path")
|
281
|
+
path = path.rstrip("/")
|
282
|
+
app_paths.append(path)
|
283
|
+
return app_paths
|
284
|
+
|
231
285
|
def copy(self, **kwargs) -> NbApi:
|
232
286
|
"""Create a duplicate of the object.
|
233
287
|
|
@@ -317,7 +371,7 @@ class NbApi:
|
|
317
371
|
url = str(kwargs.get("url") or "")
|
318
372
|
app, model, _ = h.url_to_ami(url)
|
319
373
|
data: DAny = {k: v for k, v in kwargs.items() if k not in ["url", "id"]}
|
320
|
-
method: Callable = getattr(getattr(getattr(self, app), model), "
|
374
|
+
method: Callable = getattr(getattr(getattr(self, app), model), "create_d")
|
321
375
|
return method(**data)
|
322
376
|
|
323
377
|
def delete(self, **kwargs) -> Response:
|