annet 0.16.10__py3-none-any.whl → 0.16.12__py3-none-any.whl
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.
Potentially problematic release.
This version of annet might be problematic. Click here for more details.
- annet/adapters/netbox/common/client.py +3 -1
- annet/adapters/netbox/common/storage_opts.py +8 -2
- annet/adapters/netbox/provider.py +3 -2
- annet/adapters/netbox/v37/storage.py +7 -0
- annet/generators/jsonfragment.py +7 -6
- annet/implicit.py +1 -0
- annet/output.py +18 -4
- {annet-0.16.10.dist-info → annet-0.16.12.dist-info}/METADATA +1 -2
- {annet-0.16.10.dist-info → annet-0.16.12.dist-info}/RECORD +14 -14
- {annet-0.16.10.dist-info → annet-0.16.12.dist-info}/WHEEL +1 -1
- {annet-0.16.10.dist-info → annet-0.16.12.dist-info}/AUTHORS +0 -0
- {annet-0.16.10.dist-info → annet-0.16.12.dist-info}/LICENSE +0 -0
- {annet-0.16.10.dist-info → annet-0.16.12.dist-info}/entry_points.txt +0 -0
- {annet-0.16.10.dist-info → annet-0.16.12.dist-info}/top_level.txt +0 -0
|
@@ -79,9 +79,11 @@ def collect(func: Func, field: str = "", batch_size: int = 100) -> Func:
|
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
class BaseNetboxClient(RequestsClient):
|
|
82
|
-
def __init__(self, url: str, token: str):
|
|
82
|
+
def __init__(self, url: str, token: str, insecure: bool = False):
|
|
83
83
|
url = url.rstrip("/") + "/api/"
|
|
84
84
|
session = Session()
|
|
85
|
+
if insecure:
|
|
86
|
+
session.verify = False
|
|
85
87
|
if token:
|
|
86
88
|
session.headers["Authorization"] = f"Token {token}"
|
|
87
89
|
super().__init__(url, session)
|
|
@@ -5,12 +5,18 @@ DEFAULT_URL = "http://localhost"
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class NetboxStorageOpts:
|
|
8
|
-
def __init__(self, url: str, token: str):
|
|
8
|
+
def __init__(self, url: str, token: str, insecure: bool = False):
|
|
9
9
|
self.url = url
|
|
10
10
|
self.token = token
|
|
11
|
+
self.insecure = insecure
|
|
11
12
|
|
|
12
13
|
@classmethod
|
|
13
14
|
def parse_params(cls, conf_params: Optional[dict[str, str]], cli_opts: Any):
|
|
14
15
|
url = os.getenv("NETBOX_URL") or conf_params.get("url") or DEFAULT_URL
|
|
15
16
|
token = os.getenv("NETBOX_TOKEN", "").strip() or conf_params.get("token") or ""
|
|
16
|
-
|
|
17
|
+
insecure = False
|
|
18
|
+
if insecure_env := os.getenv("NETBOX_INSECURE", "").lower():
|
|
19
|
+
insecure = insecure_env in ("true", "1", "t")
|
|
20
|
+
else:
|
|
21
|
+
insecure = bool(conf_params.get("insecure") or False)
|
|
22
|
+
return cls(url=url, token=token, insecure=insecure)
|
|
@@ -12,7 +12,7 @@ from .v37.storage import NetboxStorageV37
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def storage_factory(opts: NetboxStorageOpts) -> Storage:
|
|
15
|
-
client = NetboxStatusClient(opts.url, opts.token)
|
|
15
|
+
client = NetboxStatusClient(opts.url, opts.token, opts.insecure)
|
|
16
16
|
try:
|
|
17
17
|
status = client.status()
|
|
18
18
|
except ClientError as e:
|
|
@@ -27,9 +27,10 @@ def storage_factory(opts: NetboxStorageOpts) -> Storage:
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
class NetboxProvider(StorageProvider, AdapterWithName, AdapterWithConfig):
|
|
30
|
-
def __init__(self, url: Optional[str] = None, token: Optional[str] = None):
|
|
30
|
+
def __init__(self, url: Optional[str] = None, token: Optional[str] = None, insecure: bool = False):
|
|
31
31
|
self.url = url
|
|
32
32
|
self.token = token
|
|
33
|
+
self.insecure = insecure
|
|
33
34
|
|
|
34
35
|
@classmethod
|
|
35
36
|
def with_config(cls, **kwargs: Dict[str, Any]) -> T:
|
|
@@ -2,6 +2,7 @@ from logging import getLogger
|
|
|
2
2
|
from typing import Any, Optional, List, Union, Dict
|
|
3
3
|
from ipaddress import ip_interface
|
|
4
4
|
from collections import defaultdict
|
|
5
|
+
import ssl
|
|
5
6
|
|
|
6
7
|
from adaptix import P
|
|
7
8
|
from adaptix.conversion import impl_converter, link, link_constant
|
|
@@ -86,9 +87,15 @@ def extend_ip_address(
|
|
|
86
87
|
|
|
87
88
|
class NetboxStorageV37(Storage):
|
|
88
89
|
def __init__(self, opts: Optional[NetboxStorageOpts] = None):
|
|
90
|
+
ctx: ssl.con | ssl.SSLContext = None
|
|
91
|
+
if opts.insecure:
|
|
92
|
+
ctx = ssl.create_default_context()
|
|
93
|
+
ctx.check_hostname = False
|
|
94
|
+
ctx.verify_mode = ssl.CERT_NONE
|
|
89
95
|
self.netbox = NetboxV37(
|
|
90
96
|
url=opts.url,
|
|
91
97
|
token=opts.token,
|
|
98
|
+
ssl_context=ctx,
|
|
92
99
|
)
|
|
93
100
|
self._all_fqdns: Optional[list[str]] = None
|
|
94
101
|
|
annet/generators/jsonfragment.py
CHANGED
|
@@ -96,22 +96,23 @@ class JSONFragment(TreeGenerator):
|
|
|
96
96
|
def _set_or_replace_dict(self, pointer, value):
|
|
97
97
|
if not pointer:
|
|
98
98
|
if self._json_config == {}:
|
|
99
|
-
self._json_config = value
|
|
99
|
+
self._json_config = self.process_value(value)
|
|
100
100
|
else:
|
|
101
|
-
self._json_config = [self._json_config, value]
|
|
101
|
+
self._json_config = [self._json_config, self.process_value(value)]
|
|
102
102
|
else:
|
|
103
103
|
self._set_dict(self._json_config, pointer, value)
|
|
104
104
|
|
|
105
|
+
def process_scalar_value(self, value: Any) -> Any:
|
|
106
|
+
return str(value)
|
|
107
|
+
|
|
105
108
|
def process_value(self, value: Any) -> Any:
|
|
106
|
-
if isinstance(value,
|
|
107
|
-
return value
|
|
108
|
-
elif isinstance(value, list):
|
|
109
|
+
if isinstance(value, (list, set, frozenset)):
|
|
109
110
|
return [self.process_value(x) for x in value]
|
|
110
111
|
elif isinstance(value, dict):
|
|
111
112
|
for k, v in value.items():
|
|
112
113
|
value[k] = self.process_value(v)
|
|
113
114
|
return value
|
|
114
|
-
return
|
|
115
|
+
return self.process_scalar_value(value)
|
|
115
116
|
|
|
116
117
|
def _set_dict(self, cfg, pointer, value):
|
|
117
118
|
# pointer has at least one key
|
annet/implicit.py
CHANGED
annet/output.py
CHANGED
|
@@ -2,9 +2,12 @@ import abc
|
|
|
2
2
|
import os
|
|
3
3
|
import posixpath
|
|
4
4
|
import sys
|
|
5
|
-
from typing import List, Optional, Tuple, Type
|
|
5
|
+
from typing import Dict, List, Optional, Tuple, Type
|
|
6
|
+
from urllib.parse import urlparse
|
|
6
7
|
|
|
7
8
|
import colorama
|
|
9
|
+
from contextlog import get_logger
|
|
10
|
+
|
|
8
11
|
from annet.annlib.output import ( # pylint: disable=unused-import
|
|
9
12
|
LABEL_NEW_PREFIX,
|
|
10
13
|
OutputWriter,
|
|
@@ -17,8 +20,6 @@ from annet.annlib.output import ( # pylint: disable=unused-import
|
|
|
17
20
|
print_err_label,
|
|
18
21
|
print_label,
|
|
19
22
|
)
|
|
20
|
-
from contextlog import get_logger
|
|
21
|
-
|
|
22
23
|
from annet.cli_args import FileOutOptions, QueryOptions
|
|
23
24
|
from annet.connectors import Connector
|
|
24
25
|
from annet.storage import Device, storage_connector
|
|
@@ -112,9 +113,11 @@ class OutputDriverBasic(OutputDriver):
|
|
|
112
113
|
if label.startswith(os.sep):
|
|
113
114
|
# just in case.
|
|
114
115
|
label = label.lstrip(os.sep)
|
|
116
|
+
|
|
115
117
|
if os.sep not in label:
|
|
116
118
|
# vendor config
|
|
117
119
|
label = os.path.basename(label)
|
|
120
|
+
|
|
118
121
|
else:
|
|
119
122
|
# entire generated file
|
|
120
123
|
parts = label.split(os.sep)
|
|
@@ -125,6 +128,7 @@ class OutputDriverBasic(OutputDriver):
|
|
|
125
128
|
if query_result_count > 1 or arg_out.dest_force_create_dir:
|
|
126
129
|
label = os.path.join(hostname, label)
|
|
127
130
|
file_dest = os.path.join(dest, "errors") if is_fail else dest
|
|
131
|
+
|
|
128
132
|
out_file = os.path.normpath(os.path.join(file_dest, label))
|
|
129
133
|
logger.info("writing '%s'", out_file)
|
|
130
134
|
dirname = os.path.dirname(out_file)
|
|
@@ -164,12 +168,22 @@ class OutputDriverBasic(OutputDriver):
|
|
|
164
168
|
>>>
|
|
165
169
|
```
|
|
166
170
|
"""
|
|
171
|
+
|
|
167
172
|
# NOTE: с полученным `config_path` работаем через `posixpath`, а не через `os.path`, потому что
|
|
168
173
|
# entire-путь POSIX-специфичный; но в конце формируем путь через `os.path` для текущей платформы
|
|
169
174
|
if not posixpath.abspath(config_path):
|
|
170
175
|
raise RuntimeError(f"Want absolute config path, but relative received: {config_path}")
|
|
176
|
+
|
|
171
177
|
cfg_files = self.cfg_file_names(device)
|
|
172
|
-
|
|
178
|
+
|
|
179
|
+
parsed_config_path = urlparse(config_path)
|
|
180
|
+
scheme, config_path = parsed_config_path.scheme or "file", parsed_config_path.path
|
|
181
|
+
|
|
173
182
|
relative_config_path = posixpath.relpath(config_path, "/")
|
|
183
|
+
if scheme != "file":
|
|
184
|
+
host = parsed_config_path.hostname + f":{parsed_config_path.port}" if parsed_config_path.port else ""
|
|
185
|
+
relative_config_path = os.path.join(host, relative_config_path)
|
|
186
|
+
|
|
174
187
|
dest_config_path_parts = [cfg_files[0]] + relative_config_path.split(posixpath.sep)
|
|
188
|
+
|
|
175
189
|
return os.path.join(*dest_config_path_parts)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: annet
|
|
3
|
-
Version: 0.16.
|
|
3
|
+
Version: 0.16.12
|
|
4
4
|
Summary: annet
|
|
5
5
|
Home-page: https://github.com/annetutil/annet
|
|
6
6
|
License: MIT
|
|
@@ -19,7 +19,6 @@ Requires-Dist: psutil >=5.8.0
|
|
|
19
19
|
Requires-Dist: packaging >=23.2
|
|
20
20
|
Requires-Dist: contextlog >=1.1
|
|
21
21
|
Requires-Dist: valkit >=0.1.4
|
|
22
|
-
Requires-Dist: aiohttp >=3.8.4
|
|
23
22
|
Requires-Dist: yarl >=1.8.2
|
|
24
23
|
Requires-Dist: adaptix ==3.0.0b7
|
|
25
24
|
Requires-Dist: dataclass-rest ==0.4
|
|
@@ -11,9 +11,9 @@ annet/executor.py,sha256=Jny-hm0otZA1naPpFWR-R16SbaZioSQ8pkx-Yd2PYlM,19004
|
|
|
11
11
|
annet/filtering.py,sha256=ZtqxPsKdV9reZoRxtQyBg22BqyMqd-2SotYcxZ-68AQ,903
|
|
12
12
|
annet/gen.py,sha256=rOAveprvBaEXbLyaQUhQ0QtOvcDfndlIOpchNhu8M1U,33499
|
|
13
13
|
annet/hardware.py,sha256=_iR28dWiPtt6ZYdk-qg1sxazkSRJE3ukqKB-fFFfQak,1141
|
|
14
|
-
annet/implicit.py,sha256=
|
|
14
|
+
annet/implicit.py,sha256=P-vNhHtckMnEd8K2TiMTJWoegRcyQ_XFmrBaMdanhKU,5603
|
|
15
15
|
annet/lib.py,sha256=lOdz3UJFYkO0wnuzIRRq3FpULQliqBtfmGmKOGVFO4Q,4238
|
|
16
|
-
annet/output.py,sha256=
|
|
16
|
+
annet/output.py,sha256=FYMcWCc43-b51KsCiKnXPZHawhgWNoVtY9gRqw__Ce0,7473
|
|
17
17
|
annet/parallel.py,sha256=hLkzEht0KhzmzUWDdO4QFYQHzhxs3wPlTA8DxbB2ziw,17160
|
|
18
18
|
annet/patching.py,sha256=nILbY5oJajN0b1j3f0HEJm05H3HVThnWvB7vDVh7UQw,559
|
|
19
19
|
annet/reference.py,sha256=B8mH8VUMcecPnzULiTVb_kTQ7jQrCL7zp4pfIZQa5fk,4035
|
|
@@ -29,18 +29,18 @@ annet/adapters/fetchers/stub/fetcher.py,sha256=bJGNJcvjrxSa4d8gly6NkaRcxoK57zbZh
|
|
|
29
29
|
annet/adapters/file/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
30
30
|
annet/adapters/file/provider.py,sha256=Wn3sG2TOI6ZWuRHhPSyg8S0Dnrz5LN3VyuqE6S7r5GM,5930
|
|
31
31
|
annet/adapters/netbox/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
|
-
annet/adapters/netbox/provider.py,sha256=
|
|
32
|
+
annet/adapters/netbox/provider.py,sha256=cEPdHKw4zWA3Wrfmj01spQrkGpwcQdZ0Jjy51m5mvs4,1542
|
|
33
33
|
annet/adapters/netbox/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
34
|
-
annet/adapters/netbox/common/client.py,sha256
|
|
34
|
+
annet/adapters/netbox/common/client.py,sha256=PaxHG4W9H8_uunIwMBNYkLq4eQJYoO6p6gY-ciQs7Nc,2563
|
|
35
35
|
annet/adapters/netbox/common/manufacturer.py,sha256=QoTjmuBAg5klOJqeo8HuS2HybIUGsjTkknLkQL_Tiec,1606
|
|
36
36
|
annet/adapters/netbox/common/models.py,sha256=SeWQZV-zvaKvK2YT2Bwf-iapkIs5pr7I7rAI7vlFMB8,6886
|
|
37
37
|
annet/adapters/netbox/common/query.py,sha256=ziUFM7cUEbEIf3k1szTll4aO-OCUa-2Ogxbebi7Tegs,646
|
|
38
38
|
annet/adapters/netbox/common/status_client.py,sha256=W4nTb2yvBlJ2UkWUmUhKQ2PaSQb1shjhHj5ebb4s2s4,591
|
|
39
|
-
annet/adapters/netbox/common/storage_opts.py,sha256=
|
|
39
|
+
annet/adapters/netbox/common/storage_opts.py,sha256=0xQeO_OGex73cV9UA5XZn7hLiyhGYwNHYtO5JtMSR4o,815
|
|
40
40
|
annet/adapters/netbox/v24/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
41
41
|
annet/adapters/netbox/v24/storage.py,sha256=THI592VLx3ehixsPZQ1Ko3mYIAZQbnDY-toIziqBbL8,6005
|
|
42
42
|
annet/adapters/netbox/v37/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
|
-
annet/adapters/netbox/v37/storage.py,sha256=
|
|
43
|
+
annet/adapters/netbox/v37/storage.py,sha256=nCcQtjrAvi9sW0_XHZDCFnOk1XIbWUO_pRt1m6E0ELk,9957
|
|
44
44
|
annet/annlib/__init__.py,sha256=fT1l4xV5fqqg8HPw9HqmZVN2qwS8i6X1aIm2zGDjxKY,252
|
|
45
45
|
annet/annlib/command.py,sha256=uuBddMQphtn8P5MO5kzIa8_QrtMns-k05VeKv1bcAuA,1043
|
|
46
46
|
annet/annlib/diff.py,sha256=MZ6eQAU3cadQp8KaSE6uAYFtcfMDCIe_eNuVROnYkCk,4496
|
|
@@ -74,7 +74,7 @@ annet/generators/__init__.py,sha256=rVHHDTPKHPZsml1eNEAj3o-8RweFTN8J7LX3tKMXdIY,
|
|
|
74
74
|
annet/generators/base.py,sha256=rgQLcQBPZm4ecbKmRhVOpBR-GFJAiVfdb_y5f2-LUR8,3670
|
|
75
75
|
annet/generators/entire.py,sha256=7WySkVaXNT3ZAiHcQ0JUKdlhGJAN8cNUxF6c7ilYnO8,2928
|
|
76
76
|
annet/generators/exceptions.py,sha256=GPXTBgn2xZ3Ev_bdOPlfCLGRC1kQHe_dEq88S-uyi5s,151
|
|
77
|
-
annet/generators/jsonfragment.py,sha256=
|
|
77
|
+
annet/generators/jsonfragment.py,sha256=s7zOjX6JR43sIA9wse13GEPU06aeOa75uiA8WBOVDa8,4207
|
|
78
78
|
annet/generators/partial.py,sha256=XI01KDA--XwjSEU33SOQCCJZRXFq5boRz1uJA8lVA1g,3502
|
|
79
79
|
annet/generators/perf.py,sha256=K72ivUuXbNXrsHrLeKWhGmczGYWsB7kUDdDzqOX6j3c,2370
|
|
80
80
|
annet/generators/ref.py,sha256=QVdeL8po1D0kBsVLOpCjFR81D8yNTk-kaQj5WUM4hng,438
|
|
@@ -152,10 +152,10 @@ annet_generators/example/lldp.py,sha256=24bGvShxbio-JxUdaehyPRu31LhH9YwSwFDrWVRn
|
|
|
152
152
|
annet_generators/mesh_example/__init__.py,sha256=NfNWgXn1TNiWI6A5tmU6Y-4QV2i33td0Qs3re0MNNMo,218
|
|
153
153
|
annet_generators/mesh_example/bgp.py,sha256=ck--yU_lUdAX9DWaaVQ-C29eQN-EGf1gEpOTBxmMnWA,1317
|
|
154
154
|
annet_generators/mesh_example/mesh_logic.py,sha256=5Wt17LPt-EWe126IFAdaQQGWIOR3mxTJjAMUY8K0c0w,971
|
|
155
|
-
annet-0.16.
|
|
156
|
-
annet-0.16.
|
|
157
|
-
annet-0.16.
|
|
158
|
-
annet-0.16.
|
|
159
|
-
annet-0.16.
|
|
160
|
-
annet-0.16.
|
|
161
|
-
annet-0.16.
|
|
155
|
+
annet-0.16.12.dist-info/AUTHORS,sha256=rh3w5P6gEgqmuC-bw-HB68vBCr-yIBFhVL0PG4hguLs,878
|
|
156
|
+
annet-0.16.12.dist-info/LICENSE,sha256=yPxl7dno02Pw7gAcFPIFONzx_gapwDoPXsIsh6Y7lC0,1079
|
|
157
|
+
annet-0.16.12.dist-info/METADATA,sha256=YbWZDXAcXsV-IkxQAak-afnS7CZ3jtGF2IY5HJZiwcY,745
|
|
158
|
+
annet-0.16.12.dist-info/WHEEL,sha256=a7TGlA-5DaHMRrarXjVbQagU3Man_dCnGIWMJr5kRWo,91
|
|
159
|
+
annet-0.16.12.dist-info/entry_points.txt,sha256=5lIaDGlGi3l6QQ2ry2jZaqViP5Lvt8AmsegdD0Uznck,192
|
|
160
|
+
annet-0.16.12.dist-info/top_level.txt,sha256=QsoTZBsUtwp_FEcmRwuN8QITBmLOZFqjssRfKilGbP8,23
|
|
161
|
+
annet-0.16.12.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|