style: ruff format and the lint rules of the driver standard
Mechanical: ruff format, and ruff check --fix with the rule set every NAPALM driver uses (E, F, I, UP, B at line length 100, Python 3.10). Mapping and Iterable come from collections.abc, imports are sorted. What ruff cannot fix comes in the next commit.
This commit is contained in:
1 parent
5b24675a12
commit
09029ca0a4
29 files changed
+985
-456
No files matched your search
@@ -2,7 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Mapping
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
from .common import boolean, ident, integer, link, link_list, location_label, present, status, text
|
||||
|
||||
@@ -39,8 +40,9 @@ def parse_memory(dimm: Mapping[str, Any]) -> dict[str, Any]:
|
||||
return {
|
||||
"id": text(dimm.get("Id")),
|
||||
"name": text(dimm.get("Name")),
|
||||
"location": (location_label(dimm) or text(dimm.get("DeviceLocator"))
|
||||
or text(dimm.get("Name"))),
|
||||
"location": (
|
||||
location_label(dimm) or text(dimm.get("DeviceLocator")) or text(dimm.get("Name"))
|
||||
),
|
||||
"capacity_mib": capacity,
|
||||
"memory_device_type": text(dimm.get("MemoryDeviceType")),
|
||||
"base_module_type": text(dimm.get("BaseModuleType")),
|
||||
@@ -62,7 +64,8 @@ def _controller(ctrl: Mapping[str, Any]) -> dict[str, Any]:
|
||||
"model": ident(ctrl.get("Model")),
|
||||
"serial_number": ident(ctrl.get("SerialNumber")),
|
||||
"firmware_version": text(ctrl.get("FirmwareVersion")),
|
||||
"speed_gbps": ctrl.get("SpeedGbps") if isinstance(ctrl.get("SpeedGbps"), (int, float))
|
||||
"speed_gbps": ctrl.get("SpeedGbps")
|
||||
if isinstance(ctrl.get("SpeedGbps"), (int, float))
|
||||
else None,
|
||||
"state": state,
|
||||
"health": health,
|
||||
@@ -83,7 +86,8 @@ def parse_storage(storage: Mapping[str, Any]) -> dict[str, Any]:
|
||||
"state": state,
|
||||
"health": health,
|
||||
"controllers": [_controller(c) for c in controllers if isinstance(c, Mapping)]
|
||||
if isinstance(controllers, list) else [],
|
||||
if isinstance(controllers, list)
|
||||
else [],
|
||||
"controllers_path": link(storage, "Controllers"),
|
||||
"drive_paths": link_list(storage, "Drives"),
|
||||
}
|
||||
@@ -117,8 +121,11 @@ def parse_simple_storage(storage: Mapping[str, Any]) -> dict[str, Any]:
|
||||
"""
|
||||
state, health = status(storage)
|
||||
devices = storage.get("Devices")
|
||||
drives = [parse_drive(dev) for dev in devices if isinstance(dev, Mapping)] \
|
||||
if isinstance(devices, list) else []
|
||||
drives = (
|
||||
[parse_drive(dev) for dev in devices if isinstance(dev, Mapping)]
|
||||
if isinstance(devices, list)
|
||||
else []
|
||||
)
|
||||
return {
|
||||
"id": text(storage.get("Id")),
|
||||
"name": text(storage.get("Name")),
|
||||
|
||||
Reference in new issue
Block a user