Files
napalm-redfish/napalm_redfish/parsers/accounts.py
T
Christian Manivong cab1c84cba Add parsers for the Redfish resources in redfish-map.md
Pure functions for ServiceRoot, ComputerSystem (facts, power state, reset action and ActionInfo), Processors, Memory, Storage/Drives/SimpleStorage, Chassis Thermal and Power as well as ThermalSubsystem/PowerSubsystem/Sensors (with environment_sources to pick whichever exists), Manager, EthernetInterfaces, ManagerNetworkProtocol, accounts, firmware inventory and log services/entries.
2026-10-12 23:42:14 +00:00

41 lines
1.4 KiB
Python

"""AccountService accounts (``AccountService/Accounts/*``)."""
from __future__ import annotations
from typing import Any, Iterable, Mapping
from .common import boolean, text
# Privilege level for NAPALM's get_users, from the Redfish standard roles.
ROLE_LEVELS = {"Administrator": 15, "Operator": 5, "ReadOnly": 1}
def parse_account(account: Mapping[str, Any]) -> dict[str, Any] | None:
"""One account; ``None`` for an unused slot (no UserName), as iDRAC and Supermicro list."""
username = text(account.get("UserName"))
if username is None:
return None
types = account.get("AccountTypes")
return {
"id": text(account.get("Id")),
"username": username,
"role_id": text(account.get("RoleId")),
"enabled": boolean(account.get("Enabled")),
"locked": boolean(account.get("Locked")),
"account_types": [str(t) for t in types] if isinstance(types, list) else [],
}
def to_napalm_users(accounts: Iterable[Mapping[str, Any] | None]) -> dict[str, dict[str, Any]]:
"""NAPALM ``get_users`` from parsed accounts. Unknown (OEM) roles get level 0."""
users = {}
for acc in accounts:
if not acc:
continue
users[acc["username"]] = {
"level": ROLE_LEVELS.get(acc.get("role_id") or "", 0),
"password": "",
"sshkeys": [],
}
return users