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: DellSCPTargetPolicy, *, allow_new_attributes: bool = False)[source]¶
Bases:
object
Reprenset 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) -- when set to
True
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.
- 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
- Returns
True
if the value was added or changed,False
if it had already the correct value.- Return type
- 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) -- a dictionary of changes to apply in the same format of the one returned by
spicerack.redfish.DellSCP.components()
.- Returns
True
if any of the values produced a change,False
if no change was made.- Return type
- 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: Union[IPv4Interface, 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 (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, optional) -- 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.
- chassis_reset(action: 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.
- check_connection() None [source]¶
Check the connection with the Redfish API.
- Raises
spicerack.redfish.RedfishError -- if unable to connect to Redfish API.
- 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.
- Returns
a 2-element tuple with the URI for the account and the ETag header value of the GET response.
- Return type
- Raises
spicerack.redfish.RedfishError -- if unable to find the account.
- get_power_state() str [source]¶
Return the current power state of the device.
- Returns
the power state.
- Return type
- last_reboot() datetime [source]¶
Ask redfish for the last reboot time.
- Returns
the datetime of the last reboot event
- Return type
datetime
- 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.
- Parameters
members -- A list of dicts returned from the dell api.
key -- The key to search on.
- Returns
the most recent member
- Return type
- poll_task(uri: str) Dict [source]¶
Poll a Redfish task until the results are available.
- Parameters
uri (str) -- the URI of the task, usually returned as Location header by the originating API call.
- Returns
the task results.
- Return type
- Raises
RedfishError -- if the response from the server is outside the expected values of HTTP 200 or 202.
RedfishTaskNotCompletedError -- if the task is not yet completed.
- request(method: str, uri: str, **kwargs: Any) Response [source]¶
Perform a request against the target Redfish instance with the provided HTTP method and data.
- Parameters
- Returns
the response.
- Return type
- Raises
RedfishError -- if the response status code is between 400 and 600 or if the given uri does not start with
a slash (/) or if the request couldn't be performed. --
- submit_task(uri: str, data: Optional[Dict] = None, method: str = 'post') str [source]¶
Submit a request that generates a task, return the URI of the submitted task.
- Parameters
- Returns
the URI of the task ID to poll the results.
- Return type
- Raises
spicerack.redfish.RedfishError -- if the response status code is not 202 or there is no Location header.
- wait_reboot_since(since: datetime) None [source]¶
Wait for idrac/redfish to become responsive.
- Parameters
since -- The datetime of the last reboot
- 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
- Returns
representing the generation
- Return type
- property interface: Union[IPv4Interface, IPv6Interface]¶
Getter for the management interface address with netmask.
- Returns
ipaddress.IPv4Interface, ipaddress.IPv6Interface: the interface.
- class spicerack.redfish.RedfishDell(hostname: str, interface: Union[IPv4Interface, IPv6Interface], username: str, password: str, *, dry_run: bool = True)[source]¶
Bases:
Redfish
Dell specific Redfish support.
Initialize the instance.
- Parameters
hostname (str) -- the hostname (not FQDN) the management console belongs to.
interface (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, optional) -- whether this is a DRY-RUN.
- scp_dump(target: DellSCPTargetPolicy = DellSCPTargetPolicy.ALL, *, allow_new_attributes: bool = False) DellSCP [source]¶
Dump and return the SCP (Server Configuration Profiles) configuration.
- Parameters
target (spicerack.redfish.DellSCPTargetPolicy, optional) -- choose which sections to dump.
allow_new_attributes (bool) -- when set to
True
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.
- Returns
the server's configuration.
- Return type
- Raises
spicerack.redfish.RedfishError -- if the API call fail.
spicerack.redfish.RedfishTaskNotCompletedError -- if unable to fetch the dumped results.
- scp_push(scp: DellSCP, *, reboot: DellSCPRebootPolicy = DellSCPRebootPolicy.NO_REBOOT, power_state: 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, optional) -- which reboot policy to use to apply the changes.
power_state (spicerack.redfish.DellSCPPowerStatePolicy, optional) -- which final power state policy to use to apply to the host after the changes have been applied.
preview (bool, optional) -- if
True
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
.
- Returns
the results of the push operation.
- Return type
- Raises
spicerack.redfish.RedfishError -- if the API call fail.
spicerack.redfish.RedfishTaskNotCompletedError -- if unable to fetch the dumped results.