redfish
Redfish module.
- exception spicerack.redfish.RedfishError[source]
Bases:
SpicerackError
General errors raised by this module.
- exception spicerack.redfish.RedfishTaskNotCompletedError[source]
Bases:
RedfishError
Raised when a Redfish task is not found on the server.
- class spicerack.redfish.ChassisResetPolicy(value)[source]
Bases:
Enum
Subset of available Chassis.Reset policies compatible with all supported vendors (at this moment only Dell).
- class spicerack.redfish.DellSCP(config: dict, target: spicerack.redfish.DellSCPTargetPolicy, *, allow_new_attributes: bool = False)[source]
Bases:
object
Represent a Dell System Configuration Profile configuration as returned by Redfish API.
Parse the Redfish API response.
- Parameters:
config (
dict
) -- the configuration as returned by Redfish API.target (
spicerack.redfish.DellSCPTargetPolicy
) -- describe which sections of the configuration are represented in the loaded configuration.allow_new_attributes (
bool
, default:False
) -- when set toTrue
it allows the creation of new attributes not already present in the provided configuration that otherwise would raise an exception. This is useful for example when changing the boot mode between Uefi and Bios that changes the keys present.
- empty_components() None [source]
Empty the current Components from the configuration, allowing to create a new configuration from scratch.
After calling this method is possible to set values for non-existing components that would otherwise raise an exception.
- Return type:
- set(component_name: str, attribute_name: str, attribute_value: str) bool [source]
Update the current configuration setting to the new value for the given key in the given component.
Notes
This updates only the instance representation of the instance. To push and apply the changes to the server see
spicerack.redfish.RedfishDell.scp_push()
. In order to add attributes not present the instance must have been created with allow_new_attributes set toTrue
or thespicerack.redfish.DellSCP.empty_component()
method called. This last one allows to automatically create any missing component while setting attributes.- Parameters:
- Return type:
- Returns:
True
if the value was added or changed,False
if it had already the correct value.- Raises:
spicerack.redfish.RedfishError -- if unable to find the given component or attribute and the creation of new
items is not allowed. --
- update(changes: dict[str, dict[str, str]]) bool [source]
Bulk update the current configuration with the set of changes provided.
Notes
This updates only the instance representation of the instance. To push and apply the changes to the server see
spicerack.redfish.RedfishDell.scp_push()
.- Parameters:
changes (
dict
[str
,dict
[str
,str
]]) -- a dictionary of changes to apply in the same format of the one returned byspicerack.redfish.DellSCP.components()
.- Return type:
- Returns:
True
if any of the values produced a change,False
if no change was made.- Raises:
spicerack.redfish.RedfishError -- if unable to apply all the changes.
- property components: dict[str, dict[str, str]]
Getter for the components present in the configuration in a simplified view.
The returned dictionary where all the keys are recursively sorted and has the following format:
{ '<component name>': { 'key1': 'value1', 'key2': 'value2', }, }
- property target: DellSCPTargetPolicy
Getter for the target that the current configuration represents.
- class spicerack.redfish.DellSCPPowerStatePolicy(value)[source]
Bases:
Enum
Available Dell SCP (Server Configuration Profiles) final power state after an operation policies.
- class spicerack.redfish.DellSCPRebootPolicy(value)[source]
Bases:
Enum
Available Dell SCP (Server Configuration Profiles) reboot policies.
- class spicerack.redfish.DellSCPTargetPolicy(value)[source]
Bases:
Enum
Available sections of the Dell SCP (Server Configuration Profiles) to target.
- ALL = 'ALL'
All settings.
- BIOS = 'BIOS'
Only BIOS settings.
- IDRAC = 'IDRAC'
Only iDRAC settings.
- NIC = 'NIC'
Only network interfaces settings.
- RAID = 'RAID'
Only RAID controller settings.
- class spicerack.redfish.Redfish(hostname: str, interface: ipaddress.IPv4Interface | ipaddress.IPv6Interface, username: str, password: str, *, dry_run: bool = True)[source]
Bases:
object
Manage Redfish operations on a specific device.
Initialize the instance.
- Parameters:
hostname (
str
) -- the hostname (not FQDN) the management console belongs to.interface (
typing.Union
[ipaddress.IPv4Interface
,ipaddress.IPv6Interface
]) -- the interface of the management console to connect to.username (
str
) -- the API username.password (
str
) -- the API password.dry_run (
bool
, default:True
) -- whether this is a DRY-RUN.
- change_user_password(username: str, password: str) None [source]
Change the password for the account with the given username.
If the username matches the one used by the instance to connect to the API, automatically updates the instance value so that the instance will keep working.
- Parameters:
- Raises:
spicerack.redfish.RedfishError -- if unable to find the user or update its password.
- Return type:
- chassis_reset(action: spicerack.redfish.ChassisResetPolicy) None [source]
Perform a reset of the chassis power status.
- Parameters:
action (
spicerack.redfish.ChassisResetPolicy
) -- the reset policy to use.- Raises:
spicerack.redfish.RedfishError -- if unable to perform the reset.
- Return type:
- check_connection() None [source]
Check the connection with the Redfish API.
- Raises:
spicerack.redfish.RedfishError -- if unable to connect to Redfish API.
- Return type:
- find_account(username: str) tuple[str, str] [source]
Find the account for the given username and return its URI.
- Parameters:
username (
str
) -- the username to search for.- Return type:
- Returns:
A 2-element tuple with the URI for the account and the ETag header value of the GET response.
- Raises:
spicerack.redfish.RedfishError -- if unable to find the account.
- force_http_boot_once() None [source]
Force the host to boot over UEFI HTTP at the next reboot.
- Raises:
spicerack.redfish.RedfishError -- if unable to perform the config change or not UEFI host.
- Return type:
- last_reboot() datetime.datetime [source]
Get the the last reboot time.
- Return type:
- static most_recent_member(members: list[dict], key: str) dict [source]
Return the most recent member of members result from dell api.
Members will be sorted on key and the most recent value is returned. The value of key is assumed to be an iso date.
- multipush_upload(file_handle: _io.BufferedReader, filename: str, reboot: bool = False) str [source]
Upload a file via redfish and return its job_id URI.
- Parameters:
file_handle (
io.BufferedReader
) -- On open file handle to the object to upload.filename (
str
) -- filename name to use for upload.reboot (
bool
, default:False
) -- if true immediately reboot the server.
- Return type:
- poll_task(uri: str) dict [source]
Poll a Redfish task until the results are available and return them.
- Parameters:
uri (
str
) -- the URI of the task, usually returned as Location header by the originating API call.- Raises:
spicerack.redfish.RedfishError -- if the response from the server is outside the expected values of HTTP
200 or 202. --
spicearck.redfish.RedfishTaskNotCompletedError -- if the task is not yet completed.
- Return type:
- request(method: str, uri: str, **kwargs: Any) requests.models.Response [source]
Perform a request against the target Redfish instance with the provided HTTP method and data.
See
spicerack.apiclient.APIClient.request()
for the arguments documentation.- Raises:
spicerack.apiclient.APIClientResponseError -- if the response status code is between 400 and 600.
spicerack.redfish.RedfishError -- if the given uri does not start with a slash (/) or if the request couldn't be performed.
- Return type:
- submit_files(files: dict) str [source]
Submit a upload file request that generates a task, return the URI of the submitted task.
- submit_task(uri: str, data: dict | None = None, method: str = 'post') str [source]
Submit a request that generates a task, return the URI of the submitted task.
- Parameters:
uri (
str
) -- the relative URI to request.data (
typing.Optional
[dict
], default:None
) -- the data to send in the request.method (
str
, default:'post'
) -- the HTTP method to use, if not the default one.
- Return type:
- upload_file(file_path: pathlib.Path, reboot: bool = False) str [source]
Upload a file to the firmware directory via redfish and return the job_id URI.
- Parameters:
file_path (
pathlib.Path
) -- The file path to upload.reboot (
bool
, default:False
) -- if true immediately reboot the server.
- Return type:
- wait_reboot_since(since: datetime.datetime) None [source]
Wait for idrac/redfish to become responsive.
- Parameters:
since (
datetime.datetime
) -- The datetime of the last reboot.- Return type:
- property bios_version: Version
Property to return a instance representing the Bios version.
- boot_mode_attribute = ''
The boot mode key in the Bios attributes.
- property firmware_version: Version
Property to return a version instance representing the firmware version.
- http_boot_target = ''
The value to the BootSourceOverrideTarget key for HTTP boot.
- property interface: IPv4Interface | IPv6Interface
Getter for the management interface address with netmask.
- log_service = ''
The name of the Log service.
- manager = ''
The name of the Out of Band manager.
- property multipushuri: str
Property representing the MultipartHttpPushUri of the idrac for uploading firmwares to it.
- property pushuri: str
Property representing the HttpPushUri of the idrac for uploading firmwares to it.
- reboot_message_id = ''
The message ID for a reboot event.
- system = ''
The name of the System manager.
- class spicerack.redfish.RedfishDell(hostname: str, interface: ipaddress.IPv4Interface | ipaddress.IPv6Interface, username: str, password: str, *, dry_run: bool = True)[source]
Bases:
Redfish
Dell specific Redfish support.
Override parent's constructor.
- scp_dump(target: spicerack.redfish.DellSCPTargetPolicy = DellSCPTargetPolicy.ALL, *, allow_new_attributes: bool = False) spicerack.redfish.DellSCP [source]
Dump and return the SCP (Server Configuration Profiles) configuration.
- Parameters:
target (
spicerack.redfish.DellSCPTargetPolicy
, default:<DellSCPTargetPolicy.ALL: 'ALL'>
) -- choose which sections to dump.allow_new_attributes (
bool
, default:False
) -- when set toTrue
it allows the creation of new attributes not already present in the retrieved configuration that otherwise would raise an exception. This is useful for example when changing the boot mode between Uefi and Bios that changes the keys present.
- Raises:
spicerack.redfish.RedfishError -- if the API call fail.
spicerack.redfish.RedfishTaskNotCompletedError -- if unable to fetch the dumped results.
- Return type:
- scp_push(scp: spicerack.redfish.DellSCP, *, reboot: spicerack.redfish.DellSCPRebootPolicy = DellSCPRebootPolicy.NO_REBOOT, power_state: spicerack.redfish.DellSCPPowerStatePolicy = DellSCPPowerStatePolicy.ON, preview: bool = True) dict [source]
Push the SCP (Server Configuration Profiles) configuration.
- Parameters:
scp (
spicerack.redfish.DellSCP
) -- the configuration that will pushed to the server.reboot (
spicerack.redfish.DellSCPRebootPolicy
, default:<DellSCPRebootPolicy.NO_REBOOT: 'NoReboot'>
) -- which reboot policy to use to apply the changes.power_state (
spicerack.redfish.DellSCPPowerStatePolicy
, default:<DellSCPPowerStatePolicy.ON: 'On'>
) -- which final power state policy to use to apply to the host after the changes have been applied.preview (
bool
, default:True
) -- ifTrue
perform a test push of the SCP data. This will tell if the file parses correctly and would not result in any writes. The comments will tell if the new configuration would not produce any changes. Forces the reboot parameter to bespicerack.redfish.DellSCPRebootPolicy.NO_REBOOT
.
- Return type:
- Returns:
The results of the push operation.
- Raises:
spicerack.redfish.RedfishError -- if the API call fail.
spicerack.redfish.RedfishTaskNotCompletedError -- if unable to fetch the dumped results.
- wait_reboot_since(since: datetime.datetime) None [source]
Wait for idrac/redfish to become responsive.
- Parameters:
since (
datetime.datetime
) -- the datetime of the last reboot.- Return type:
- boot_mode_attribute = 'BootMode'
The boot mode key in the Bios attributes.
- property generation: int
Property representing the generation of the idrac.
This is often 13 for idrac8 and 14 for idrac9. This property allows us to add workarounds for older idrac models
- http_boot_target = 'UefiHttp'
The value to the BootSourceOverrideTarget key for HTTP boot.
- log_service = 'Lclog'
The name of the Log service.
- manager = 'iDRAC.Embedded.1'
The name of the Out of Band manager.
- reboot_message_id = 'RAC0182'
The message ID for a reboot event.
-
scp_base_uri:
str
= '/redfish/v1/Managers/iDRAC.Embedded.1/Actions/Oem/EID_674_Manager' The Dell's SCP push base URI.
- system = 'System.Embedded.1'
The name of the System manager.
- class spicerack.redfish.RedfishSupermicro(hostname: str, interface: ipaddress.IPv4Interface | ipaddress.IPv6Interface, username: str, password: str, *, dry_run: bool = True)[source]
Bases:
Redfish
Redfish class for SuperMicro servers.
Initialize the instance.
- Parameters:
hostname (
str
) -- the hostname (not FQDN) the management console belongs to.interface (
typing.Union
[ipaddress.IPv4Interface
,ipaddress.IPv6Interface
]) -- the interface of the management console to connect to.username (
str
) -- the API username.password (
str
) -- the API password.dry_run (
bool
, default:True
) -- whether this is a DRY-RUN.
- add_account(username: str, password: str, role: spicerack.redfish.RedfishUserRoles = RedfishUserRoles.ADMINISTRATOR) None [source]
Create a new account with username and password.
- Parameters:
username (
str
) -- the username to create.password (
str
) -- the password to associate with the user.role (
spicerack.redfish.RedfishUserRoles
, default:<RedfishUserRoles.ADMINISTRATOR: 'Administrator'>
) -- aspicerack.redfish.RedfishUserRoles
value identifying the Redfish Role. Default is set to Administrator.
- Raises:
spicerack.redfish.RedfishError -- if unable to create the account.
- Return type:
- boot_mode_attribute = 'BootModeSelect'
The boot mode key in the Bios attributes.
- http_boot_target = 'Pxe'
The value to the BootSourceOverrideTarget key for HTTP boot.
- log_service = 'Log1'
The name of the Log service.
- manager = '1'
The name of the Out of Band manager.
- reboot_message_id = 'Event.1.0.SystemPowerAction'
The message ID for a reboot event.
- system = '1'
The name of the System manager.