gnetcli-adapter 2.0.0__tar.gz → 2.0.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: gnetcli_adapter
3
- Version: 2.0.0
3
+ Version: 2.0.1
4
4
  Summary: Gnetcli-server adapter for Annet
5
5
  Author-email: Aleksandr Balezin <gescheit12@gmail.com>
6
6
  Requires-Python: >=3.10
@@ -307,6 +307,7 @@ def make_api(conf: AppSettings) -> Gnetcli:
307
307
  while time.monotonic() - start < 5:
308
308
  if _local_gnetcli_p is not None and _local_gnetcli_p.returncode is not None:
309
309
  raise Exception("gnetcli server died with code %s" % _local_gnetcli_p.returncode)
310
+ gnetcli_url = _local_gnetcli_url
310
311
  else:
311
312
  gnetcli_url = conf.url
312
313
  auth_token = conf.make_server_credentials()
@@ -318,6 +319,16 @@ def make_api(conf: AppSettings) -> Gnetcli:
318
319
  )
319
320
  return api
320
321
 
322
+ def format_trace(trace: list[pb.CMDTraceItem]) -> str:
323
+ res:list[str] = []
324
+ for t in trace:
325
+ op = "unknown" # TODO: get from pb
326
+ if t.operation == 2:
327
+ op = "write"
328
+ elif t.operation == 3:
329
+ op = "read"
330
+ res.append(f"{op}={t.data}")
331
+ return "\n".join(res)
321
332
 
322
333
  class GnetcliDeployer(DeployDriver, AdapterWithConfig, AdapterWithName):
323
334
  def __init__(
@@ -391,12 +402,18 @@ class GnetcliDeployer(DeployDriver, AdapterWithConfig, AdapterWithName):
391
402
  async with self.api.cmd_session(hostname=device.fqdn) as sess:
392
403
  result: List[pb.CMDResult] = []
393
404
  for cmd in run_cmds:
405
+ if progress_bar:
406
+ progress_bar.set_progress(device.fqdn, done_cmds, total_cmds, suffix=cmd.cmd)
394
407
  res = await sess.cmd(
395
408
  cmd=cmd.cmd,
396
409
  cmd_timeout=cmd.timeout,
397
410
  host_params=host_params,
398
411
  qa=parse_annet_qa(cmd.questions or []),
412
+ trace=True,
399
413
  )
414
+ if progress_bar:
415
+ tr = format_trace(res.trace)
416
+ progress_bar.set_content(device.fqdn, f"cmd={cmd.cmd} out={res.out_str} status={res.status}\n{tr}")
400
417
  done_cmds += 1
401
418
  if res.status != 0:
402
419
  if cmd.suppress_nonzero:
@@ -406,10 +423,10 @@ class GnetcliDeployer(DeployDriver, AdapterWithConfig, AdapterWithName):
406
423
  raise Exception("cmd %s error %s status %s", cmd, res.error, res.status)
407
424
  result.append(res)
408
425
  if progress_bar:
409
- progress_bar.set_progress(device.fqdn, len(cmds), total_cmds)
426
+ progress_bar.set_progress(device.fqdn, done_cmds, total_cmds)
410
427
  if do_reload:
411
428
  for file, cmds in reload_cmds.items():
412
- _logger.debug("reload %s", file, cmds)
429
+ _logger.debug("reload %s %s", file, cmds)
413
430
  for cmd in cmds:
414
431
  if progress_bar:
415
432
  progress_bar.set_progress(device.fqdn, done_cmds, total_cmds, suffix=f"{file}:{cmd.cmd}")