centralcli
Advanced tools
@@ -8,2 +8,3 @@ from __future__ import annotations | ||
| from ...client import BatchRequest | ||
| from centralcli.response import BatchResponse | ||
@@ -235,33 +236,31 @@ if TYPE_CHECKING: | ||
| br = BatchRequest | ||
| funcs = [ | ||
| self.wids_get_interfering_aps, | ||
| self.wids_get_neighbor_aps, | ||
| self.wids_get_suspect_aps, | ||
| self.wids_get_rogue_aps, | ||
| ] | ||
| funcs = { | ||
| "interfering_aps": self.wids_get_interfering_aps, | ||
| "neighbor_aps": self.wids_get_neighbor_aps, | ||
| "suspect_aps": self.wids_get_suspect_aps, | ||
| "rogue_aps": self.wids_get_rogue_aps, | ||
| } | ||
| batch_req = [ | ||
| br(f, **params) for f in funcs | ||
| br(f, **params) for f in funcs.values() | ||
| ] | ||
| # TODO send to CombinedResponse | ||
| batch_res = await self.session._batch_request(batch_req) | ||
| resp = batch_res[-1] | ||
| ok_res = [idx for idx, res in enumerate(batch_res) if res.ok] | ||
| if not len(ok_res) == len(funcs): | ||
| failed = [x for x in range(0, len(funcs)) if x not in ok_res] | ||
| for f in failed: | ||
| if f in range(0, len(batch_res)): | ||
| log.error(f"{batch_res[f].method} {batch_res[f].url.path} Returned Error Status {batch_res[f].status}. {batch_res[f].output or batch_res[f].error}", show=True) | ||
| if ok_res: | ||
| log.error(f"Partial Failure {batch_res[f].method}:{batch_res[f].url.path} returned {batch_res[f].status} {batch_res[f].error} [italic]see logs[/]", caption=True) | ||
| raw_keys = ["interfering_aps", "neighbor_aps", "suspect_aps"] | ||
| if resp.ok: | ||
| resp.raw = {"rogue_aps": resp.raw.get("rogue_aps", []), "_counts": {"rogues": resp.raw.get("total")}} # TODO need more error handling | ||
| for idx, key in enumerate(raw_keys): | ||
| if idx in ok_res: | ||
| resp.raw = {**resp.raw, **{key: batch_res[idx].raw.get(key, [])}} | ||
| resp.raw["_counts"][key.rstrip("_aps")] = batch_res[idx].raw.get("total") | ||
| resp.output = [*resp.output, *batch_res[idx].output] | ||
| batch_res = BatchResponse(await self.session._batch_request(batch_req)) | ||
| if not batch_res.passed: | ||
| return batch_res.failed[-1] # should only be 1 item given batch_request will abort if first call fails | ||
| if batch_res.failed: | ||
| for f in batch_res.failed: | ||
| log.error(f"Partial Failure {f.method}:{f.url.path} returned {f.status} {f.error} [italic]see logs[/]", caption=True) | ||
| resp = batch_res.last | ||
| resp.raw["_counts"] = {} | ||
| resp.raw["_exit_code"] = 0 | ||
| for key, res in zip(funcs.keys(), batch_res.responses): | ||
| if res.ok: | ||
| resp.raw["_counts"][key.rstrip("_aps")] = res.raw.get("total") | ||
| resp.output = [*resp.output, *res.output] | ||
| else: | ||
| resp.raw["_exit_code"] = 1 | ||
| return resp |
@@ -24,2 +24,4 @@ #!/usr/bin/env python3 | ||
| self.response = response | ||
| self.exit_code = 0 if response.ok else 1 | ||
| if response.ok: | ||
@@ -30,2 +32,3 @@ wids_model = Wids(response.output) | ||
| self.caption = self.all_caption() | ||
| self.exit_code = response.raw.get("_exit_code") or self.exit_code | ||
| else: | ||
@@ -38,3 +41,3 @@ caption = common.get_time_range_caption(start, end, default="in past 3 hours.") | ||
| caption = "" | ||
| sections = ["rogues", "suspect", "interfering", "neighbor"] | ||
| sections = ["rogue", "suspect", "interfering", "neighbor"] | ||
| if self.response.raw.get("_counts"): | ||
@@ -284,2 +287,3 @@ for section in sections: | ||
| pager=pager, | ||
| exit_on_fail=False, | ||
| outfile=outfile, | ||
@@ -290,2 +294,3 @@ sort_by=sort_by, | ||
| ) | ||
| common.exit(code=resp.exit_code) | ||
@@ -292,0 +297,0 @@ |
@@ -309,2 +309,3 @@ from __future__ import annotations | ||
| self.cache_dir = self.dir / ".cache" | ||
| self.cache_dir.mkdir(parents=True, exist_ok=True) | ||
| self.default_cache_file = self.cache_dir / "db.json" | ||
@@ -311,0 +312,0 @@ self.sticky_workspace_file = self.cache_dir / "last_workspace" |
@@ -537,3 +537,5 @@ #!/usr/bin/env python3 | ||
| def last(self): | ||
| resp = [*self.failed, *self.passed][-1] | ||
| last_resp = [*self.failed, *self.passed][-1] | ||
| raw = self.raw | ||
| resp = Response(last_resp._response, raw=raw) | ||
| resp.rl = self.last_rl | ||
@@ -540,0 +542,0 @@ return resp |
+1
-1
| Metadata-Version: 2.4 | ||
| Name: centralcli | ||
| Version: 9.0.4.post1 | ||
| Version: 9.0.5 | ||
| Summary: A CLI for interacting with Aruba Central (Cloud Management Platform). Facilitates bulk imports, exports, reporting. A handy tool if you have devices managed by Aruba Central. | ||
@@ -5,0 +5,0 @@ License-Expression: MIT |
+2
-1
| [project] | ||
| name = "centralcli" | ||
| version = "9.0.4-1" | ||
| version = "9.0.5" | ||
| description = "A CLI for interacting with Aruba Central (Cloud Management Platform). Facilitates bulk imports, exports, reporting. A handy tool if you have devices managed by Aruba Central." | ||
@@ -147,2 +147,3 @@ license = "MIT" | ||
| "# pragma: no cover", | ||
| "@overload", | ||
| "if show_example:", | ||
@@ -149,0 +150,0 @@ "if not import_file:", |
Sorry, the diff of this file is too big to display
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
111354
04830869
-0.01%