gnetcli-adapter 2.0.3__tar.gz → 2.0.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 annetutil
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: gnetcli_adapter
3
- Version: 2.0.3
3
+ Version: 2.0.5
4
4
  Summary: Gnetcli-server adapter for Annet
5
5
  Author-email: Aleksandr Balezin <gescheit12@gmail.com>
6
6
  Requires-Python: >=3.10
@@ -11,6 +11,7 @@ Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Programming Language :: Python :: 3 :: Only
12
12
  Classifier: Programming Language :: Python :: 3.10
13
13
  Classifier: Programming Language :: Python :: 3.11
14
+ License-File: LICENSE
14
15
  Requires-Dist: annet>=1.0.0
15
16
  Requires-Dist: gnetclisdk>=1.0.31
16
17
  Requires-Dist: pydantic_settings
@@ -33,6 +33,7 @@ breed_to_device = {
33
33
  "bcom-os": "bcomos",
34
34
  "pc": "pc",
35
35
  "cuml2": "pc",
36
+ "moxa": "pc",
36
37
  "jun10": "juniper",
37
38
  "eos4": "arista",
38
39
  "h3c": "h3c",
@@ -231,23 +232,34 @@ class GnetcliFetcher(Fetcher, AdapterWithConfig, AdapterWithName):
231
232
  devices: List[Device],
232
233
  files_to_download: Optional[Dict[Device, List[str]]] = None,
233
234
  processes: int = 1,
234
- max_slots: int = 0,):
235
+ max_slots: int = 0,
236
+ ):
235
237
  running = {}
236
238
  failed_running = {}
239
+
240
+ tasks = {}
237
241
  for device in devices:
238
- try:
239
- if files_to_download or device.is_pc():
240
- if files_to_download:
241
- files =files_to_download.get(device, [])
242
- dev_res = await self.adownload_dev(device=device, files=files)
243
- else:
244
- dev_res = {}
242
+ if files_to_download or device.is_pc():
243
+ if files_to_download:
244
+ files = files_to_download.get(device, [])
245
+ task = asyncio.create_task(self.adownload_dev(device=device, files=files))
246
+ tasks[task] = device
245
247
  else:
246
- dev_res = await self.afetch_dev(device=device)
247
- except Exception as e:
248
- failed_running[device] = e
248
+ running[device] = {}
249
+ else:
250
+ task = asyncio.create_task(self.afetch_dev(device=device))
251
+ tasks[task] = device
252
+
253
+ if not tasks:
254
+ return running, failed_running
255
+
256
+ done, pending = await asyncio.wait(list(tasks), return_when=asyncio.ALL_COMPLETED)
257
+ for task in done:
258
+ device = tasks[task]
259
+ if (exc := task.exception()) is not None:
260
+ failed_running[device] = exc
249
261
  else:
250
- running[device] = dev_res
262
+ running[device] = task.result()
251
263
  return running, failed_running
252
264
 
253
265
  async def afetch_dev(self, device: Device) -> str:
@@ -272,13 +284,14 @@ class GnetcliFetcher(Fetcher, AdapterWithConfig, AdapterWithName):
272
284
  return b"\n".join(dev_result).decode()
273
285
 
274
286
  async def adownload_dev(self, device: Device, files: List[str]) -> Dict[str, str]:
287
+ gnetcli_device = breed_to_device.get(device.breed, device.breed)
275
288
  ip = get_device_ip(device)
276
289
  downloaded = await self.api.download(
277
290
  hostname=device.fqdn,
278
291
  paths=files,
279
292
  host_params=HostParams(
280
293
  credentials=self.conf.make_dev_credentials(),
281
- device="pc",
294
+ device=gnetcli_device,
282
295
  ip=ip,
283
296
  ),
284
297
  )