tools.bmc_vendor_tools module

Vendor BMC tools: Redfish/HTTPS, Dell racadm, Supermicro SMCIPMITool.

Security: all handlers require UNSANDBOXED_EXEC. No shell; argv lists only for subprocess tools. Redfish uses enum actions mapped to fixed paths.

Remote HPE iLO is accessed via Redfish (not hponcfg, which is local OS only).

async tools.bmc_vendor_tools.run_bmc_redfish(host, user, password, action, ctx=None, *, credential_profile='', system_id='', chassis_id='', manager_id='', reset_type='ForceRestart', boot_override_enabled='Once', boot_override_target='Pxe', verify_ssl=False, port=None, timeout=120.0)[source]

Perform one allowlisted Redfish operation over HTTPS against a BMC.

Backing implementation of the bmc_redfish tool, covering HPE iLO, Dell iDRAC (Redfish mode), Lenovo XCC, and many Supermicro/Cisco controllers. Dispatches on action — an enum drawn from _REDFISH_ACTIONS — to a fixed Redfish path (service root, systems/chassis/managers inventory, thermal and power readings, log services and entries, firmware/software inventory, virtual-media listing, boot properties, a boot-override PATCH, or a ComputerSystem.Reset POST). Member ids are auto-discovered when not supplied. Only enum actions reach fixed paths; arbitrary URLs are never issued.

When credential_profile is set it loads saved connection fields via tools._credential_profile_store.load_profile() (aliased _cred_load) and merges them with _cred_merge before validating the host, user, password, and port with _host_ok(), _user_ok(), _bad_pw(), and _port_ok(). Requires UNSANDBOXED_EXEC via tools.ipmi_tools._check_priv(). Builds the base URL with _bmc_base_url(), opens an SSRF-guarded client from tools._safe_http.safe_httpx_client() carrying httpx.BasicAuth, resolves ids through _resolve_system_id(), _resolve_chassis_id(), and _resolve_manager_id(), issues each request via _redfish_json(), and bounds every response with _truncate_payload(). Side effects: outbound HTTPS to the BMC management network, and (for boot_override/system_reset) a state change on the target server. Errors are returned as JSON, not raised.

Called by the tool_loader dispatcher as the registered handler for the bmc_redfish entry in TOOLS (and directly in tests/test_credential_profile_merges.py).

Parameters:
  • host (str) – BMC hostname or IP, optionally with an http(s):// scheme.

  • user (str) – BMC username for BasicAuth.

  • password (str) – BMC password for BasicAuth.

  • action (str) – Redfish operation to perform; must be in _REDFISH_ACTIONS.

  • ctx (Any) – Tool context providing redis/user_id for the privilege and credential lookups; required.

  • credential_profile (str) – Optional saved profile name supplying host, user, password, and TLS options.

  • system_id (str) – Redfish Systems member id; empty auto-detects the first.

  • chassis_id (str) – Chassis member id; empty auto-detects the first.

  • manager_id (str) – Managers member id; empty auto-detects the first.

  • reset_type (str) – ResetType for system_reset (must be in _RESET_TYPES; default "ForceRestart").

  • boot_override_enabled (str) – BootSourceOverrideEnabled for boot_override (default "Once").

  • boot_override_target (str) – BootSourceOverrideTarget for boot_override (default "Pxe").

  • verify_ssl (bool) – Whether to verify the BMC’s TLS certificate (default False for self-signed BMC certs).

  • port (int | None) – Optional HTTPS port when not 443 and not embedded in host.

  • timeout (float) – HTTP timeout in seconds (default 120).

Returns:

A JSON object carrying success, http_status, action, the resolved id(s), and the truncated data (or per-action payload keys), or {"success": False, "error": ...} on a validation, auth, or request failure.

Return type:

str

async tools.bmc_vendor_tools.run_idrac_racadm(host, user, password, action, ctx=None, *, credential_profile='', timeout=180.0)[source]

