ironic.conductor.utils module¶
- ironic.conductor.utils.abort_on_conductor_take_over(task)[source]¶
Set node’s state when a task was aborted due to conductor take over.
- Parameters:
task – a TaskManager instance.
- ironic.conductor.utils.add_secret_token(node, pregenerated=False)[source]¶
Adds a secret token to driver_internal_info for IPA verification.
- Parameters:
node – Node object
pregenerated – Boolean value, default False, which indicates if the token should be marked as “pregenerated” in order to facilitate virtual media booting where the token is embedded into the configuration.
- ironic.conductor.utils.agent_is_alive(node, timeout=None)[source]¶
Check that the agent is likely alive.
The method then checks for the last agent heartbeat, and if it occurred within the timeout set by [deploy]fast_track_timeout, then agent is presumed alive.
- Parameters:
node – A node object.
timeout – Heartbeat timeout, defaults to fast_track_timeout.
- ironic.conductor.utils.build_configdrive(node, configdrive)[source]¶
Build a configdrive from provided meta_data, network_data and user_data.
If uuid or name are not provided in the meta_data, they’re defaulted to the node’s uuid and name accordingly.
- Parameters:
node – an Ironic node object.
configdrive – A configdrive as a dict with keys
meta_data
,network_data
,user_data
andvendor_data
(all optional).
- Returns:
A gzipped and base64 encoded configdrive as a string.
- ironic.conductor.utils.cleaning_error_handler(task, logmsg, errmsg=None, traceback=False, tear_down_cleaning=True, set_fail_state=True, set_maintenance=None)[source]¶
Put a failed node in CLEANFAIL and maintenance (if needed).
- Parameters:
task – a TaskManager instance.
logmsg – Message to be logged.
errmsg – Message for the user. Optional, if not provided logmsg is used.
traceback – Whether to log a traceback. Defaults to False.
tear_down_cleaning – Whether to clean up the PXE and DHCP files after cleaning. Default to True.
set_fail_state – Whether to set node to failed state. Default to True.
set_maintenance – Whether to set maintenance mode. If None, maintenance mode will be set if and only if a clean step is being executed on a node.
- ironic.conductor.utils.cleanup_after_timeout(task)[source]¶
Cleanup deploy task after timeout.
- Parameters:
task – a TaskManager instance.
- ironic.conductor.utils.cleanup_cleanwait_timeout(task)[source]¶
Cleanup a cleaning task after timeout.
- Parameters:
task – a TaskManager instance.
- ironic.conductor.utils.cleanup_rescuewait_timeout(task)[source]¶
Cleanup rescue task after timeout.
- Parameters:
task – a TaskManager instance.
- ironic.conductor.utils.cleanup_servicewait_timeout(task)[source]¶
Cleanup a servicing task after timeout.
- Parameters:
task – a TaskManager instance.
- ironic.conductor.utils.deploying_error_handler(task, logmsg, errmsg=None, traceback=False, clean_up=True)[source]¶
Put a failed node in DEPLOYFAIL.
- Parameters:
task – the task
logmsg – message to be logged
errmsg – message for the user
traceback – Boolean; True to log a traceback
clean_up – Boolean; True to clean up
- ironic.conductor.utils.exclude_current_conductor(current_conductor, offline_conductors)[source]¶
Wrapper to exclude current conductor from offline_conductors
In some cases the current conductor may have failed to update the heartbeat timestamp due to failure or resource starvation. When this occurs the dbapi get_offline_conductors method will include the current conductor in its return value.
- Parameters:
current_conductor – id or hostname of the current conductor
offline_conductors – List of offline conductors.
- Returns:
List of offline conductors, excluding current conductor
- ironic.conductor.utils.fail_on_error(error_callback, msg, *error_args, **error_kwargs)[source]¶
A decorator for failing operation on failure.
- ironic.conductor.utils.fast_track_able(task)[source]¶
Checks if the operation can be a streamlined deployment sequence.
This is mainly focused on ensuring that we are able to quickly sequence through operations if we already have a ramdisk heartbeating through external means.
- Parameters:
task – Taskmanager object
- Returns:
True if [deploy]fast_track is set to True, no iSCSI boot configuration is present, and no last_error is present for the node indicating that there was a recent failure.
- ironic.conductor.utils.get_attached_vif(port)[source]¶
Get any attached vif ID for the port
- Parameters:
port – The port object upon which to check for a vif record.
- Returns:
Returns a tuple of the vif if found and the use of the vif in the form of a string, ‘tenant’, ‘cleaning’ ‘provisioning’, ‘rescuing’.
- Raises:
InvalidState exception upon finding a port with a transient state vif on the port.
- ironic.conductor.utils.get_configdrive_image(node)[source]¶
Get configdrive as an ISO image or a URL.
Converts the JSON representation into an image. URLs and raw contents are returned unchanged.
- Parameters:
node – an Ironic node object.
- Returns:
A gzipped and base64 encoded configdrive as a string.
- ironic.conductor.utils.get_token_project_from_request(ctx)[source]¶
Identifies the request originator project via keystone token details.
This method evaluates the
auth_token_info
field, which is used to pass information returned from keystone as a token’s verification. This information is based upon the actual, original requester context providedauth_token
.When a service, such as Nova proxies a request, the request provided auth token value is intended to be from the original user.
- Returns:
The project ID value.
- ironic.conductor.utils.hash_password(password='')[source]¶
Hashes a supplied password.
- Parameters:
password – password to be hashed
- ironic.conductor.utils.is_agent_token_pregenerated(node)[source]¶
Determines if the token was generated for out of band configuration.
Ironic supports the ability to provide configuration data to the agent through the a virtual floppy or as part of the virtual media image which is attached to the BMC.
This method helps us identify WHEN we did so as we don’t need to remove records of the token prior to rebooting the token. This is important as tokens provided through out of band means persist in the virtual media image, are loaded as part of the agent ramdisk, and do not require regeneration of the token upon the initial lookup, ultimately making the overall usage of virtual media and pregenerated tokens far more secure.
- Parameters:
node – Node Object
- Returns:
True if the token was pregenerated as indicated by the node’s driver_internal_info field. False in all other cases.
- ironic.conductor.utils.is_agent_token_present(node)[source]¶
Determines if an agent token is present upon a node.
- Parameters:
node – Node object
- Returns:
True if an agent_secret_token value is present in a node driver_internal_info field.
- ironic.conductor.utils.is_agent_token_valid(node, token)[source]¶
Validates if a supplied token is valid for the node.
- Parameters:
node – Node object
token – A token value to validate against the driver_internal_info field agent_secret_token.
- Returns:
True if the supplied token matches the token recorded in the supplied node object.
- ironic.conductor.utils.is_fast_track(task)[source]¶
Checks a fast track is available.
This method first ensures that the node and conductor configuration is valid to perform a fast track sequence meaning that we already have a ramdisk running through another means like discovery. If not valid, False is returned.
The method then checks for the last agent heartbeat, and if it occurred within the timeout set by [deploy]fast_track_timeout and the power state for the machine is POWER_ON, then fast track is permitted.
- Parameters:
task – Taskmanager object
- Returns:
True if the last heartbeat that was recorded was within the [deploy]fast_track_timeout setting.
- ironic.conductor.utils.make_salt()[source]¶
Generate a random salt with the indicator tag for password type.
- Returns:
a valid salt for use with crypt.crypt
- ironic.conductor.utils.node_cache_bios_settings(task)[source]¶
Do caching of bios settings if supported by driver
- ironic.conductor.utils.node_cache_boot_mode(task)[source]¶
Cache boot_mode and secure_boot state if supported by driver.
Cache current boot_mode and secure_boot in ironic’s node representation
- Parameters:
task – a TaskManager instance containing the node to check.
- ironic.conductor.utils.node_cache_firmware_components(task)[source]¶
Do caching of firmware components if supported by driver
- ironic.conductor.utils.node_change_boot_mode(task, target_boot_mode)[source]¶
Change boot mode to requested state for node
- Parameters:
task – a TaskManager instance containing the node to act on.
target_boot_mode – Any boot mode in
ironic.common.boot_modes
.
- ironic.conductor.utils.node_change_secure_boot(task, secure_boot_target)[source]¶
Change secure_boot state to requested state for node
- Parameters:
task – a TaskManager instance containing the node to act on.
secure_boot_target (boolean) – Target secure_boot state OneOf(True => on, False => off)
- ironic.conductor.utils.node_get_boot_mode(task)[source]¶
Read currently set boot mode from a node.
Reads the boot mode for a node. If boot mode can’t be discovered, None is returned.
- Parameters:
task – a TaskManager instance.
- Raises:
DriverOperationError or its derivative in case of driver runtime error.
- Raises:
UnsupportedDriverExtension if current driver does not have management interface or get_boot_mode() method is not supported.
- Returns:
Boot mode. One of
ironic.common.boot_mode
or None if boot mode can’t be discovered
- ironic.conductor.utils.node_history_record(node, conductor=None, event=None, event_type=None, user=None, error=False)[source]¶
Records a node history record
Adds an entry to the node history table with the appropriate fields populated to ensure consistent experience by also updating the node
last_error
field. Please note the event is only recorded if the[conductor]node_history_max_size
parameter is set to a value greater than0
.- Parameters:
node – A node object from a task object. Required.
conductor – The hostname of the conductor. If not specified this value is populated with the conductor FQDN.
event – The text to record to the node history table. If no value is supplied, the method silently returns to the caller.
event_type – The type activity where the event was encountered, either “provisioning”, “monitoring”, “cleaning”, or whatever text the a driver author wishes to supply based upon the activity. The purpose is to help guide an API consumer/operator to have a better contextual understanding of what was going on when the “event” occurred.
user – The user_id value which triggered the request, if available.
error – Boolean value, default false, to signify if the event is an error which should be recorded in the node
last_error
field.
- Returns:
None. No value is returned by this method.
- ironic.conductor.utils.node_power_action(task, new_state, timeout=None)[source]¶
Change power state or reset for a node.
Perform the requested power action if the transition is required.
- Parameters:
task – a TaskManager instance containing the node to act on.
new_state – Any power state from ironic.common.states.
timeout – timeout (in seconds) positive integer (> 0) for any power state.
None
indicates to use default timeout.
- Raises:
InvalidParameterValue when the wrong state is specified or the wrong driver info is specified.
- Raises:
StorageError when a failure occurs updating the node’s storage interface upon setting power on.
- Raises:
other exceptions by the node’s power driver if something wrong occurred during the power action.
- ironic.conductor.utils.node_set_boot_device(task, device, persistent=False)[source]¶
Set the boot device for a node.
If the node that the boot device change is being requested for is in ADOPTING state, the boot device will not be set as that change could potentially result in the future running state of an adopted node being modified erroneously.
- Parameters:
task – a TaskManager instance.
device – Boot device. Values are vendor-specific.
persistent – Whether to set next-boot, or make the change permanent. Default: False.
- Raises:
InvalidParameterValue if the validation of the ManagementInterface fails.
- ironic.conductor.utils.node_set_boot_mode(task, mode)[source]¶
Set the boot mode for a node.
Sets the boot mode for a node if the node’s driver interface contains a ‘management’ interface.
If the node that the boot mode change is being requested for is in ADOPTING state, the boot mode will not be set as that change could potentially result in the future running state of an adopted node being modified erroneously.
- Parameters:
task – a TaskManager instance.
mode – Boot mode. Values are one of
ironic.common.boot_modes
- Raises:
InvalidParameterValue if the validation of the ManagementInterface fails.
- Raises:
DriverOperationError or its derivative in case of driver runtime error.
- Raises:
UnsupportedDriverExtension if current driver does not have vendor interface or method is unsupported.
- ironic.conductor.utils.node_update_cache(task)[source]¶
Updates various cached information.
Includes vendor, boot mode, BIOS settings and firmware components.
- Parameters:
task – A TaskManager instance containing the node to act on.
- ironic.conductor.utils.node_wait_for_power_state(task, new_state, timeout=None)[source]¶
Wait for node to be in new power state.
- Parameters:
task – a TaskManager instance.
new_state – the desired new power state, one of the power states in
ironic.common.states
.timeout – number of seconds to wait before giving up. If not specified, uses the conductor.power_state_change_timeout config value.
- Raises:
PowerStateFailure if timed out
- ironic.conductor.utils.notify_conductor_resume_operation(task, operation)[source]¶
Notify the conductor to resume an operation.
- Parameters:
task – the task
operation – the operation, a string
- ironic.conductor.utils.power_on_node_if_needed(task)[source]¶
Powers on node if it is powered off and has a Smart NIC port
- Parameters:
task – A TaskManager object
- Returns:
the previous power state or None if no changes were made
- Raises:
exception.NetworkError if agent status didn’t match the required status after max retry attempts.
- ironic.conductor.utils.power_state_error_handler(e, node, power_state)[source]¶
Set the node’s power states if error occurs.
This hook gets called upon an exception being raised when spawning the worker thread to change the power state of a node.
- Parameters:
e – the exception object that was raised.
node – an Ironic node object.
power_state – the power state to set on the node.
- ironic.conductor.utils.power_state_for_network_configuration(task)[source]¶
Handle the power state for a node reconfiguration.
Powers the node on if and only if it has a Smart NIC port. Yields for the actual reconfiguration, then restores the power state.
- Parameters:
task – A TaskManager object.
- ironic.conductor.utils.provisioning_error_handler(e, node, provision_state, target_provision_state)[source]¶
Set the node’s provisioning states if error occurs.
This hook gets called upon an exception being raised when spawning the worker to do some provisioning to a node like deployment, tear down, or cleaning.
- Parameters:
e – the exception object that was raised.
node – an Ironic node object.
provision_state – the provision state to be set on the node.
target_provision_state – the target provision state to be set on the node.
- ironic.conductor.utils.remove_node_rescue_password(node, save=True)[source]¶
Helper to remove rescue password from a node.
Removes rescue password from node. It saves node by default. If node should not be saved, then caller needs to explicitly indicate it.
- Parameters:
node – an Ironic node object.
save – Boolean; True (default) to save the node; False otherwise.
- ironic.conductor.utils.rescuing_error_handler(task, msg, set_fail_state=True)[source]¶
Cleanup rescue task after timeout or failure.
- Parameters:
task – a TaskManager instance.
msg – a message to set into node’s last_error field
set_fail_state – a boolean flag to indicate if node needs to be transitioned to a failed state. By default node would be transitioned to a failed state.
- ironic.conductor.utils.restore_power_state_if_needed(task, power_state_to_restore)[source]¶
Change the node’s power state if power_state_to_restore is not None
- Parameters:
task – A TaskManager object
power_state_to_restore – power state
- ironic.conductor.utils.run_node_action(task, call, error_msg, success_msg=None, **kwargs)[source]¶
Run a node action and report any errors via last_error.
- Parameters:
task – A TaskManager instance containing the node to act on.
call – A callable object to invoke.
error_msg – A template for a failure message. Can use %(node)s, %(exc)s and any variables from kwargs.
success_msg – A template for a success message. Can use %(node)s and any variables from kwargs.
kwargs – Arguments to pass to the call.
- ironic.conductor.utils.servicing_error_handler(task, logmsg, errmsg=None, traceback=False, tear_down_service=True, set_fail_state=True, set_maintenance=None)[source]¶
Put a failed node in SERVICEFAIL and maintenance (if needed).
- Parameters:
task – a TaskManager instance.
logmsg – Message to be logged.
errmsg – Message for the user. Optional, if not provided logmsg is used.
traceback – Whether to log a traceback. Defaults to False.
tear_down_service – Whether to clean up the PXE and DHCP files after service. Default to True.
set_fail_state – Whether to set node to failed state. Default to True.
set_maintenance – Whether to set maintenance mode. If None, maintenance mode will be set if and only if a clean step is being executed on a node.
- ironic.conductor.utils.skip_automated_cleaning(node)[source]¶
Checks if node cleaning needs to be skipped for an specific node.
- Parameters:
node – the node to consider
- ironic.conductor.utils.spawn_cleaning_error_handler(e, node)[source]¶
Handle spawning error for node cleaning.
- ironic.conductor.utils.spawn_deploying_error_handler(e, node)[source]¶
Handle spawning error for node deploying.
- ironic.conductor.utils.spawn_rescue_error_handler(e, node)[source]¶
Handle spawning error for node rescue.
- ironic.conductor.utils.spawn_servicing_error_handler(e, node)[source]¶
Handle spawning error for node servicing.
- ironic.conductor.utils.store_agent_certificate(node, agent_verify_ca)[source]¶
Store certificate received from the agent and return its path.
- ironic.conductor.utils.update_image_type(context, node)[source]¶
Updates is_whole_disk_image and image_type based on the node data.
- Parameters:
context – Request context.
node – Node object.
- Returns:
True if any changes have been done, else False.
- ironic.conductor.utils.update_next_step_index(task, step_type)[source]¶
Calculate the next step index and update the node.
- Parameters:
task – A TaskManager object
step_type – The type of steps to process: ‘clean’ or ‘deploy’.
- Returns:
Index of the next step.
- ironic.conductor.utils.validate_instance_info_traits(node)[source]¶
Validate traits in instance_info.
All traits in instance_info must also exist as node traits.
- Parameters:
node – an Ironic node object.
- Raises:
InvalidParameterValue if the instance traits are badly formatted, or contain traits that are not set on the node.
- ironic.conductor.utils.validate_port_physnet(task, port_obj)[source]¶
Validate the consistency of physical networks of ports in a portgroup.
Validate the consistency of a port’s physical network with other ports in the same portgroup. All ports in a portgroup should have the same value (which may be None) for their physical_network field.
During creation or update of a port in a portgroup we apply the following validation criteria:
If the portgroup has existing ports with different physical networks, we raise PortgroupPhysnetInconsistent. This shouldn’t ever happen.
If the port has a physical network that is inconsistent with other ports in the portgroup, we raise exception.Conflict.
If a port’s physical network is None, this indicates that ironic’s VIF attachment mapping algorithm should operate in a legacy (physical network unaware) mode for this port or portgroup. This allows existing ironic nodes to continue to function after an upgrade to a release including physical network support.
- Parameters:
task – a TaskManager instance
port_obj – a port object to be validated.
- Raises:
Conflict if the port is a member of a portgroup which is on a different physical network.
- Raises:
PortgroupPhysnetInconsistent if the port’s portgroup has ports which are not all assigned the same physical network.
- ironic.conductor.utils.value_within_timeout(value, timeout)[source]¶
Checks if the time is within the previous timeout seconds from now.
- Parameters:
value – a datetime or string representing date and time or None.
timeout – timeout in seconds.
- ironic.conductor.utils.verifying_error_handler(task, logmsg, errmsg=None, traceback=False)[source]¶
Handle errors during verification steps
- Parameters:
task – the task
logmsg – message to be logged
errmsg – message for the user
traceback – Boolean; True to log a traceback
- ironic.conductor.utils.wipe_cleaning_internal_info(task)[source]¶
Remove temporary cleaning fields from driver_internal_info.
- ironic.conductor.utils.wipe_deploy_internal_info(task)[source]¶
Remove temporary deployment fields from driver_internal_info.
- ironic.conductor.utils.wipe_internal_info_on_power_off(node)[source]¶
Wipe information that should not survive reboot/power off.