The heat.engine.resource Module

exception heat.engine.resource.NoActionRequired[source]

Bases: exceptions.Exception

Exception raised when a signal is ignored.

Resource subclasses should raise this exception from handle_signal() to suppress recording of an event corresponding to the signal.

exception heat.engine.resource.PollDelay(period)[source]

Bases: exceptions.Exception

Exception to delay polling of the resource.

This exception may be raised by a Resource subclass’s check_*_complete() methods to indicate that it need not be polled again immediately. If this exception is raised, the check_*_complete() method will not be called again until the nth time that the resource becomes eligible for polling. A PollDelay period of 1 is equivalent to returning False.

class heat.engine.resource.Resource(name, definition, stack)[source]

Bases: object


For the intrinsic function Fn::Base64.

Parameters:data – the input data.
Returns:the Base64 representation of the input data.
FnGetAtt(key, *path)[source]

For the intrinsic function Fn::GetAtt.

  • key – the attribute key.
  • path – a list of path components to select from the attribute.

the attribute value.


For the intrinsic function get_attr which returns all attributes.

Returns:dict of all resource’s attributes exclude “show” attribute.

For the intrinsic function Ref.

Results:the id or name of the resource.
SHOW = 'show'
action_handler_task(action, args=None, action_prefix=None)[source]

A task to call the Resource subclass’s handler methods for action.

Calls the handle_<ACTION>() method for the given action and then calls the check_<ACTION>_complete() method with the result in a loop until it returns True. If the methods are not provided, the call is omitted.

Any args provided are passed to the handler.

If a prefix is supplied, the handler method handle_<PREFIX>_<ACTION>() is called instead.


Add implicit dependencies specific to the resource type.

Some resource types may have implicit dependencies on other resources in the same stack that are not linked by a property value (that would be set using get_resource or get_attr for example, thus creating an explicit dependency). Such dependencies are opaque to the user and should be avoided wherever possible, however in some circumstances they are required due to magic in the underlying API.

The deps parameter is a Dependencies object to which dependency pairs may be added.


Add all dependencies explicitly specified in the template.

The deps parameter is a Dependencies object to which dependency pairs are added.


Adopt the existing resource.

Resource subclasses can provide a handle_adopt() method to customise adopt.

attributes_schema = {}
base_attributes_schema = {'show': <heat.engine.attributes.Schema object at 0x7fbb55d72a90>}
static build_template_dict(res_name, res_type, tmpl_type, params, props, outputs, description)[source]

Checks that the physical resource is in its expected state.

Gets the current status of the physical resource and updates the database accordingly. If check is not supported by the resource, default action is to fail and revert the resource’s status to its original state with the added message that check was not performed.

classmethod check_is_substituted(new_res_type)[source]
client(name=None, version=None)[source]
create(*args, **kwargs)[source]

Create the resource.

Subclasses should provide a handle_create() method to customise creation.

create_convergence(template_id, resource_data, engine_id, timeout, progress_callback=None)[source]

Creates the resource by invoking the scheduler TaskRunner.


Return the resource data for this resource.

Use methods data_set and data_delete to modify the resource data for this resource.

Returns:a dict representing the resource data for this resource.

Remove a key from the resource data.

Returns:True if the key existed to delete.
data_set(key, value, redact=False)[source]

Set a key in the resource data.

default_client_name = None
delete(*args, **kwargs)[source]

A task to delete the resource.

Subclasses should provide a handle_delete() method to customise deletion.

delete_convergence(template_id, input_data, engine_id, timeout, progress_callback=None)[source]

Destroys the resource if it doesn’t belong to given template.

The given template is suppose to be the current template being provisioned.

Also, since this resource is visited as part of clean-up phase, the needed_by should be updated. If this resource was replaced by more recent resource, then delete this and update the replacement resource’s needed_by and replaces fields.

delete_snapshot(*args, **kwargs)[source]
destroy(*args, **kwargs)[source]

A task to delete the resource and remove it from the database.

entity = None
get_attribute(key, *path)[source]

Default implementation for function get_attr and Fn::GetAtt.

This may be overridden by resource plugins to add extra logic specific to the resource implementation.


Default implementation; can be overridden by resources.

Get resource data and handle it with exceptions.


Default implementation; should be overridden by resources.

Parameters:resource_properties – resource’s object of Properties class.
Returns:dict of resource’s real state of properties.

Default implementation for function get_resource.

This may be overridden by resource plugins to add extra logic specific to the resource implementation.


Default implementation; should be overridden by resources.


Default implementation; should be overridden by resources.

Now we override this method to reset the metadata for scale-policy and scale-group resources, because their metadata might hang in a wrong state (‘scaling_in_progress’ is always True) if engine restarts while scaling.

handle_update(json_snippet, tmpl_diff, prop_diff)[source]

Check if resource is mapped to resource_type or is “resource_type”.

Check to see if this resource is either mapped to resource_type or is a “resource_type”.


Return True if the resource has an existing nested stack.

For most resource types, this will always return False. StackResource subclasses return True when appropriate. Resource subclasses that may return True must also provide a nested_identifier() method to return the identifier of the nested stack, and a nested() method to return a Stack object for the nested stack.


Return an identifier for this resource.

classmethod is_service_available(context)[source]
classmethod load(context, resource_id, is_update, data)[source]
lock(*args, **kwds)[source]
metadata_set(*args, **kw)[source]

