annet 0.14.3__tar.gz → 0.14.5__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.
Potentially problematic release.
This version of annet might be problematic. Click here for more details.
- {annet-0.14.3/annet.egg-info → annet-0.14.5}/PKG-INFO +2 -2
- {annet-0.14.3 → annet-0.14.5}/README.md +74 -9
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/netbox/common/storage_opts.py +2 -1
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/netbox/provider.py +3 -0
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/netbox/v37/storage.py +5 -4
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/netdev/devdb/data/devdb.json +6 -0
- {annet-0.14.3 → annet-0.14.5}/annet/api/__init__.py +3 -3
- {annet-0.14.3 → annet-0.14.5}/annet/cli.py +4 -5
- {annet-0.14.3 → annet-0.14.5}/annet/cli_args.py +4 -9
- {annet-0.14.3 → annet-0.14.5}/annet/configs/context.yml +7 -0
- {annet-0.14.3 → annet-0.14.5}/annet/connectors.py +2 -1
- {annet-0.14.3 → annet-0.14.5}/annet/storage.py +23 -6
- {annet-0.14.3 → annet-0.14.5/annet.egg-info}/PKG-INFO +2 -2
- {annet-0.14.3 → annet-0.14.5}/annet.egg-info/requires.txt +1 -1
- {annet-0.14.3 → annet-0.14.5}/requirements.txt +1 -1
- {annet-0.14.3 → annet-0.14.5}/AUTHORS +0 -0
- {annet-0.14.3 → annet-0.14.5}/LICENSE +0 -0
- {annet-0.14.3 → annet-0.14.5}/MANIFEST.in +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/netbox/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/netbox/common/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/netbox/common/client.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/netbox/common/manufacturer.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/netbox/common/models.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/netbox/common/query.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/netbox/common/status_client.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/netbox/v24/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/netbox/v24/storage.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/adapters/netbox/v37/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annet.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/command.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/diff.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/errors.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/filter_acl.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/jsontools.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/lib.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/netdev/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/netdev/db.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/netdev/devdb/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/netdev/views/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/netdev/views/dump.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/netdev/views/hardware.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/output.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/patching.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/rbparser/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/rbparser/acl.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/rbparser/deploying.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/rbparser/ordering.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/rbparser/platform.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/rbparser/syntax.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/rulebook/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/rulebook/common.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/tabparser.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/annlib/types.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/argparse.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/configs/logging.yaml +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/deploy.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/diff.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/executor.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/filtering.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/gen.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/generators/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/generators/base.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/generators/common/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/generators/common/initial.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/generators/entire.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/generators/exceptions.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/generators/jsonfragment.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/generators/partial.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/generators/perf.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/generators/ref.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/generators/result.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/hardware.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/implicit.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/lib.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/output.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/parallel.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/patching.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/reference.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/arista/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/arista/iface.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/aruba/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/aruba/ap_env.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/aruba/misc.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/cisco/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/cisco/iface.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/cisco/misc.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/cisco/vlandb.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/common.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/deploying.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/huawei/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/huawei/aaa.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/huawei/bgp.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/huawei/iface.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/huawei/misc.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/huawei/vlandb.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/juniper/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/nexus/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/nexus/iface.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/patching.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/ribbon/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/arista.deploy +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/arista.order +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/arista.rul +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/aruba.deploy +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/aruba.order +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/aruba.rul +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/cisco.deploy +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/cisco.order +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/cisco.rul +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/huawei.deploy +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/huawei.order +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/huawei.rul +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/juniper.rul +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/nexus.deploy +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/nexus.order +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/nexus.rul +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/nokia.rul +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/pc.order +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/pc.rul +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/ribbon.deploy +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/ribbon.rul +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/routeros.order +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/rulebook/texts/routeros.rul +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/tabparser.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/text_term_format.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/tracing.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet/types.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet.egg-info/SOURCES.txt +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet.egg-info/dependency_links.txt +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet.egg-info/entry_points.txt +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet.egg-info/top_level.txt +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet_generators/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet_generators/example/__init__.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/annet_generators/example/lldp.py +0 -0
- {annet-0.14.3 → annet-0.14.5}/setup.cfg +0 -0
- {annet-0.14.3 → annet-0.14.5}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: annet
|
|
3
|
-
Version: 0.14.
|
|
3
|
+
Version: 0.14.5
|
|
4
4
|
Summary: annet
|
|
5
5
|
Home-page: https://github.com/annetutil/annet
|
|
6
6
|
License: MIT
|
|
@@ -21,5 +21,5 @@ Requires-Dist: contextlog>=1.1
|
|
|
21
21
|
Requires-Dist: valkit>=0.1.4
|
|
22
22
|
Requires-Dist: aiohttp>=3.8.4
|
|
23
23
|
Requires-Dist: yarl>=1.8.2
|
|
24
|
-
Requires-Dist: adaptix==3.0.
|
|
24
|
+
Requires-Dist: adaptix==3.0.0b7
|
|
25
25
|
Requires-Dist: dataclass-rest==0.4
|
|
@@ -13,15 +13,6 @@ Usage help can be obtained by calling ```annet -h``` or for a specific command,
|
|
|
13
13
|
|
|
14
14
|
## Overview
|
|
15
15
|
|
|
16
|
-
## Configuration
|
|
17
|
-
|
|
18
|
-
Provide `NETBOX_URL` and `NETBOX_TOKEN` environment variable to setup data source.
|
|
19
|
-
|
|
20
|
-
```shell
|
|
21
|
-
export NETBOX_URL="https://demo.netbox.dev"
|
|
22
|
-
export NETBOX_TOKEN="1234567890abcdef01234567890abcdef0123456"
|
|
23
|
-
```
|
|
24
|
-
|
|
25
16
|
### annet gen
|
|
26
17
|
|
|
27
18
|
The annet_generators directory contains many files called generators.
|
|
@@ -109,3 +100,77 @@ Normal layout. The screen with patches will be shown and the process of laying o
|
|
|
109
100
|
annet deploy -g snmp $HOST
|
|
110
101
|
```
|
|
111
102
|
Credentials will be used from the current user (username, ssh key, ssh agent, encrypted password in $HOME). -->
|
|
103
|
+
|
|
104
|
+
## Configuration
|
|
105
|
+
|
|
106
|
+
The path to the configuration file is searched in following order:
|
|
107
|
+
- `ANN_CONTEXT_CONFIG_PATH` env.
|
|
108
|
+
- `~/.annet/context.yml`.
|
|
109
|
+
- `annet/configs/context.yml`.
|
|
110
|
+
|
|
111
|
+
Config example:
|
|
112
|
+
|
|
113
|
+
```yaml
|
|
114
|
+
connection:
|
|
115
|
+
default:
|
|
116
|
+
login: ~
|
|
117
|
+
passwords: ~
|
|
118
|
+
|
|
119
|
+
generators:
|
|
120
|
+
default:
|
|
121
|
+
- my_annet_generators.example
|
|
122
|
+
|
|
123
|
+
storage:
|
|
124
|
+
default:
|
|
125
|
+
adapter: annet.adapters.file.provider
|
|
126
|
+
params:
|
|
127
|
+
path: /path/to/file
|
|
128
|
+
|
|
129
|
+
context:
|
|
130
|
+
default:
|
|
131
|
+
connection: default
|
|
132
|
+
generators: default
|
|
133
|
+
storage: default
|
|
134
|
+
|
|
135
|
+
selected_context: default
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Environment variable `ANN_SELECTED_CONTEXT` can be used to override `selected_context` parameter.
|
|
139
|
+
|
|
140
|
+
### Storages
|
|
141
|
+
|
|
142
|
+
Storages provide information about devices like FQDN, interface and so on.
|
|
143
|
+
|
|
144
|
+
#### Netbox storage
|
|
145
|
+
|
|
146
|
+
Provide `NETBOX_URL` and `NETBOX_TOKEN` environment variable to setup data source.
|
|
147
|
+
|
|
148
|
+
```shell
|
|
149
|
+
export NETBOX_URL="https://demo.netbox.dev"
|
|
150
|
+
export NETBOX_TOKEN="1234567890abcdef01234567890abcdef0123456"
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### File storage
|
|
154
|
+
```yaml
|
|
155
|
+
storage:
|
|
156
|
+
default:
|
|
157
|
+
adapter: annet.adapters.file.provider
|
|
158
|
+
params:
|
|
159
|
+
path: /path/to/file
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
cat /path/to/file:
|
|
163
|
+
|
|
164
|
+
```yaml
|
|
165
|
+
devices:
|
|
166
|
+
- fqdn: myhost.yndx.net
|
|
167
|
+
vendor: mikrotik
|
|
168
|
+
interfaces:
|
|
169
|
+
- name: eth0
|
|
170
|
+
description: test
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Extending
|
|
174
|
+
|
|
175
|
+
Annet uses [Entry Points](https://setuptools.pypa.io/en/latest/userguide/entry_point.html) mechanism for customization.
|
|
176
|
+
For example, you can implement the Storage interface on top of your favorite inventory system.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
+
from typing import Any
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
class NetboxStorageOpts:
|
|
@@ -7,7 +8,7 @@ class NetboxStorageOpts:
|
|
|
7
8
|
self.token = token
|
|
8
9
|
|
|
9
10
|
@classmethod
|
|
10
|
-
def
|
|
11
|
+
def parse_params(cls, conf_params: dict[str, str] | None, cli_opts: Any):
|
|
11
12
|
return cls(
|
|
12
13
|
url=os.getenv("NETBOX_URL", "http://localhost"),
|
|
13
14
|
token=os.getenv("NETBOX_TOKEN", "").strip(),
|
|
@@ -4,7 +4,7 @@ from ipaddress import ip_interface
|
|
|
4
4
|
from collections import defaultdict
|
|
5
5
|
|
|
6
6
|
from adaptix import P
|
|
7
|
-
from adaptix.conversion import impl_converter, link
|
|
7
|
+
from adaptix.conversion import impl_converter, link, link_constant
|
|
8
8
|
from annetbox.v37 import models as api_models
|
|
9
9
|
from annetbox.v37.client_sync import NetboxV37
|
|
10
10
|
|
|
@@ -24,13 +24,13 @@ logger = getLogger(__name__)
|
|
|
24
24
|
@impl_converter(recipe=[
|
|
25
25
|
link(P[api_models.Device].name, P[models.NetboxDevice].hostname),
|
|
26
26
|
link(P[api_models.Device].name, P[models.NetboxDevice].fqdn),
|
|
27
|
+
link_constant(P[models.NetboxDevice].neighbours, value=None),
|
|
27
28
|
])
|
|
28
29
|
def extend_device_base(
|
|
29
30
|
device: api_models.Device,
|
|
30
31
|
interfaces: List[models.Interface],
|
|
31
32
|
hw: Optional[HardwareView],
|
|
32
33
|
breed: str,
|
|
33
|
-
neighbours: Optional[List[models.NetboxDevice]],
|
|
34
34
|
storage: Storage,
|
|
35
35
|
) -> models.NetboxDevice:
|
|
36
36
|
...
|
|
@@ -45,7 +45,7 @@ def extend_device(
|
|
|
45
45
|
platform_name: str = ""
|
|
46
46
|
if device.platform:
|
|
47
47
|
platform_name = device.platform.name
|
|
48
|
-
|
|
48
|
+
res = extend_device_base(
|
|
49
49
|
device=device,
|
|
50
50
|
interfaces=interfaces,
|
|
51
51
|
breed=get_breed(
|
|
@@ -57,9 +57,10 @@ def extend_device(
|
|
|
57
57
|
device.device_type.model,
|
|
58
58
|
platform_name,
|
|
59
59
|
),
|
|
60
|
-
neighbours=neighbours,
|
|
61
60
|
storage=storage,
|
|
62
61
|
)
|
|
62
|
+
res.neighbours = neighbours
|
|
63
|
+
return res
|
|
63
64
|
|
|
64
65
|
|
|
65
66
|
@impl_converter
|
|
@@ -52,6 +52,8 @@
|
|
|
52
52
|
"Huawei.CE.CE8800.CE8850": " CE8850",
|
|
53
53
|
"Huawei.CE.CE8800.CE8851": " CE8851",
|
|
54
54
|
"Huawei.CE.CE9800": " CE98\\d\\d",
|
|
55
|
+
"Huawei.DC": " DC\\d+",
|
|
56
|
+
"Huawei.DC.DC908": " DC908",
|
|
55
57
|
"Huawei.Quidway": " S\\d+",
|
|
56
58
|
"Huawei.Quidway.S2x": " S2\\d{3}",
|
|
57
59
|
"Huawei.Quidway.S2x.S2300": " S23\\d\\d",
|
|
@@ -129,6 +131,10 @@
|
|
|
129
131
|
"Aruba.AP.AP500": " AP-5\\d\\d",
|
|
130
132
|
"Aruba.AP.AP500.AP514": " AP-514",
|
|
131
133
|
"Aruba.AP.AP500.AP515": " AP-515",
|
|
134
|
+
"Aruba.AP.AP600": " AP-6\\d\\d",
|
|
135
|
+
"Aruba.AP.AP600.AP615": " AP-615",
|
|
136
|
+
"Aruba.AP.AP600.AP635": " AP-635",
|
|
137
|
+
"Aruba.AP.AP600.AP655": " AP-655",
|
|
132
138
|
"Aruba.AP.IAP": " IAP-",
|
|
133
139
|
"Aruba.AP.IAP.IAP300": " IAP-3\\d\\d",
|
|
134
140
|
"Aruba.AP.IAP.IAP300.IAP304": " IAP-304",
|
|
@@ -45,7 +45,7 @@ from annet.output import (
|
|
|
45
45
|
)
|
|
46
46
|
from annet.parallel import Parallel, TaskResult
|
|
47
47
|
from annet.reference import RefTracker
|
|
48
|
-
from annet.storage import Device,
|
|
48
|
+
from annet.storage import Device, get_storage
|
|
49
49
|
from annet.types import Diff, ExitCode, OldNewResult, Op, PCDiff, PCDiffFile
|
|
50
50
|
|
|
51
51
|
|
|
@@ -218,8 +218,8 @@ def log_host_progress_cb(pool: Parallel, task_result: TaskResult):
|
|
|
218
218
|
stacklevel=2,
|
|
219
219
|
)
|
|
220
220
|
args = cast(cli_args.QueryOptions, pool.args[0])
|
|
221
|
-
connector =
|
|
222
|
-
storage_opts = connector.opts().
|
|
221
|
+
connector, connector_opts = get_storage()
|
|
222
|
+
storage_opts = connector.opts().parse_params(connector_opts, args)
|
|
223
223
|
with connector.storage()(storage_opts) as storage:
|
|
224
224
|
fqdns = storage.resolve_fdnds_by_query(args.query)
|
|
225
225
|
PoolProgressLogger(device_fqdns=fqdns)(pool, task_result)
|
|
@@ -19,7 +19,7 @@ from annet.diff import gen_sort_diff
|
|
|
19
19
|
from annet.gen import Loader, old_raw
|
|
20
20
|
from annet.lib import get_context_path, repair_context_file
|
|
21
21
|
from annet.output import output_driver_connector, OutputDriver
|
|
22
|
-
from annet.storage import
|
|
22
|
+
from annet.storage import get_storage
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
def fill_base_args(parser: ArgParser, pkg_name: str, logging_config: str):
|
|
@@ -62,12 +62,11 @@ def _gen_current_items(
|
|
|
62
62
|
@contextmanager
|
|
63
63
|
def get_loader(gen_args: cli_args.GenOptions, args: cli_args.QueryOptions):
|
|
64
64
|
exit_stack = ExitStack()
|
|
65
|
-
connectors = storage_connector.get_all()
|
|
66
65
|
storages = []
|
|
67
66
|
with exit_stack:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
connector, connector_opts = get_storage()
|
|
68
|
+
storage_opts = connector.opts().parse_params(connector_opts, args)
|
|
69
|
+
storages.append(exit_stack.enter_context(connector.storage()(storage_opts)))
|
|
71
70
|
yield Loader(*storages, args=gen_args)
|
|
72
71
|
|
|
73
72
|
|
|
@@ -10,7 +10,7 @@ from valkit.common import valid_string_list
|
|
|
10
10
|
|
|
11
11
|
from annet.argparse import Arg, ArgGroup, DefaultFromEnv
|
|
12
12
|
from annet.hardware import hardware_connector
|
|
13
|
-
from annet.storage import Query,
|
|
13
|
+
from annet.storage import Query, get_storage
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
# ====
|
|
@@ -361,14 +361,9 @@ class QueryOptionsBase(CacheOptions):
|
|
|
361
361
|
def __init__(self, *args, **kwargs):
|
|
362
362
|
super().__init__(*args, **kwargs)
|
|
363
363
|
if not isinstance(self.query, Query):
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
elif len(connectors) == 1:
|
|
368
|
-
query_type = connectors[0].query()
|
|
369
|
-
self.query = query_type.new(self.query, hosts_range=self.hosts_range)
|
|
370
|
-
else:
|
|
371
|
-
logging.warning("Multiple connectors found, skip parsing query")
|
|
364
|
+
storage, _ = get_storage()
|
|
365
|
+
query_type = storage.query()
|
|
366
|
+
self.query = query_type.new(self.query, hosts_range=self.hosts_range)
|
|
372
367
|
|
|
373
368
|
|
|
374
369
|
class QueryOptions(QueryOptionsBase):
|
|
@@ -10,9 +10,16 @@ generators:
|
|
|
10
10
|
default:
|
|
11
11
|
- annet_generators.example
|
|
12
12
|
|
|
13
|
+
storage:
|
|
14
|
+
default:
|
|
15
|
+
adapter: annet.adapters.file.provider
|
|
16
|
+
params:
|
|
17
|
+
path: /path/to/file
|
|
18
|
+
|
|
13
19
|
context:
|
|
14
20
|
default:
|
|
15
21
|
connection: default
|
|
16
22
|
generators: default
|
|
23
|
+
storage: default
|
|
17
24
|
|
|
18
25
|
selected_context: default
|
|
@@ -3,6 +3,7 @@ from abc import ABC
|
|
|
3
3
|
from functools import cached_property
|
|
4
4
|
from importlib.metadata import entry_points
|
|
5
5
|
from typing import Generic, Optional, Type, TypeVar, List
|
|
6
|
+
from annet.lib import get_context
|
|
6
7
|
|
|
7
8
|
T = TypeVar("T")
|
|
8
9
|
|
|
@@ -33,7 +34,7 @@ class Connector(ABC, Generic[T]):
|
|
|
33
34
|
res = self._classes[0]
|
|
34
35
|
return res(*args, **kwargs)
|
|
35
36
|
|
|
36
|
-
def get_all(self, *args, **kwargs) -> T:
|
|
37
|
+
def get_all(self, *args, **kwargs) -> list[T]:
|
|
37
38
|
if self._classes is None:
|
|
38
39
|
self._classes = self._entry_point or [self._get_default()]
|
|
39
40
|
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import abc
|
|
2
2
|
from typing import Any, Iterable, Optional, Type, Union, Protocol
|
|
3
|
-
|
|
4
|
-
try:
|
|
5
|
-
from annet.connectors import Connector
|
|
6
|
-
except ImportError:
|
|
7
|
-
from noc.annushka.annet.connectors import Connector # noqa: F401
|
|
3
|
+
from annet.connectors import Connector, get_context
|
|
8
4
|
|
|
9
5
|
|
|
10
6
|
class _StorageConnector(Connector["StorageProvider"]):
|
|
@@ -28,6 +24,10 @@ class StorageProvider(abc.ABC):
|
|
|
28
24
|
def query(self) -> Type["Query"]:
|
|
29
25
|
pass
|
|
30
26
|
|
|
27
|
+
@abc.abstractmethod
|
|
28
|
+
def name(self) -> str:
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
31
|
|
|
32
32
|
class Storage(abc.ABC):
|
|
33
33
|
@abc.abstractmethod
|
|
@@ -69,7 +69,7 @@ class Storage(abc.ABC):
|
|
|
69
69
|
class StorageOpts(abc.ABC):
|
|
70
70
|
@classmethod
|
|
71
71
|
@abc.abstractmethod
|
|
72
|
-
def
|
|
72
|
+
def parse_params(cls, conf_params: dict[str, str] | None, cli_opts: Any):
|
|
73
73
|
pass
|
|
74
74
|
|
|
75
75
|
|
|
@@ -123,3 +123,20 @@ class Device(Protocol):
|
|
|
123
123
|
@abc.abstractmethod
|
|
124
124
|
def breed(self):
|
|
125
125
|
pass
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def get_storage() -> (Storage, dict[str, Any]):
|
|
129
|
+
connectors = storage_connector.get_all()
|
|
130
|
+
seen: list[str] = []
|
|
131
|
+
if context_storage := get_context().get("storage"):
|
|
132
|
+
for connector in connectors:
|
|
133
|
+
con_name = connector.name()
|
|
134
|
+
seen.append(con_name)
|
|
135
|
+
if "adapter" not in context_storage:
|
|
136
|
+
raise Exception("adapter is not set in %s" % context_storage)
|
|
137
|
+
if context_storage["adapter"] == con_name:
|
|
138
|
+
return connector, context_storage.get("params", {})
|
|
139
|
+
else:
|
|
140
|
+
raise Exception("unknown storage %s: seen %s" % (context_storage["adapter"], seen))
|
|
141
|
+
else:
|
|
142
|
+
return connectors[0], {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: annet
|
|
3
|
-
Version: 0.14.
|
|
3
|
+
Version: 0.14.5
|
|
4
4
|
Summary: annet
|
|
5
5
|
Home-page: https://github.com/annetutil/annet
|
|
6
6
|
License: MIT
|
|
@@ -21,5 +21,5 @@ Requires-Dist: contextlog>=1.1
|
|
|
21
21
|
Requires-Dist: valkit>=0.1.4
|
|
22
22
|
Requires-Dist: aiohttp>=3.8.4
|
|
23
23
|
Requires-Dist: yarl>=1.8.2
|
|
24
|
-
Requires-Dist: adaptix==3.0.
|
|
24
|
+
Requires-Dist: adaptix==3.0.0b7
|
|
25
25
|
Requires-Dist: dataclass-rest==0.4
|
|
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
|
|
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
|
|
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
|