The heat.engine.resource Module

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

Bases: object

ACTIONS = ('INIT', 'CREATE', 'DELETE', 'UPDATE', 'ROLLBACK', 'SUSPEND', 'RESUME', 'ADOPT', 'SNAPSHOT', 'CHECK')
ADOPT = 'ADOPT'
BASE_ATTRIBUTES = ('show',)
CHECK = 'CHECK'
COMPLETE = 'COMPLETE'
CREATE = 'CREATE'
DELETE = 'DELETE'
FAILED = 'FAILED'
FnBase64(data)[source]

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.

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

the attribute value.

FnGetAtts()[source]

For the intrinsic function get_attr which returns all attributes.

Returns:dict of all resource’s attributes exclude “show” attribute.
FnGetRefId()[source]

For the intrinsic function Ref.

Results:the id or name of the resource.
INIT = 'INIT'
IN_PROGRESS = 'IN_PROGRESS'
RESUME = 'RESUME'
ROLLBACK = 'ROLLBACK'
SHOW = 'show'
SNAPSHOT = 'SNAPSHOT'
STATUSES = ('IN_PROGRESS', 'FAILED', 'COMPLETE')
SUSPEND = 'SUSPEND'
UPDATE = 'UPDATE'
action_handler_task(action, args=[], 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_dependencies(deps)[source]

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_explicit_dependencies(deps)[source]

Add all dependencies explicitly specified in the template.

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

adopt(resource_data)[source]

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 0x7ffbc6ffaa90>}
static build_template_dict(res_name, res_type, tmpl_type, params, props, outputs, description)[source]
ceilometer()[source]
check()[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.

cinder()[source]
clear_hook(hook)[source]
client(name=None)[source]
client_plugin(name=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)[source]

Creates the resource by invoking the scheduler TaskRunner.

data()[source]

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.
data_delete(key)[source]

Remove a resource_data element associated to a resource.

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

Save resource’s key/value pair to database.

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

Delete the resource.

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

delete_convergence(template_id, input_data, engine_id, timeout)[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]
dep_attrs(resource_name)[source]
destroy(*args, **kwargs)[source]

Delete the resource and remove it from the database.

entity = None
frozen_definition()[source]
get_reference_id()[source]
glance()[source]
handle_adopt(resource_data=None)[source]
handle_delete()[source]

Default implementation; should be overridden by resources.

handle_update(json_snippet, tmpl_diff, prop_diff)[source]
has_hook(hook)[source]
has_interface(resource_type)[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”.

has_nested()[source]
heat()[source]
identifier()[source]

Return an identifier for this resource.

implementation_signature()[source]

Return a tuple defining the implementation.

This should be broken down into a definition and an implementation version.

classmethod is_service_available(context)[source]
is_using_neutron()[source]
keystone()[source]
classmethod load(context, resource_id, is_update, data)[source]
lock(*args, **kwds)[source]
make_replacement(new_tmpl_id)[source]
metadata_get(refresh=False)[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).

metadata_update(new_metadata=None)[source]

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

neutron()[source]
no_signal_actions = ('SUSPEND', 'DELETE')
nova()[source]
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.

physical_resource_name()[source]
physical_resource_name_limit = 255
physical_resource_name_or_FnGetRefId()[source]
prepare_abandon()[source]
prepare_for_replace()[source]

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.

preview()[source]

Default implementation of Resource.preview.

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

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
Parameters:
  • name – The name to reduce the length of
  • limit – The max length limit
Returns:

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

regenerate_info_schema(definition)[source]

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()[source]
required_by()[source]

List of resources’ names which require the resource as dependency.

Returns a list of resources’ names which directly require this resource as a dependency.

requires_deferred_auth = False
resource_class()[source]

Return the resource class.

This is used to compare old and new resources when updating, to ensure that in-place updates are possible. This method shold return the highest common class in the hierarchy whose subclasses are all capable of converting to each other’s types via handle_update().

This mechanism may disappear again in future, so third-party resource types should not rely on it.

resource_id_set(inst)[source]
classmethod resource_to_template(resource_type, template_type='cfn')[source]

Template where resource’s properties mapped as parameters.

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

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

restore_after_rollback()[source]

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.

resume()[source]

Resume the resource.

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

rpc_client()[source]

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()[source]

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

stack[source]
state[source]

Returns state, tuple of action, status.

state_reset()[source]

Reset state to (INIT, COMPLETE).

state_set(action, status, reason='state changed')[source]
strict_dependency = True
support_status = <heat.engine.support.SupportStatus object at 0x7ffbc6ffab10>
suspend()[source]

Suspend the resource.

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

swift()[source]
translate_properties(properties)[source]

Translates old properties to new ones.

translation_rules(properties)[source]

Return specified rules for resource.

trigger_hook(hook)[source]
trove()[source]
type()[source]
update(*args, **kwargs)[source]

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)[source]

Updates the resource.

Updates the resource by invoking the scheduler TaskRunner and it persists the resource’s current_template_id to template_id and resource’s requires to list of the required resource id from the given resource_data and existing resource’s requires.

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]

The 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()[source]

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_template()[source]

Validate strucural/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 heat.engine.properties Module

Next topic

The heat.engine.rsrc_defn Module

Project Source

This Page