Write new metadata to the database.

The caller may optionally provide a merge_metadata() function, which takes two arguments - the metadata passed to metadata_set() and the current metadata of the resource - and returns the merged metadata to write. If merge_metadata is not provided, the metadata passed to metadata_set() is written verbatim, overwriting any existing metadata.

If a race condition is detected, the write will be retried with the new result of merge_metadata() (if it is supplied) or the verbatim data (if it is not).


No-op for resources which don’t explicitly override this method.


Mandatory replace based on certain properties.

needs_replace_with_prop_diff(changed_properties_set, after_props, before_props)[source]

Needs replace based on prop_diff.


Needs replace based on tmpl_diff.

no_signal_actions = ('SUSPEND', 'DELETE')
parse_live_resource_data(resource_properties, resource_data)[source]

Default implementation; can be overridden by resources.

Parse resource data for using it in updating properties with live state. :param resource_properties: properties of stored resource plugin. :param resource_data: data from current live state of a resource.

parsed_template(section=None, default=None)[source]

Return the parsed template data for the resource.

May be limited to only one section of the data, in which case a default value may also be supplied.

static pause()[source]
physical_resource_name_limit = 255

Prepare resource for replacing.

Some resources requires additional actions before replace them. If resource need to be changed before replacing, this method should be implemented in resource class.


Default implementation of Resource.preview.

This method should be overridden by child classes for specific behavior.

preview_update(after, before, after_props, before_props, prev_resource, check_init_complete=False)[source]

Simulates update without actually updating the resource.

Raises UpdateReplace, if replacement is required or returns True, if in-place update is required.

static reduce_physical_resource_name(name, limit)[source]

Reduce length of physical resource name to a limit.

The reduced name will consist of the following:

  • the first 2 characters of the name
  • a hyphen
  • the end of the name, truncated on the left to bring the name length within the limit
  • name – The name to reduce the length of
  • limit – The max length limit

A name whose length is less than or equal to the limit


Default implementation; should be overridden by resources.

Should be overridden by resources that would require schema refresh during update, ex. TemplateResource.

Definition:Resource Definition
reparse(translate=True, client_resolve=True)[source]

Reparse the resource properties.

Optional translate flag for property translation and client_resolve flag for resolving properties by doing client lookup.


List of resources that require this one as a dependency.

Returns a list of names of resources that depend on this resource directly.

required_service_extension = None
requires_deferred_auth = False
classmethod resource_to_template(resource_type, template_type='cfn')[source]

Generate a provider template that mirrors the resource.

  • resource_type – The resource type to be displayed in the template
  • template_type – the template type to generate, cfn or hot.

A template where the resource’s properties_schema is mapped as parameters, and the resource’s attributes_schema is mapped as outputs


Restore resource after rollback.

Some resources requires additional actions after rollback. If resource need to be changed during rollback, this method should be implemented in resource class.


Return a task to resume the resource.

Subclasses should provide a handle_resume() method to implement resume.


Return a client for making engine RPC calls.

classmethod set_needed_by(db_rsrc, needed_by, expected_engine_id=None)[source]
classmethod set_requires(db_rsrc, requires)[source]
signal(details=None, need_check=True)[source]

Signal the resource.

Returns True if the metadata for all resources in the stack needs to be regenerated as a result of the signal, False if it should not be.

Subclasses should provide a handle_signal() method to implement the signal. The base-class raise an exception if no handler is implemented.

signal_needs_metadata_updates = True

Snapshot the resource and return the created data, if any.


Returns state, tuple of action, status.


Reset state to (INIT, COMPLETE).

state_set(action, status, reason='state changed')[source]
strict_dependency = True
support_status = < object at 0x7fbb55d72ad0>

Return a task to suspend the resource.

Subclasses should provide a handle_suspend() method to implement suspend.

translate_properties(properties, client_resolve=True)[source]

Translates properties with resource specific rules.

The properties parameter is a properties object and the optional client_resolve flag is to specify whether to do ‘RESOLVE’ translation with client lookup.


Return specified rules for resource.

update(*args, **kwargs)[source]

Return a task to update the resource.

Subclasses should provide a handle_update() method to customise update, the base-class handle_update will fail by default.

update_allowed_properties = ()
update_convergence(template_id, resource_data, engine_id, timeout, new_stack, progress_callback=None)[source]

Update the resource synchronously.

Persist the resource’s current_template_id to template_id and resource’s requires to list of the required resource ids from the given resource_data and existing resource’s requires, then updates the resource by invoking the scheduler TaskRunner.

update_policy_schema = {}
update_template_diff(after, before)[source]

Returns the difference between the before and after json snippets.

If something has been removed in after which exists in before we set it to None.

update_template_diff_properties(after_props, before_props)[source]

Return changed Properties between the before and after properties.

If any property having immutable as True is updated, raises NotSupported error. If any properties have changed which are not in update_allowed_properties, raises UpdateReplace.


Validate the resource.

This may be overridden by resource plugins to add extra validation logic specific to the resource implementation.

classmethod validate_deletion_policy(policy)[source]

Validate structural/syntax aspects of the resource definition.

Resource plugins should not override this, because this interface is expected to be called pre-create so things normally valid in an overridden validate() such as accessing properties may not work.

Previous topic

The Module

Next topic

The heat.engine.rsrc_defn Module

Project Source

This Page