Run one allowlisted Dell iDRAC racadm action against a remote BMC.

Backing implementation of the idrac_racadm tool. It invokes the local racadm binary in remote mode (racadm -r host, -u user, -p password, then the action tail) with a fixed, pre-vetted subcommand tail chosen from _RACADM_ACTIONS — read and power actions plus storage get views. Because only constant argv tails (resolved by _racadm_tail()) are appended and no shell is used, no user-controlled token can reach the subcommand; firmware flash and destructive RAID actions are not exposed.

When credential_profile is set it loads and merges saved fields via _cred_load/_cred_merge. Requires UNSANDBOXED_EXEC via tools.ipmi_tools._check_priv(); checks the binary with _racadm_available() and validates host/user/password with _host_ok() and _user_ok(); then runs the argv through _run_subprocess() (no shell, bounded output, timeout-killed). Side effect: spawns the racadm process, which reaches out to the iDRAC over the network (and may change power state for serveraction_*). Errors are returned as JSON, not raised.

Called by the tool_loader dispatcher as the registered handler for the idrac_racadm entry in TOOLS; no internal callers in this module.

Parameters:
  • host (str) – iDRAC IP or hostname.

  • user (str) – iDRAC username.

  • password (str) – iDRAC password.

  • action (str) – Action name; must be in _RACADM_ACTIONS and map to a tail.

  • ctx (Any) – Tool context providing redis/user_id; required.

  • credential_profile (str) – Optional saved profile supplying host, user, password, and timeout.

  • timeout (float) – Subprocess wall-clock timeout in seconds (default 180).

Returns:

A JSON object with success (true on exit code 0), action, exit_code, and the captured stdout/stderr, or {"success": False, "error": ...} on a missing binary, validation, or auth failure.

Return type:

str

async tools.bmc_vendor_tools.run_smc_supermicro(host, user, password, action, ctx=None, *, credential_profile='', timeout=180.0)[source]

Run one allowlisted Supermicro SMCIPMITool action against a BMC.

Backing implementation of the smc_supermicro tool. It invokes the Supermicro CLI in remote IP mode (the resolved binary followed by host, user, password, then the ipmi subcommand tokens) with a fixed subcommand tail chosen from _SMC_ACTIONS — power, sensor, FRU, LAN, and SEL reads. Only the constant tails resolved by _smc_tail() are appended and no shell is used, so user input cannot reach the subcommand.

When credential_profile is set it loads and merges saved fields via _cred_load/_cred_merge. Requires UNSANDBOXED_EXEC via tools.ipmi_tools._check_priv(); locates the binary with _smc_bin() and validates host/user/password with _host_ok() and _user_ok(); then runs the argv through _run_subprocess() (no shell, bounded output, timeout-killed). Side effect: spawns the SMCIPMITool process, which contacts the BMC over the network (and may change power state for the ipmi_power_* actions). Errors are returned as JSON, not raised.

Called by the tool_loader dispatcher as the registered handler for the smc_supermicro entry in TOOLS; no internal callers in this module.

Parameters:
  • host (str) – BMC IP address.

  • user (str) – BMC username.

  • password (str) – BMC password.

  • action (str) – Action name; must be in _SMC_ACTIONS and map to a tail.

  • ctx (Any) – Tool context providing redis/user_id; required.

  • credential_profile (str) – Optional saved profile supplying host, user, password, and timeout.

  • timeout (float) – Subprocess wall-clock timeout in seconds (default 180).

Returns:

A JSON object with success (true on exit code 0), action, exit_code, and the captured stdout/stderr, or {"success": False, "error": ...} on a missing binary, validation, or auth failure.

Return type:

str

async tools.bmc_vendor_tools.bmc_redfish_save_credentials(host, user, password, profile='default', ctx=None, *, verify_ssl=False, port=None, timeout=120.0)[source]

Encrypt and persist a reusable Redfish BMC credential profile.

