gnetcli-adapter 2.0.0__tar.gz → 2.0.2__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.
- {gnetcli_adapter-2.0.0 → gnetcli_adapter-2.0.2}/PKG-INFO +1 -1
- {gnetcli_adapter-2.0.0 → gnetcli_adapter-2.0.2}/src/gnetcli_adapter/gnetcli_adapter.py +35 -9
- {gnetcli_adapter-2.0.0 → gnetcli_adapter-2.0.2}/README.md +0 -0
- {gnetcli_adapter-2.0.0 → gnetcli_adapter-2.0.2}/pyproject.toml +0 -0
- {gnetcli_adapter-2.0.0 → gnetcli_adapter-2.0.2}/src/gnetcli_adapter/__init__.py +0 -0
|
@@ -15,6 +15,7 @@ from annet.connectors import AdapterWithConfig, AdapterWithName
|
|
|
15
15
|
from typing import Dict, List, Any, Optional, Tuple
|
|
16
16
|
from annet.storage import Device
|
|
17
17
|
from gnetclisdk.client import Credentials, Gnetcli, HostParams, QA, File
|
|
18
|
+
from gnetclisdk.exceptions import EOFError
|
|
18
19
|
import gnetclisdk.proto.server_pb2 as pb
|
|
19
20
|
from pydantic import Field, field_validator, FieldValidationInfo
|
|
20
21
|
from pydantic_core import PydanticUndefined
|
|
@@ -307,6 +308,7 @@ def make_api(conf: AppSettings) -> Gnetcli:
|
|
|
307
308
|
while time.monotonic() - start < 5:
|
|
308
309
|
if _local_gnetcli_p is not None and _local_gnetcli_p.returncode is not None:
|
|
309
310
|
raise Exception("gnetcli server died with code %s" % _local_gnetcli_p.returncode)
|
|
311
|
+
gnetcli_url = _local_gnetcli_url
|
|
310
312
|
else:
|
|
311
313
|
gnetcli_url = conf.url
|
|
312
314
|
auth_token = conf.make_server_credentials()
|
|
@@ -318,6 +320,16 @@ def make_api(conf: AppSettings) -> Gnetcli:
|
|
|
318
320
|
)
|
|
319
321
|
return api
|
|
320
322
|
|
|
323
|
+
def format_trace(trace: list[pb.CMDTraceItem]) -> str:
|
|
324
|
+
res:list[str] = []
|
|
325
|
+
for t in trace:
|
|
326
|
+
op = "unknown" # TODO: get from pb
|
|
327
|
+
if t.operation == 2:
|
|
328
|
+
op = "write"
|
|
329
|
+
elif t.operation == 3:
|
|
330
|
+
op = "read"
|
|
331
|
+
res.append(f"{op}={t.data}")
|
|
332
|
+
return "\n".join(res)
|
|
321
333
|
|
|
322
334
|
class GnetcliDeployer(DeployDriver, AdapterWithConfig, AdapterWithName):
|
|
323
335
|
def __init__(
|
|
@@ -391,12 +403,26 @@ class GnetcliDeployer(DeployDriver, AdapterWithConfig, AdapterWithName):
|
|
|
391
403
|
async with self.api.cmd_session(hostname=device.fqdn) as sess:
|
|
392
404
|
result: List[pb.CMDResult] = []
|
|
393
405
|
for cmd in run_cmds:
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
406
|
+
if progress_bar:
|
|
407
|
+
progress_bar.set_progress(device.fqdn, done_cmds, total_cmds, suffix=cmd.cmd)
|
|
408
|
+
try:
|
|
409
|
+
res = await sess.cmd(
|
|
410
|
+
cmd=cmd.cmd,
|
|
411
|
+
cmd_timeout=cmd.timeout,
|
|
412
|
+
host_params=host_params,
|
|
413
|
+
qa=parse_annet_qa(cmd.questions or []),
|
|
414
|
+
trace=True,
|
|
415
|
+
)
|
|
416
|
+
time.sleep(1)
|
|
417
|
+
except EOFError as e:
|
|
418
|
+
if cmd.suppress_eof:
|
|
419
|
+
if progress_bar:
|
|
420
|
+
progress_bar.set_progress(device.fqdn, total_cmds, total_cmds, suffix=f"suppressed EOF: {cmd.cmd}")
|
|
421
|
+
break # we can't exec subsequent cmds
|
|
422
|
+
raise e
|
|
423
|
+
if progress_bar:
|
|
424
|
+
tr = format_trace(res.trace)
|
|
425
|
+
progress_bar.set_content(device.fqdn, f"cmd={cmd.cmd} out={res.out_str} status={res.status}\n{tr}")
|
|
400
426
|
done_cmds += 1
|
|
401
427
|
if res.status != 0:
|
|
402
428
|
if cmd.suppress_nonzero:
|
|
@@ -406,10 +432,10 @@ class GnetcliDeployer(DeployDriver, AdapterWithConfig, AdapterWithName):
|
|
|
406
432
|
raise Exception("cmd %s error %s status %s", cmd, res.error, res.status)
|
|
407
433
|
result.append(res)
|
|
408
434
|
if progress_bar:
|
|
409
|
-
progress_bar.set_progress(device.fqdn,
|
|
435
|
+
progress_bar.set_progress(device.fqdn, done_cmds, total_cmds)
|
|
410
436
|
if do_reload:
|
|
411
437
|
for file, cmds in reload_cmds.items():
|
|
412
|
-
_logger.debug("reload %s", file, cmds)
|
|
438
|
+
_logger.debug("reload %s %s", file, cmds)
|
|
413
439
|
for cmd in cmds:
|
|
414
440
|
if progress_bar:
|
|
415
441
|
progress_bar.set_progress(device.fqdn, done_cmds, total_cmds, suffix=f"{file}:{cmd.cmd}")
|
|
@@ -431,7 +457,7 @@ class GnetcliDeployer(DeployDriver, AdapterWithConfig, AdapterWithName):
|
|
|
431
457
|
break # break on command for current file
|
|
432
458
|
raise Exception("cmd %s error %s status %s", cmd, res.error, res.status)
|
|
433
459
|
result.append(res)
|
|
434
|
-
if progress_bar:
|
|
460
|
+
if reload_cmds and progress_bar:
|
|
435
461
|
progress_bar.set_progress(device.fqdn, total_cmds, total_cmds)
|
|
436
462
|
if seen_exc and progress_bar:
|
|
437
463
|
progress_bar.set_exception(device.fqdn, "seen exception", str(seen_exc), total_cmds)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|