Bundles the connection fields (host, user, password, verify_ssl, port, timeout) so a later run_bmc_redfish() call can load them by name via credential_profile instead of re-supplying secrets each time.

Requires the UNSANDBOXED_EXEC privilege, enforced via tools.ipmi_tools._check_priv(). Delegates storage to tools._credential_profile_store.save_profile() (aliased _cred_save) under prefix bmc_redfish, which encrypts the JSON with the per-user key and writes it to the user’s Redis hash stargazer:bmc_redfish_credentials:{user_id} (field = profile name). This is a tool handler registered in TOOLS and is invoked by the tool dispatcher rather than by other functions in this module.

Parameters:
  • host (str) – BMC hostname or IP (whitespace-stripped before saving).

  • user (str) – BMC username to store.

  • password (str) – BMC password to store (encrypted at rest).

  • profile (str) – Profile name to save under; defaults to "default".

  • ctx (Any) – Tool context providing redis and user_id; required.

  • verify_ssl (bool) – Whether saved sessions should verify TLS certs.

  • port (int | None) – Optional HTTPS port to remember.

  • timeout (float) – HTTP timeout in seconds to remember.

Returns:

A JSON result string {"success": ...} from the credential store (or an error envelope when ctx is missing or the privilege check fails).

Return type:

str

async tools.bmc_vendor_tools.bmc_redfish_list_credentials(ctx=None)[source]

List the saved Redfish BMC credential profile names for the user.

Returns only the profile names, never the decrypted secrets. Requires UNSANDBOXED_EXEC via _check_priv(), then delegates to tools._credential_profile_store.list_profile_names() (_cred_list), which reads the keys of the Redis hash stargazer:bmc_redfish_credentials:{user_id}. Registered in TOOLS and called by the tool dispatcher.

Parameters:

ctx (Any) – Tool context providing redis and user_id; required.

Returns:

JSON string {"success": True, "profiles": [...], "count": N} on success, or an error envelope when ctx is missing or unprivileged.

Return type:

str

async tools.bmc_vendor_tools.bmc_redfish_delete_credentials(profile='default', ctx=None)[source]

Delete one saved Redfish BMC credential profile for the user.

Requires UNSANDBOXED_EXEC via _check_priv(), then delegates to tools._credential_profile_store.delete_profile() (_cred_delete), which removes the profile field from the Redis hash stargazer:bmc_redfish_credentials:{user_id}. Registered in TOOLS and invoked by the tool dispatcher.

Parameters:
  • profile (str) – Name of the profile to delete; defaults to "default".

  • ctx (Any) – Tool context providing redis and user_id; required.

Returns:

JSON result string from the credential store, or an error envelope when ctx is missing or the privilege check fails.

Return type:

str

async tools.bmc_vendor_tools.idrac_racadm_save_credentials(host, user, password, profile='default', ctx=None, *, timeout=180.0)[source]

Encrypt and persist a reusable Dell iDRAC racadm credential profile.

Stores host, user, password, and subprocess timeout so a later run_idrac_racadm() call can load them by credential_profile name. Requires UNSANDBOXED_EXEC via _check_priv(), then delegates to tools._credential_profile_store.save_profile() (_cred_save) under prefix idrac_racadm, encrypting the JSON to the user’s Redis hash stargazer:idrac_racadm_credentials:{user_id}. Registered in TOOLS and invoked by the tool dispatcher.

Parameters:
  • host (str) – iDRAC IP or hostname (whitespace-stripped before saving).

  • user (str) – iDRAC username.

  • password (str) – iDRAC password (encrypted at rest).

  • profile (str) – Profile name to save under; defaults to "default".

  • ctx (Any) – Tool context providing redis and user_id; required.

  • timeout (float) – Subprocess timeout in seconds to remember.

Returns:

JSON result string from the credential store, or an error envelope when ctx is missing or unprivileged.

Return type:

str

async tools.bmc_vendor_tools.idrac_racadm_list_credentials(ctx=None)[source]

List the saved iDRAC racadm credential profile names for the user.

Returns names only, no secrets. Requires UNSANDBOXED_EXEC via _check_priv(), then delegates to tools._credential_profile_store.list_profile_names() (_cred_list) reading the Redis hash stargazer:idrac_racadm_credentials:{user_id}. Registered in TOOLS and invoked by the tool dispatcher.

Parameters:

ctx (Any) – Tool context providing redis and user_id; required.

Returns:

JSON {"success": True, "profiles": [...], "count": N} on success, else an error envelope.

Return type:

str

async tools.bmc_vendor_tools.idrac_racadm_delete_credentials(profile='default', ctx=None)[source]

Delete one saved iDRAC racadm credential profile for the user.

Requires UNSANDBOXED_EXEC via _check_priv(), then delegates to tools._credential_profile_store.delete_profile() (_cred_delete), removing the profile field from the Redis hash stargazer:idrac_racadm_credentials:{user_id}. Registered in TOOLS and invoked by the tool dispatcher.

Parameters:
  • profile (str) – Name of the profile to delete; defaults to "default".

  • ctx (Any) – Tool context providing redis and user_id; required.

Returns:

JSON result string from the credential store, or an error envelope when ctx is missing or unprivileged.

Return type:

str

async tools.bmc_vendor_tools.smc_supermicro_save_credentials(host, user, password, profile='default', ctx=None, *, timeout=180.0)[source]

Encrypt and persist a reusable Supermicro SMCIPMITool credential profile.

Stores host, user, password, and subprocess timeout so a later run_smc_supermicro() call can load them by credential_profile name. Requires UNSANDBOXED_EXEC via _check_priv(), then delegates to tools._credential_profile_store.save_profile() (_cred_save) under prefix smc_supermicro, encrypting the JSON to the user’s Redis hash stargazer:smc_supermicro_credentials:{user_id}. Registered in TOOLS and invoked by the tool dispatcher.

Parameters:
  • host (str) – BMC IP address (whitespace-stripped before saving).

  • user (str) – BMC username.

  • password (str) – BMC password (encrypted at rest).

  • profile (str) – Profile name to save under; defaults to "default".

  • ctx (Any) – Tool context providing redis and user_id; required.

  • timeout (float) – Subprocess timeout in seconds to remember.

Returns:

JSON result string from the credential store, or an error envelope when ctx is missing or unprivileged.

Return type:

str

async tools.bmc_vendor_tools.smc_supermicro_list_credentials(ctx=None)[source]

List the saved Supermicro SMCIPMITool credential profile names.

Returns names only, no secrets. Requires UNSANDBOXED_EXEC via _check_priv(), then delegates to tools._credential_profile_store.list_profile_names() (_cred_list) reading the Redis hash stargazer:smc_supermicro_credentials:{user_id}. Registered in TOOLS and invoked by the tool dispatcher.

Parameters:

ctx (Any) – Tool context providing redis and user_id; required.

Returns:

JSON {"success": True, "profiles": [...], "count": N} on success, else an error envelope.

Return type:

str

async tools.bmc_vendor_tools.smc_supermicro_delete_credentials(profile='default', ctx=None)[source]

Delete one saved Supermicro SMCIPMITool credential profile.

Requires UNSANDBOXED_EXEC via _check_priv(), then delegates to tools._credential_profile_store.delete_profile() (_cred_delete), removing the profile field from the Redis hash stargazer:smc_supermicro_credentials:{user_id}. Registered in TOOLS and invoked by the tool dispatcher.

Parameters:
  • profile (str) – Name of the profile to delete; defaults to "default".

  • ctx (Any) – Tool context providing redis and user_id; required.

Returns:

JSON result string from the credential store, or an error envelope when ctx is missing or unprivileged.

Return type:

str